Commit a7afff31 authored by Bart Van Assche's avatar Bart Van Assche Committed by Martin K. Petersen

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarAndy 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: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 7251c0a4
...@@ -142,14 +142,6 @@ static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc); ...@@ -142,14 +142,6 @@ static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc);
static const struct blk_mq_ops nvme_rdma_mq_ops; static const struct blk_mq_ops nvme_rdma_mq_ops;
static const struct blk_mq_ops nvme_rdma_admin_mq_ops; static const struct blk_mq_ops nvme_rdma_admin_mq_ops;
/* XXX: really should move to a generic header sooner or later.. */
static inline void put_unaligned_le24(u32 val, u8 *p)
{
*p++ = val;
*p++ = val >> 8;
*p++ = val >> 16;
}
static inline int nvme_rdma_queue_idx(struct nvme_rdma_queue *queue) static inline int nvme_rdma_queue_idx(struct nvme_rdma_queue *queue)
{ {
return queue - queue->ctrl->queues; return queue - queue->ctrl->queues;
......
...@@ -143,12 +143,6 @@ static int num_pages(int len) ...@@ -143,12 +143,6 @@ static int num_pages(int len)
return 1 + (((len - 1) & PAGE_MASK) >> PAGE_SHIFT); return 1 + (((len - 1) & PAGE_MASK) >> PAGE_SHIFT);
} }
/* XXX: really should move to a generic header sooner or later.. */
static inline u32 get_unaligned_le24(const u8 *p)
{
return (u32)p[0] | (u32)p[1] << 8 | (u32)p[2] << 16;
}
static inline bool nvmet_rdma_need_data_in(struct nvmet_rdma_rsp *rsp) static inline bool nvmet_rdma_need_data_in(struct nvmet_rdma_rsp *rsp)
{ {
return nvme_is_write(rsp->req.cmd) && return nvme_is_write(rsp->req.cmd) &&
......
...@@ -216,6 +216,7 @@ ...@@ -216,6 +216,7 @@
#include <linux/freezer.h> #include <linux/freezer.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <asm/unaligned.h>
#include <linux/usb/ch9.h> #include <linux/usb/ch9.h>
#include <linux/usb/gadget.h> #include <linux/usb/gadget.h>
......
...@@ -172,11 +172,6 @@ enum data_direction { ...@@ -172,11 +172,6 @@ enum data_direction {
DATA_DIR_NONE DATA_DIR_NONE
}; };
static inline u32 get_unaligned_be24(u8 *buf)
{
return 0xffffff & (u32) get_unaligned_be32(buf - 1);
}
static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev) static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)
{ {
return container_of(dev, struct fsg_lun, dev); return container_of(dev, struct fsg_lun, dev);
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#ifndef _LINUX_UNALIGNED_GENERIC_H #ifndef _LINUX_UNALIGNED_GENERIC_H
#define _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 * Cause a link-time error if we try an unaligned access other than
* 1,2,4 or 8 bytes long * 1,2,4 or 8 bytes long
...@@ -66,4 +68,48 @@ extern void __bad_unaligned_access_size(void); ...@@ -66,4 +68,48 @@ extern void __bad_unaligned_access_size(void);
} \ } \
(void)0; }) (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 */ #endif /* _LINUX_UNALIGNED_GENERIC_H */
...@@ -116,10 +116,4 @@ static inline bool target_dev_configured(struct se_device *se_dev) ...@@ -116,10 +116,4 @@ static inline bool target_dev_configured(struct se_device *se_dev)
return !!(se_dev->dev_flags & DF_CONFIGURED); return !!(se_dev->dev_flags & DF_CONFIGURED);
} }
/* Only use get_unaligned_be24() if reading p - 1 is allowed. */
static inline uint32_t get_unaligned_be24(const uint8_t *const p)
{
return get_unaligned_be32(p - 1) & 0xffffffU;
}
#endif /* TARGET_CORE_BACKEND_H */ #endif /* TARGET_CORE_BACKEND_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment