Skip to content

Commit 84f969e

Browse files
committed
IB/qib: Fix null pointer subtraction compiler warning
>> drivers/infiniband/hw/qib/qib_sysfs.c:411:1: warning: performing pointer subtraction with a null pointer has undefined behavior +[-Wnull-pointer-subtraction] QIB_DIAGC_ATTR(rc_resends); ^~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/infiniband/hw/qib/qib_sysfs.c:408:51: note: expanded from macro 'QIB_DIAGC_ATTR' .counter = &((struct qib_ibport *)0)->rvp.n_##N - (u64 *)0, \ Use offsetof and accomplish the type check using static_assert. Fixes: 4a7aaf8 ("RDMA/qib: Use attributes for the port sysfs") Link: https://lore.kernel.org/r/0-v1-43ae3c759177+65-qib_type_jgg@nvidia.com Reported-by: kernel test robot <lkp@intel.com> Acked-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent f4c6f31 commit 84f969e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/infiniband/hw/qib/qib_sysfs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,11 @@ static ssize_t diagc_attr_store(struct ib_device *ibdev, u32 port_num,
403403
}
404404

405405
#define QIB_DIAGC_ATTR(N) \
406+
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
406407
static struct qib_diagc_attr qib_diagc_attr_##N = { \
407408
.attr = __ATTR(N, 0664, diagc_attr_show, diagc_attr_store), \
408-
.counter = &((struct qib_ibport *)0)->rvp.n_##N - (u64 *)0, \
409+
.counter = \
410+
offsetof(struct qib_ibport, rvp.n_##N) / sizeof(u64) \
409411
}
410412

411413
QIB_DIAGC_ATTR(rc_resends);

0 commit comments

Comments
 (0)