History

scsi: treewide: Consolidate {get,put}_unaligned_[bl]e24() definitions

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.

Bart Van Assche committed 6 years ago

Commit a7afff31 parent 7251c0a6 files · +47 −25Browse files

Showing the changes to include/linux (1 of 6 files). Show all

Unified · Split

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