From 4a9dce9a486187c78922a235e6199a27da54dab1 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 5 Jul 2018 15:04:43 -0700 Subject: [PATCH] Use SPDK_CONTAINEROF in a few more places A few open-coded sequences equivalent to SPDK_CONTAINEROF() were scattered around; replace them with the macro from spdk/util.h. Change-Id: I95c6e6838902f411420573399ced7c58c2e4ef84 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/418126 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- include/spdk/bdev_module.h | 4 ++-- lib/iscsi/task.h | 3 ++- lib/nvme/nvme_pcie.c | 4 ++-- lib/nvme/nvme_rdma.c | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/spdk/bdev_module.h b/include/spdk/bdev_module.h index ca03afc6e..a69ec0286 100644 --- a/include/spdk/bdev_module.h +++ b/include/spdk/bdev_module.h @@ -47,6 +47,7 @@ #include "spdk/queue.h" #include "spdk/scsi_spec.h" #include "spdk/thread.h" +#include "spdk/util.h" #include "spdk/uuid.h" /** Block device module */ @@ -690,8 +691,7 @@ struct spdk_bdev_module *spdk_bdev_module_list_find(const char *name); static inline struct spdk_bdev_io * spdk_bdev_io_from_ctx(void *ctx) { - return (struct spdk_bdev_io *) - ((uintptr_t)ctx - offsetof(struct spdk_bdev_io, driver_ctx)); + return SPDK_CONTAINEROF(ctx, struct spdk_bdev_io, driver_ctx); } struct spdk_bdev_part_base; diff --git a/lib/iscsi/task.h b/lib/iscsi/task.h index 8e6f7e04e..0fee4cda2 100644 --- a/lib/iscsi/task.h +++ b/lib/iscsi/task.h @@ -37,6 +37,7 @@ #include "iscsi/iscsi.h" #include "spdk/scsi.h" +#include "spdk/util.h" struct spdk_iscsi_task { struct spdk_scsi_task scsi; @@ -169,7 +170,7 @@ struct spdk_iscsi_task *spdk_iscsi_task_get(struct spdk_iscsi_conn *conn, static inline struct spdk_iscsi_task * spdk_iscsi_task_from_scsi_task(struct spdk_scsi_task *task) { - return (struct spdk_iscsi_task *)((uintptr_t)task - offsetof(struct spdk_iscsi_task, scsi)); + return SPDK_CONTAINEROF(task, struct spdk_iscsi_task, scsi); } static inline struct spdk_iscsi_task * diff --git a/lib/nvme/nvme_pcie.c b/lib/nvme/nvme_pcie.c index 1e0f5eb32..53e67ff65 100644 --- a/lib/nvme/nvme_pcie.c +++ b/lib/nvme/nvme_pcie.c @@ -316,14 +316,14 @@ static inline struct nvme_pcie_ctrlr * nvme_pcie_ctrlr(struct spdk_nvme_ctrlr *ctrlr) { assert(ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_PCIE); - return (struct nvme_pcie_ctrlr *)((uintptr_t)ctrlr - offsetof(struct nvme_pcie_ctrlr, ctrlr)); + return SPDK_CONTAINEROF(ctrlr, struct nvme_pcie_ctrlr, ctrlr); } static inline struct nvme_pcie_qpair * nvme_pcie_qpair(struct spdk_nvme_qpair *qpair) { assert(qpair->trtype == SPDK_NVME_TRANSPORT_PCIE); - return (struct nvme_pcie_qpair *)((uintptr_t)qpair - offsetof(struct nvme_pcie_qpair, qpair)); + return SPDK_CONTAINEROF(qpair, struct nvme_pcie_qpair, qpair); } static volatile void * diff --git a/lib/nvme/nvme_rdma.c b/lib/nvme/nvme_rdma.c index edd245bf8..d2743d418 100644 --- a/lib/nvme/nvme_rdma.c +++ b/lib/nvme/nvme_rdma.c @@ -154,14 +154,14 @@ static inline struct nvme_rdma_qpair * nvme_rdma_qpair(struct spdk_nvme_qpair *qpair) { assert(qpair->trtype == SPDK_NVME_TRANSPORT_RDMA); - return (struct nvme_rdma_qpair *)((uintptr_t)qpair - offsetof(struct nvme_rdma_qpair, qpair)); + return SPDK_CONTAINEROF(qpair, struct nvme_rdma_qpair, qpair); } static inline struct nvme_rdma_ctrlr * nvme_rdma_ctrlr(struct spdk_nvme_ctrlr *ctrlr) { assert(ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_RDMA); - return (struct nvme_rdma_ctrlr *)((uintptr_t)ctrlr - offsetof(struct nvme_rdma_ctrlr, ctrlr)); + return SPDK_CONTAINEROF(ctrlr, struct nvme_rdma_ctrlr, ctrlr); } static struct spdk_nvme_rdma_req *