* [PATCH] infiniband: remove unnecessary null check
@ 2022-08-24 8:05 cgel.zte
2022-08-24 8:15 ` Niels Dossche
0 siblings, 1 reply; 3+ messages in thread
From: cgel.zte @ 2022-08-24 8:05 UTC (permalink / raw)
To: dennis.dalessandro
Cc: jgg, leon, linux-rdma, linux-kernel, Minghao Chi, Zeal Robot
From: Minghao Chi <chi.minghao@zte.com.cn>
container_of is never null, so this null check is
unnecessary.
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
---
drivers/infiniband/sw/rdmavt/vt.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/infiniband/sw/rdmavt/vt.c b/drivers/infiniband/sw/rdmavt/vt.c
index 59481ae39505..b2d83b4958fc 100644
--- a/drivers/infiniband/sw/rdmavt/vt.c
+++ b/drivers/infiniband/sw/rdmavt/vt.c
@@ -50,8 +50,6 @@ struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)
struct rvt_dev_info *rdi;
rdi = container_of(_ib_alloc_device(size), struct rvt_dev_info, ibdev);
- if (!rdi)
- return rdi;
rdi->ports = kcalloc(nports, sizeof(*rdi->ports), GFP_KERNEL);
if (!rdi->ports)
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] infiniband: remove unnecessary null check
2022-08-24 8:05 [PATCH] infiniband: remove unnecessary null check cgel.zte
@ 2022-08-24 8:15 ` Niels Dossche
2022-08-24 11:51 ` Leon Romanovsky
0 siblings, 1 reply; 3+ messages in thread
From: Niels Dossche @ 2022-08-24 8:15 UTC (permalink / raw)
To: cgel.zte, dennis.dalessandro
Cc: jgg, leon, linux-rdma, linux-kernel, Minghao Chi, Zeal Robot
On 8/24/22 10:05, cgel.zte@gmail.com wrote:
> From: Minghao Chi <chi.minghao@zte.com.cn>
>
> container_of is never null, so this null check is
> unnecessary.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> ---
> drivers/infiniband/sw/rdmavt/vt.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/drivers/infiniband/sw/rdmavt/vt.c b/drivers/infiniband/sw/rdmavt/vt.c
> index 59481ae39505..b2d83b4958fc 100644
> --- a/drivers/infiniband/sw/rdmavt/vt.c
> +++ b/drivers/infiniband/sw/rdmavt/vt.c
> @@ -50,8 +50,6 @@ struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)
> struct rvt_dev_info *rdi;
>
> rdi = container_of(_ib_alloc_device(size), struct rvt_dev_info, ibdev);
> - if (!rdi)
> - return rdi;
>
> rdi->ports = kcalloc(nports, sizeof(*rdi->ports), GFP_KERNEL);
> if (!rdi->ports)
I believe this patch is incorrect because "_ib_alloc_device" may return a null pointer.
Note that the first member of "rvt_dev_info" is "ib_device", so the check on container_of effectively checks if the allocation failed, which is necessary to check.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] infiniband: remove unnecessary null check
2022-08-24 8:15 ` Niels Dossche
@ 2022-08-24 11:51 ` Leon Romanovsky
0 siblings, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2022-08-24 11:51 UTC (permalink / raw)
To: Niels Dossche
Cc: cgel.zte, dennis.dalessandro, jgg, linux-rdma, linux-kernel,
Minghao Chi, Zeal Robot
On Wed, Aug 24, 2022 at 10:15:56AM +0200, Niels Dossche wrote:
> On 8/24/22 10:05, cgel.zte@gmail.com wrote:
> > From: Minghao Chi <chi.minghao@zte.com.cn>
> >
> > container_of is never null, so this null check is
> > unnecessary.
> >
> > Reported-by: Zeal Robot <zealci@zte.com.cn>
> > Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> > ---
> > drivers/infiniband/sw/rdmavt/vt.c | 2 --
> > 1 file changed, 2 deletions(-)
> >
> > diff --git a/drivers/infiniband/sw/rdmavt/vt.c b/drivers/infiniband/sw/rdmavt/vt.c
> > index 59481ae39505..b2d83b4958fc 100644
> > --- a/drivers/infiniband/sw/rdmavt/vt.c
> > +++ b/drivers/infiniband/sw/rdmavt/vt.c
> > @@ -50,8 +50,6 @@ struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)
> > struct rvt_dev_info *rdi;
> >
> > rdi = container_of(_ib_alloc_device(size), struct rvt_dev_info, ibdev);
> > - if (!rdi)
> > - return rdi;
> >
> > rdi->ports = kcalloc(nports, sizeof(*rdi->ports), GFP_KERNEL);
> > if (!rdi->ports)
>
> I believe this patch is incorrect because "_ib_alloc_device" may return a null pointer.
> Note that the first member of "rvt_dev_info" is "ib_device", so the check on container_of effectively checks if the allocation failed, which is necessary to check.
You are absolutely right, this container_of() and check later are done
on purpose. It is open-coded variant of ib_alloc_device(...) macro.
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-24 11:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-24 8:05 [PATCH] infiniband: remove unnecessary null check cgel.zte
2022-08-24 8:15 ` Niels Dossche
2022-08-24 11:51 ` Leon Romanovsky
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).