Move the get_unaligned_be24(), get_unaligned_le24() and put_unaligned_le24() definitions from various drivers into include/linux/unaligned/generic.h. Add a put_unaligned_be24() implementation.
Showing the changes to include/linux (1 of 6 files). Show all
Unified · Split
| @@ -2,6 +2,8 @@ · 1 unmodified line | ||
| 2 | 2 | #ifndef _LINUX_UNALIGNED_GENERIC_H |
| 3 | 3 | #define _LINUX_UNALIGNED_GENERIC_H |
| 4 | 4 | |
| 5 | +#include <linux/types.h> | |
| 6 | + | |
| 5 | 7 | /* |
| 6 | 8 | * Cause a link-time error if we try an unaligned access other than |
| 7 | 9 | * 1,2,4 or 8 bytes long |
| @@ -66,4 +68,48 @@ extern void __bad_unaligned_access_size(void); · 58 unmodified lines | ||
| 66 | 68 | } \ |
| 67 | 69 | (void)0; }) |
| 68 | 70 | |
| 71 | +static inline u32 __get_unaligned_be24(const u8 *p) | |
| 72 | +{ | |
| 73 | + return p[0] << 16 | p[1] << 8 | p[2]; | |
| 74 | +} | |
| 75 | + | |
| 76 | +static inline u32 get_unaligned_be24(const void *p) | |
| 77 | +{ | |
| 78 | + return __get_unaligned_be24(p); | |
| 79 | +} | |
| 80 | + | |
| 81 | +static inline u32 __get_unaligned_le24(const u8 *p) | |
| 82 | +{ | |
| 83 | + return p[0] | p[1] << 8 | p[2] << 16; | |
| 84 | +} | |
| 85 | + | |
| 86 | +static inline u32 get_unaligned_le24(const void *p) | |
| 87 | +{ | |
| 88 | + return __get_unaligned_le24(p); | |
| 89 | +} | |
| 90 | + | |
| 91 | +static inline void __put_unaligned_be24(const u32 val, u8 *p) | |
| 92 | +{ | |
| 93 | + *p++ = val >> 16; | |
| 94 | + *p++ = val >> 8; | |
| 95 | + *p++ = val; | |
| 96 | +} | |
| 97 | + | |
| 98 | +static inline void put_unaligned_be24(const u32 val, void *p) | |
| 99 | +{ | |
| 100 | + __put_unaligned_be24(val, p); | |
| 101 | +} | |
| 102 | + | |
| 103 | +static inline void __put_unaligned_le24(const u32 val, u8 *p) | |
| 104 | +{ | |
| 105 | + *p++ = val; | |
| 106 | + *p++ = val >> 8; | |
| 107 | + *p++ = val >> 16; | |
| 108 | +} | |
| 109 | + | |
| 110 | +static inline void put_unaligned_le24(const u32 val, void *p) | |
| 111 | +{ | |
| 112 | + __put_unaligned_le24(val, p); | |
| 113 | +} | |
| 114 | + | |
| 69 | 115 | #endif /* _LINUX_UNALIGNED_GENERIC_H */ |