IB/qib: Fix null pointer subtraction compiler warning
authorJason Gunthorpe <jgg@nvidia.com>
Fri, 3 Sep 2021 13:07:28 +0000 (10:07 -0300)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 8 Sep 2021 11:32:04 +0000 (08:32 -0300)
commit84f969e1c48ed3825986e91a0786e363d57f69d1
treefa0df9b7953931d0180dba5e3b507ace303e8909
parentf4c6f31011eafe027abddf6cee1288a1b5a05b73
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: 4a7aaf88c89f ("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>
drivers/infiniband/hw/qib/qib_sysfs.c