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
142static const struct blk_mq_ops nvme_rdma_mq_ops;142static const struct blk_mq_ops nvme_rdma_mq_ops;
143static const struct blk_mq_ops nvme_rdma_admin_mq_ops;143static const struct blk_mq_ops nvme_rdma_admin_mq_ops;
144 144
145/* XXX: really should move to a generic header sooner or later.. */
146static inline void put_unaligned_le24(u32 val, u8 *p)
147{
148 *p++ = val;
149 *p++ = val >> 8;
150 *p++ = val >> 16;
151}
152
153static inline int nvme_rdma_queue_idx(struct nvme_rdma_queue *queue)145static inline int nvme_rdma_queue_idx(struct nvme_rdma_queue *queue)
154{146{
155 return queue - queue->ctrl->queues;147 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
143 return 1 + (((len - 1) & PAGE_MASK) >> PAGE_SHIFT);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.. */
147static inline u32 get_unaligned_le24(const u8 *p)
148{
149 return (u32)p[0] | (u32)p[1] << 8 | (u32)p[2] << 16;
150}
151
152static inline bool nvmet_rdma_need_data_in(struct nvmet_rdma_rsp *rsp)146static inline bool nvmet_rdma_need_data_in(struct nvmet_rdma_rsp *rsp)
153{147{
154 return nvme_is_write(rsp->req.cmd) &&148 return nvme_is_write(rsp->req.cmd) &&
drivers/usb/gadget/function/f_mass_storage.c+1−0
@@ -216,6 +216,7 @@ · 215 unmodified lines
216#include <linux/freezer.h>216#include <linux/freezer.h>
217#include <linux/module.h>217#include <linux/module.h>
218#include <linux/uaccess.h>218#include <linux/uaccess.h>
219#include <asm/unaligned.h>
219 220
220#include <linux/usb/ch9.h>221#include <linux/usb/ch9.h>
221#include <linux/usb/gadget.h>222#include <linux/usb/gadget.h>
drivers/usb/gadget/function/storage_common.h+0−5
@@ -172,11 +172,6 @@ enum data_direction { · 171 unmodified lines
172 DATA_DIR_NONE172 DATA_DIR_NONE
173};173};
174 174
175static inline u32 get_unaligned_be24(u8 *buf)
176{
177 return 0xffffff & (u32) get_unaligned_be32(buf - 1);
178}
179
180static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)175static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)
181{176{
182 return container_of(dev, struct fsg_lun, dev);177 return container_of(dev, struct fsg_lun, dev);
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 */
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
116 return !!(se_dev->dev_flags & DF_CONFIGURED);116 return !!(se_dev->dev_flags & DF_CONFIGURED);
117}117}
118 118
119/* Only use get_unaligned_be24() if reading p - 1 is allowed. */
120static inline uint32_t get_unaligned_be24(const uint8_t *const p)
121{
122 return get_unaligned_be32(p - 1) & 0xffffffU;
123}
124
125#endif /* TARGET_CORE_BACKEND_H */119#endif /* TARGET_CORE_BACKEND_H */