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.
Unified · Split
| @@ -142,14 +142,6 @@ static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc); · 141 unmodified lines | |||
| 142 | static const struct blk_mq_ops nvme_rdma_mq_ops; | 142 | static const struct blk_mq_ops nvme_rdma_mq_ops; |
| 143 | static const struct blk_mq_ops nvme_rdma_admin_mq_ops; | 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 | static inline int nvme_rdma_queue_idx(struct nvme_rdma_queue *queue) | 145 | static 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; |
| @@ -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.. */ | ||
| 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 | static inline bool nvmet_rdma_need_data_in(struct nvmet_rdma_rsp *rsp) | 146 | static 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) && |
| @@ -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> |
| @@ -172,11 +172,6 @@ enum data_direction { · 171 unmodified lines | |||
| 172 | DATA_DIR_NONE | 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 | static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev) | 175 | static 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); |
| @@ -2,6 +2,8 @@ · 1 unmodified line | |||
| 2 | #ifndef _LINUX_UNALIGNED_GENERIC_H | 2 | #ifndef _LINUX_UNALIGNED_GENERIC_H |
| 3 | #define _LINUX_UNALIGNED_GENERIC_H | 3 | #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 than | 8 | * Cause a link-time error if we try an unaligned access other than |
| 7 | * 1,2,4 or 8 bytes long | 9 | * 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 | ||
| 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 | |||
| 69 | #endif /* _LINUX_UNALIGNED_GENERIC_H */ | 115 | #endif /* _LINUX_UNALIGNED_GENERIC_H */ |
| @@ -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. */ | ||
| 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 | #endif /* TARGET_CORE_BACKEND_H */ | 119 | #endif /* TARGET_CORE_BACKEND_H */ |