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

Unified · Split

6 files
  1. drivers/nvme/host/rdma.c +0 −8
  2. drivers/nvme/target/rdma.c +0 −6
  3. drivers/usb/gadget/function/f_mass_storage.c +1 −0
  4. drivers/usb/gadget/function/storage_common.h +0 −5
  5. include/linux/unaligned/generic.h +46 −0
  6. include/target/target_core_backend.h +0 −6
drivers/nvme/host/rdma.c+0−8
@@ -142,14 +142,6 @@ static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc); · 141 unmodified lines
142142 static const struct blk_mq_ops nvme_rdma_mq_ops;
143143 static const struct blk_mq_ops nvme_rdma_admin_mq_ops;
144144
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−
153145 static inline int nvme_rdma_queue_idx(struct nvme_rdma_queue *queue)
154146 {
155147 return queue - queue->ctrl->queues;
drivers/nvme/target/rdma.c+0−6
@@ -143,12 +143,6 @@ static int num_pages(int len) · 142 unmodified lines
143143 return 1 + (((len - 1) & PAGE_MASK) >> PAGE_SHIFT);
144144 }
145145
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−
152146 static inline bool nvmet_rdma_need_data_in(struct nvmet_rdma_rsp *rsp)
153147 {
154148 return nvme_is_write(rsp->req.cmd) &&
drivers/usb/gadget/function/f_mass_storage.c+1−0
@@ -216,6 +216,7 @@ · 215 unmodified lines
216216 #include <linux/freezer.h>
217217 #include <linux/module.h>
218218 #include <linux/uaccess.h>
219+#include <asm/unaligned.h>
219220
220221 #include <linux/usb/ch9.h>
221222 #include <linux/usb/gadget.h>
drivers/usb/gadget/function/storage_common.h+0−5
@@ -172,11 +172,6 @@ enum data_direction { · 171 unmodified lines
172172 DATA_DIR_NONE
173173 };
174174
175−static inline u32 get_unaligned_be24(u8 *buf)
176−{
177− return 0xffffff & (u32) get_unaligned_be32(buf - 1);
178−}
179−
180175 static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)
181176 {
182177 return container_of(dev, struct fsg_lun, dev);
include/linux/unaligned/generic.h+46−0
@@ -2,6 +2,8 @@ · 1 unmodified line
22 #ifndef _LINUX_UNALIGNED_GENERIC_H
33 #define _LINUX_UNALIGNED_GENERIC_H
44
5+#include <linux/types.h>
6+
57 /*
68 * Cause a link-time error if we try an unaligned access other than
79 * 1,2,4 or 8 bytes long
@@ -66,4 +68,48 @@ extern void __bad_unaligned_access_size(void); · 58 unmodified lines
6668 } \
6769 (void)0; })
6870
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+
69115 #endif /* _LINUX_UNALIGNED_GENERIC_H */
include/target/target_core_backend.h+0−6
@@ -116,10 +116,4 @@ static inline bool target_dev_configured(struct se_device *se_dev) · 115 unmodified lines
116116 return !!(se_dev->dev_flags & DF_CONFIGURED);
117117 }
118118
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−
125119 #endif /* TARGET_CORE_BACKEND_H */