Skip to content

Commit a7afff3

Browse files
bvanasschemartinkpetersen
authored andcommitted
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>
1 parent 7251c0a commit a7afff3

6 files changed

Lines changed: 47 additions & 25 deletions

File tree

‎drivers/nvme/host/rdma.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,6 @@ static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc);
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‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ static int num_pages(int len)
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
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‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ enum data_direction {
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‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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);
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‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,4 @@ static inline bool target_dev_configured(struct se_device *se_dev)
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 */

0 commit comments

Comments
 (0)