aboutsummaryrefslogtreecommitdiff
path: root/include/linux/unaligned
diff options
context:
space:
mode:
authorBart Van Assche <[email protected]>2020-03-13 13:31:00 -0700
committerMartin K. Petersen <[email protected]>2020-03-16 22:08:34 -0400
commita7afff31d56db22647251d76d6af030cd47bd97e (patch)
tree7a42b6b8e15f957ba640a476b53fb6ccba2854f8 /include/linux/unaligned
parent7251c0a41053631ac66795e7f7ddf4d4cba1f467 (diff)
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. Link: https://lore.kernel.org/r/[email protected] Cc: Keith Busch <[email protected]> Cc: Sagi Grimberg <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Harvey Harrison <[email protected]> Cc: Martin K. Petersen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Andrew Morton <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> # For drivers/usb Reviewed-by: Felipe Balbi <[email protected]> # For drivers/usb/gadget Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
Diffstat (limited to 'include/linux/unaligned')
-rw-r--r--include/linux/unaligned/generic.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/include/linux/unaligned/generic.h b/include/linux/unaligned/generic.h
index 57d3114656e5..303289492859 100644
--- a/include/linux/unaligned/generic.h
+++ b/include/linux/unaligned/generic.h
@@ -2,6 +2,8 @@
#ifndef _LINUX_UNALIGNED_GENERIC_H
#define _LINUX_UNALIGNED_GENERIC_H
+#include <linux/types.h>
+
/*
* Cause a link-time error if we try an unaligned access other than
* 1,2,4 or 8 bytes long
@@ -66,4 +68,48 @@ extern void __bad_unaligned_access_size(void);
} \
(void)0; })
+static inline u32 __get_unaligned_be24(const u8 *p)
+{
+ return p[0] << 16 | p[1] << 8 | p[2];
+}
+
+static inline u32 get_unaligned_be24(const void *p)
+{
+ return __get_unaligned_be24(p);
+}
+
+static inline u32 __get_unaligned_le24(const u8 *p)
+{
+ return p[0] | p[1] << 8 | p[2] << 16;
+}
+
+static inline u32 get_unaligned_le24(const void *p)
+{
+ return __get_unaligned_le24(p);
+}
+
+static inline void __put_unaligned_be24(const u32 val, u8 *p)
+{
+ *p++ = val >> 16;
+ *p++ = val >> 8;
+ *p++ = val;
+}
+
+static inline void put_unaligned_be24(const u32 val, void *p)
+{
+ __put_unaligned_be24(val, p);
+}
+
+static inline void __put_unaligned_le24(const u32 val, u8 *p)
+{
+ *p++ = val;
+ *p++ = val >> 8;
+ *p++ = val >> 16;
+}
+
+static inline void put_unaligned_le24(const u32 val, void *p)
+{
+ __put_unaligned_le24(val, p);
+}
+
#endif /* _LINUX_UNALIGNED_GENERIC_H */