* [PATCH] IB/qib: Fix null pointer subtraction compiler warning
@ 2021-09-03 13:07 Jason Gunthorpe
2021-09-03 17:24 ` Dennis Dalessandro
2021-09-08 11:44 ` Jason Gunthorpe
0 siblings, 2 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2021-09-03 13:07 UTC (permalink / raw)
To: Dennis Dalessandro, linux-rdma
Cc: Leon Romanovsky, kernel test robot, Mike Marciniszyn, llvm,
kbuild-all, linux-kernel
>> 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")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/infiniband/hw/qib/qib_sysfs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
index d57e49de6650be..452e2355d24eeb 100644
--- a/drivers/infiniband/hw/qib/qib_sysfs.c
+++ b/drivers/infiniband/hw/qib/qib_sysfs.c
@@ -403,9 +403,11 @@ static ssize_t diagc_attr_store(struct ib_device *ibdev, u32 port_num,
}
#define QIB_DIAGC_ATTR(N) \
+ static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
static struct qib_diagc_attr qib_diagc_attr_##N = { \
.attr = __ATTR(N, 0664, diagc_attr_show, diagc_attr_store), \
- .counter = &((struct qib_ibport *)0)->rvp.n_##N - (u64 *)0, \
+ .counter = \
+ offsetof(struct qib_ibport, rvp.n_##N) / sizeof(u64) \
}
QIB_DIAGC_ATTR(rc_resends);
base-commit: 6a217437f9f5482a3f6f2dc5fcd27cf0f62409ac
--
2.33.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] IB/qib: Fix null pointer subtraction compiler warning
2021-09-03 13:07 [PATCH] IB/qib: Fix null pointer subtraction compiler warning Jason Gunthorpe
@ 2021-09-03 17:24 ` Dennis Dalessandro
2021-09-08 11:44 ` Jason Gunthorpe
1 sibling, 0 replies; 3+ messages in thread
From: Dennis Dalessandro @ 2021-09-03 17:24 UTC (permalink / raw)
To: Jason Gunthorpe, linux-rdma
Cc: Leon Romanovsky, kernel test robot, Mike Marciniszyn, llvm,
kbuild-all, linux-kernel
On 9/3/21 9:07 AM, Jason Gunthorpe wrote:
>>> 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")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
> drivers/infiniband/hw/qib/qib_sysfs.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
> index d57e49de6650be..452e2355d24eeb 100644
> --- a/drivers/infiniband/hw/qib/qib_sysfs.c
> +++ b/drivers/infiniband/hw/qib/qib_sysfs.c
> @@ -403,9 +403,11 @@ static ssize_t diagc_attr_store(struct ib_device *ibdev, u32 port_num,
> }
>
> #define QIB_DIAGC_ATTR(N) \
> + static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
> static struct qib_diagc_attr qib_diagc_attr_##N = { \
> .attr = __ATTR(N, 0664, diagc_attr_show, diagc_attr_store), \
> - .counter = &((struct qib_ibport *)0)->rvp.n_##N - (u64 *)0, \
> + .counter = \
> + offsetof(struct qib_ibport, rvp.n_##N) / sizeof(u64) \
> }
>
> QIB_DIAGC_ATTR(rc_resends);
>
> base-commit: 6a217437f9f5482a3f6f2dc5fcd27cf0f62409ac
>
Looks fine.
Acked-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] IB/qib: Fix null pointer subtraction compiler warning
2021-09-03 13:07 [PATCH] IB/qib: Fix null pointer subtraction compiler warning Jason Gunthorpe
2021-09-03 17:24 ` Dennis Dalessandro
@ 2021-09-08 11:44 ` Jason Gunthorpe
1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2021-09-08 11:44 UTC (permalink / raw)
To: Dennis Dalessandro, linux-rdma
Cc: Leon Romanovsky, kernel test robot, Mike Marciniszyn, llvm,
kbuild-all, linux-kernel
On Fri, Sep 03, 2021 at 10:07:28AM -0300, Jason Gunthorpe wrote:
> >> 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")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> Acked-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
> ---
> drivers/infiniband/hw/qib/qib_sysfs.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
Applied to for-rc
Jason
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-08 11:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 13:07 [PATCH] IB/qib: Fix null pointer subtraction compiler warning Jason Gunthorpe
2021-09-03 17:24 ` Dennis Dalessandro
2021-09-08 11:44 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).