1717#include <linux/delay.h>
1818#include <linux/log2.h>
1919#include <linux/hwspinlock.h>
20+ #include <asm/unaligned.h>
2021
2122#define CREATE_TRACE_POINTS
2223#include "trace.h"
@@ -249,22 +250,20 @@ static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
249250
250251static void regmap_format_16_be (void * buf , unsigned int val , unsigned int shift )
251252{
252- __be16 * b = buf ;
253-
254- b [0 ] = cpu_to_be16 (val << shift );
253+ put_unaligned_be16 (val << shift , buf );
255254}
256255
257256static void regmap_format_16_le (void * buf , unsigned int val , unsigned int shift )
258257{
259- __le16 * b = buf ;
260-
261- b [0 ] = cpu_to_le16 (val << shift );
258+ put_unaligned_le16 (val << shift , buf );
262259}
263260
264261static void regmap_format_16_native (void * buf , unsigned int val ,
265262 unsigned int shift )
266263{
267- * (u16 * )buf = val << shift ;
264+ u16 v = val << shift ;
265+
266+ memcpy (buf , & v , sizeof (v ));
268267}
269268
270269static void regmap_format_24 (void * buf , unsigned int val , unsigned int shift )
@@ -280,43 +279,39 @@ static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
280279
281280static void regmap_format_32_be (void * buf , unsigned int val , unsigned int shift )
282281{
283- __be32 * b = buf ;
284-
285- b [0 ] = cpu_to_be32 (val << shift );
282+ put_unaligned_be32 (val << shift , buf );
286283}
287284
288285static void regmap_format_32_le (void * buf , unsigned int val , unsigned int shift )
289286{
290- __le32 * b = buf ;
291-
292- b [0 ] = cpu_to_le32 (val << shift );
287+ put_unaligned_le32 (val << shift , buf );
293288}
294289
295290static void regmap_format_32_native (void * buf , unsigned int val ,
296291 unsigned int shift )
297292{
298- * (u32 * )buf = val << shift ;
293+ u32 v = val << shift ;
294+
295+ memcpy (buf , & v , sizeof (v ));
299296}
300297
301298#ifdef CONFIG_64BIT
302299static void regmap_format_64_be (void * buf , unsigned int val , unsigned int shift )
303300{
304- __be64 * b = buf ;
305-
306- b [0 ] = cpu_to_be64 ((u64 )val << shift );
301+ put_unaligned_be64 ((u64 ) val << shift , buf );
307302}
308303
309304static void regmap_format_64_le (void * buf , unsigned int val , unsigned int shift )
310305{
311- __le64 * b = buf ;
312-
313- b [0 ] = cpu_to_le64 ((u64 )val << shift );
306+ put_unaligned_le64 ((u64 ) val << shift , buf );
314307}
315308
316309static void regmap_format_64_native (void * buf , unsigned int val ,
317310 unsigned int shift )
318311{
319- * (u64 * )buf = (u64 )val << shift ;
312+ u64 v = (u64 ) val << shift ;
313+
314+ memcpy (buf , & v , sizeof (v ));
320315}
321316#endif
322317
@@ -333,35 +328,34 @@ static unsigned int regmap_parse_8(const void *buf)
333328
334329static unsigned int regmap_parse_16_be (const void * buf )
335330{
336- const __be16 * b = buf ;
337-
338- return be16_to_cpu (b [0 ]);
331+ return get_unaligned_be16 (buf );
339332}
340333
341334static unsigned int regmap_parse_16_le (const void * buf )
342335{
343- const __le16 * b = buf ;
344-
345- return le16_to_cpu (b [0 ]);
336+ return get_unaligned_le16 (buf );
346337}
347338
348339static void regmap_parse_16_be_inplace (void * buf )
349340{
350- __be16 * b = buf ;
341+ u16 v = get_unaligned_be16 ( buf ) ;
351342
352- b [ 0 ] = be16_to_cpu ( b [ 0 ] );
343+ memcpy ( buf , & v , sizeof ( v ) );
353344}
354345
355346static void regmap_parse_16_le_inplace (void * buf )
356347{
357- __le16 * b = buf ;
348+ u16 v = get_unaligned_le16 ( buf ) ;
358349
359- b [ 0 ] = le16_to_cpu ( b [ 0 ] );
350+ memcpy ( buf , & v , sizeof ( v ) );
360351}
361352
362353static unsigned int regmap_parse_16_native (const void * buf )
363354{
364- return * (u16 * )buf ;
355+ u16 v ;
356+
357+ memcpy (& v , buf , sizeof (v ));
358+ return v ;
365359}
366360
367361static unsigned int regmap_parse_24 (const void * buf )
@@ -376,69 +370,67 @@ static unsigned int regmap_parse_24(const void *buf)
376370
377371static unsigned int regmap_parse_32_be (const void * buf )
378372{
379- const __be32 * b = buf ;
380-
381- return be32_to_cpu (b [0 ]);
373+ return get_unaligned_be32 (buf );
382374}
383375
384376static unsigned int regmap_parse_32_le (const void * buf )
385377{
386- const __le32 * b = buf ;
387-
388- return le32_to_cpu (b [0 ]);
378+ return get_unaligned_le32 (buf );
389379}
390380
391381static void regmap_parse_32_be_inplace (void * buf )
392382{
393- __be32 * b = buf ;
383+ u32 v = get_unaligned_be32 ( buf ) ;
394384
395- b [ 0 ] = be32_to_cpu ( b [ 0 ] );
385+ memcpy ( buf , & v , sizeof ( v ) );
396386}
397387
398388static void regmap_parse_32_le_inplace (void * buf )
399389{
400- __le32 * b = buf ;
390+ u32 v = get_unaligned_le32 ( buf ) ;
401391
402- b [ 0 ] = le32_to_cpu ( b [ 0 ] );
392+ memcpy ( buf , & v , sizeof ( v ) );
403393}
404394
405395static unsigned int regmap_parse_32_native (const void * buf )
406396{
407- return * (u32 * )buf ;
397+ u32 v ;
398+
399+ memcpy (& v , buf , sizeof (v ));
400+ return v ;
408401}
409402
410403#ifdef CONFIG_64BIT
411404static unsigned int regmap_parse_64_be (const void * buf )
412405{
413- const __be64 * b = buf ;
414-
415- return be64_to_cpu (b [0 ]);
406+ return get_unaligned_be64 (buf );
416407}
417408
418409static unsigned int regmap_parse_64_le (const void * buf )
419410{
420- const __le64 * b = buf ;
421-
422- return le64_to_cpu (b [0 ]);
411+ return get_unaligned_le64 (buf );
423412}
424413
425414static void regmap_parse_64_be_inplace (void * buf )
426415{
427- __be64 * b = buf ;
416+ u64 v = get_unaligned_be64 ( buf ) ;
428417
429- b [ 0 ] = be64_to_cpu ( b [ 0 ] );
418+ memcpy ( buf , & v , sizeof ( v ) );
430419}
431420
432421static void regmap_parse_64_le_inplace (void * buf )
433422{
434- __le64 * b = buf ;
423+ u64 v = get_unaligned_le64 ( buf ) ;
435424
436- b [ 0 ] = le64_to_cpu ( b [ 0 ] );
425+ memcpy ( buf , & v , sizeof ( v ) );
437426}
438427
439428static unsigned int regmap_parse_64_native (const void * buf )
440429{
441- return * (u64 * )buf ;
430+ u64 v ;
431+
432+ memcpy (& v , buf , sizeof (v ));
433+ return v ;
442434}
443435#endif
444436
@@ -2944,8 +2936,9 @@ EXPORT_SYMBOL_GPL(regmap_update_bits_base);
29442936 * @reg: Register to read from
29452937 * @bits: Bits to test
29462938 *
2947- * Returns -1 if the underlying regmap_read() fails, 0 if at least one of the
2948- * tested bits is not set and 1 if all tested bits are set.
2939+ * Returns 0 if at least one of the tested bits is not set, 1 if all tested
2940+ * bits are set and a negative error number if the underlying regmap_read()
2941+ * fails.
29492942 */
29502943int regmap_test_bits (struct regmap * map , unsigned int reg , unsigned int bits )
29512944{
0 commit comments