Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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/20200313203102.16613-4-bvanassche@acm.org
Cc: Keith Busch <kbusch@kernel.org>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Jens Axboe <axboe@fb.com>
Cc: Harvey Harrison <harvey.harrison@gmail.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> # For drivers/usb
Reviewed-by: Felipe Balbi <balbi@kernel.org> # For drivers/usb/gadget
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
a7afff31 7251c0a4

+47 -25
-8
drivers/nvme/host/rdma.c
··· 142 142 static const struct blk_mq_ops nvme_rdma_mq_ops; 143 143 static const struct blk_mq_ops nvme_rdma_admin_mq_ops; 144 144 145 - /* XXX: really should move to a generic header sooner or later.. */ 146 - static inline void put_unaligned_le24(u32 val, u8 *p) 147 - { 148 - *p++ = val; 149 - *p++ = val >> 8; 150 - *p++ = val >> 16; 151 - } 152 - 153 145 static inline int nvme_rdma_queue_idx(struct nvme_rdma_queue *queue) 154 146 { 155 147 return queue - queue->ctrl->queues;
-6
drivers/nvme/target/rdma.c
··· 143 143 return 1 + (((len - 1) & PAGE_MASK) >> PAGE_SHIFT); 144 144 } 145 145 146 - /* XXX: really should move to a generic header sooner or later.. */ 147 - static inline u32 get_unaligned_le24(const u8 *p) 148 - { 149 - return (u32)p[0] | (u32)p[1] << 8 | (u32)p[2] << 16; 150 - } 151 - 152 146 static inline bool nvmet_rdma_need_data_in(struct nvmet_rdma_rsp *rsp) 153 147 { 154 148 return nvme_is_write(rsp->req.cmd) &&
+1
drivers/usb/gadget/function/f_mass_storage.c
··· 216 216 #include <linux/freezer.h> 217 217 #include <linux/module.h> 218 218 #include <linux/uaccess.h> 219 + #include <asm/unaligned.h> 219 220 220 221 #include <linux/usb/ch9.h> 221 222 #include <linux/usb/gadget.h>
-5
drivers/usb/gadget/function/storage_common.h
··· 172 172 DATA_DIR_NONE 173 173 }; 174 174 175 - static inline u32 get_unaligned_be24(u8 *buf) 176 - { 177 - return 0xffffff & (u32) get_unaligned_be32(buf - 1); 178 - } 179 - 180 175 static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev) 181 176 { 182 177 return container_of(dev, struct fsg_lun, dev);
+46
include/linux/unaligned/generic.h
··· 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 ··· 67 65 break; \ 68 66 } \ 69 67 (void)0; }) 68 + 69 + static inline u32 __get_unaligned_be24(const u8 *p) 70 + { 71 + return p[0] << 16 | p[1] << 8 | p[2]; 72 + } 73 + 74 + static inline u32 get_unaligned_be24(const void *p) 75 + { 76 + return __get_unaligned_be24(p); 77 + } 78 + 79 + static inline u32 __get_unaligned_le24(const u8 *p) 80 + { 81 + return p[0] | p[1] << 8 | p[2] << 16; 82 + } 83 + 84 + static inline u32 get_unaligned_le24(const void *p) 85 + { 86 + return __get_unaligned_le24(p); 87 + } 88 + 89 + static inline void __put_unaligned_be24(const u32 val, u8 *p) 90 + { 91 + *p++ = val >> 16; 92 + *p++ = val >> 8; 93 + *p++ = val; 94 + } 95 + 96 + static inline void put_unaligned_be24(const u32 val, void *p) 97 + { 98 + __put_unaligned_be24(val, p); 99 + } 100 + 101 + static inline void __put_unaligned_le24(const u32 val, u8 *p) 102 + { 103 + *p++ = val; 104 + *p++ = val >> 8; 105 + *p++ = val >> 16; 106 + } 107 + 108 + static inline void put_unaligned_le24(const u32 val, void *p) 109 + { 110 + __put_unaligned_le24(val, p); 111 + } 70 112 71 113 #endif /* _LINUX_UNALIGNED_GENERIC_H */
-6
include/target/target_core_backend.h
··· 116 116 return !!(se_dev->dev_flags & DF_CONFIGURED); 117 117 } 118 118 119 - /* Only use get_unaligned_be24() if reading p - 1 is allowed. */ 120 - static inline uint32_t get_unaligned_be24(const uint8_t *const p) 121 - { 122 - return get_unaligned_be32(p - 1) & 0xffffffU; 123 - } 124 - 125 119 #endif /* TARGET_CORE_BACKEND_H */