* [PATCH] RDMA/siw: Fix a memory leak in siw_init_cpulist()
@ 2019-08-09 10:16 Dan Carpenter
2019-08-09 11:44 ` Bernard Metzler
0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2019-08-09 10:16 UTC (permalink / raw)
To: Bernard Metzler
Cc: Doug Ledford, Jason Gunthorpe, linux-rdma, kernel-janitors
The error handling code doesn't free siw_cpu_info.tx_valid_cpus[0]. The
first iteration through the loop is a no-op so this is sort of an off by
one bug.
Fixes: bdcf26bf9b3a ("rdma/siw: network and RDMA core interface")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/infiniband/sw/siw/siw_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/sw/siw/siw_main.c b/drivers/infiniband/sw/siw/siw_main.c
index d0f140daf659..95ace3967391 100644
--- a/drivers/infiniband/sw/siw/siw_main.c
+++ b/drivers/infiniband/sw/siw/siw_main.c
@@ -160,9 +160,9 @@ static int siw_init_cpulist(void)
out_err:
siw_cpu_info.num_nodes = 0;
- while (i) {
+ while (--i >= 0) {
kfree(siw_cpu_info.tx_valid_cpus[i]);
- siw_cpu_info.tx_valid_cpus[i--] = NULL;
+ siw_cpu_info.tx_valid_cpus[i] = NULL;
}
kfree(siw_cpu_info.tx_valid_cpus);
siw_cpu_info.tx_valid_cpus = NULL;
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/siw: Fix a memory leak in siw_init_cpulist()
2019-08-09 10:16 [PATCH] RDMA/siw: Fix a memory leak in siw_init_cpulist() Dan Carpenter
@ 2019-08-09 11:44 ` Bernard Metzler
2019-08-09 11:59 ` Dan Carpenter
2019-08-09 14:09 ` [PATCH v2] " Dan Carpenter
0 siblings, 2 replies; 6+ messages in thread
From: Bernard Metzler @ 2019-08-09 11:44 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Doug Ledford, Jason Gunthorpe, linux-rdma, kernel-janitors
-----"Dan Carpenter" <dan.carpenter@oracle.com> wrote: -----
>To: "Bernard Metzler" <bmt@zurich.ibm.com>
>From: "Dan Carpenter" <dan.carpenter@oracle.com>
>Date: 08/09/2019 12:16PM
>Cc: "Doug Ledford" <dledford@redhat.com>, "Jason Gunthorpe"
><jgg@ziepe.ca>, linux-rdma@vger.kernel.org,
>kernel-janitors@vger.kernel.org
>Subject: [EXTERNAL] [PATCH] RDMA/siw: Fix a memory leak in
>siw_init_cpulist()
>
>The error handling code doesn't free siw_cpu_info.tx_valid_cpus[0].
>The
>first iteration through the loop is a no-op so this is sort of an off
>by
>one bug.
>
>Fixes: bdcf26bf9b3a ("rdma/siw: network and RDMA core interface")
>Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>---
> drivers/infiniband/sw/siw/siw_main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/infiniband/sw/siw/siw_main.c
>b/drivers/infiniband/sw/siw/siw_main.c
>index d0f140daf659..95ace3967391 100644
>--- a/drivers/infiniband/sw/siw/siw_main.c
>+++ b/drivers/infiniband/sw/siw/siw_main.c
>@@ -160,9 +160,9 @@ static int siw_init_cpulist(void)
>
> out_err:
> siw_cpu_info.num_nodes = 0;
>- while (i) {
>+ while (--i >= 0) {
> kfree(siw_cpu_info.tx_valid_cpus[i]);
>- siw_cpu_info.tx_valid_cpus[i--] = NULL;
>+ siw_cpu_info.tx_valid_cpus[i] = NULL;
> }
> kfree(siw_cpu_info.tx_valid_cpus);
> siw_cpu_info.tx_valid_cpus = NULL;
>--
>2.20.1
>
>
Dan, many thanks for catching this one!
I suggest you provide an even simpler fix, taking the
chance to remove the redundant
"siw_cpu_info.tx_valid_cpus[i] = NULL;" line (since
the whole structure gets kfree'd a line further
down...).
This shall be suffcient:
- while (i) {
+ while (--i >= 0)
kfree(siw_cpu_info.tx_valid_cpus[i]);
- siw_cpu_info.tx_valid_cpus[i--] = NULL;
- }
+
Reviewed-by: Bernard Metzler <bmt@zurich.ibm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/siw: Fix a memory leak in siw_init_cpulist()
2019-08-09 11:44 ` Bernard Metzler
@ 2019-08-09 11:59 ` Dan Carpenter
2019-08-09 14:09 ` [PATCH v2] " Dan Carpenter
1 sibling, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-08-09 11:59 UTC (permalink / raw)
To: Bernard Metzler
Cc: Doug Ledford, Jason Gunthorpe, linux-rdma, kernel-janitors
On Fri, Aug 09, 2019 at 11:44:45AM +0000, Bernard Metzler wrote:
> -----"Dan Carpenter" <dan.carpenter@oracle.com> wrote: -----
>
> >To: "Bernard Metzler" <bmt@zurich.ibm.com>
> >From: "Dan Carpenter" <dan.carpenter@oracle.com>
> >Date: 08/09/2019 12:16PM
> >Cc: "Doug Ledford" <dledford@redhat.com>, "Jason Gunthorpe"
> ><jgg@ziepe.ca>, linux-rdma@vger.kernel.org,
> >kernel-janitors@vger.kernel.org
> >Subject: [EXTERNAL] [PATCH] RDMA/siw: Fix a memory leak in
> >siw_init_cpulist()
> >
> >The error handling code doesn't free siw_cpu_info.tx_valid_cpus[0].
> >The
> >first iteration through the loop is a no-op so this is sort of an off
> >by
> >one bug.
> >
> >Fixes: bdcf26bf9b3a ("rdma/siw: network and RDMA core interface")
> >Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> >---
> > drivers/infiniband/sw/siw/siw_main.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> >diff --git a/drivers/infiniband/sw/siw/siw_main.c
> >b/drivers/infiniband/sw/siw/siw_main.c
> >index d0f140daf659..95ace3967391 100644
> >--- a/drivers/infiniband/sw/siw/siw_main.c
> >+++ b/drivers/infiniband/sw/siw/siw_main.c
> >@@ -160,9 +160,9 @@ static int siw_init_cpulist(void)
> >
> > out_err:
> > siw_cpu_info.num_nodes = 0;
> >- while (i) {
> >+ while (--i >= 0) {
> > kfree(siw_cpu_info.tx_valid_cpus[i]);
> >- siw_cpu_info.tx_valid_cpus[i--] = NULL;
> >+ siw_cpu_info.tx_valid_cpus[i] = NULL;
> > }
> > kfree(siw_cpu_info.tx_valid_cpus);
> > siw_cpu_info.tx_valid_cpus = NULL;
> >--
> >2.20.1
> >
> >
> Dan, many thanks for catching this one!
>
> I suggest you provide an even simpler fix, taking the
> chance to remove the redundant
> "siw_cpu_info.tx_valid_cpus[i] = NULL;" line (since
> the whole structure gets kfree'd a line further
> down...).
> This shall be suffcient:
>
> - while (i) {
> + while (--i >= 0)
> kfree(siw_cpu_info.tx_valid_cpus[i]);
> - siw_cpu_info.tx_valid_cpus[i--] = NULL;
Yeah that's a good point. I'll resend.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] RDMA/siw: Fix a memory leak in siw_init_cpulist()
2019-08-09 11:44 ` Bernard Metzler
2019-08-09 11:59 ` Dan Carpenter
@ 2019-08-09 14:09 ` Dan Carpenter
2019-08-09 14:28 ` Bernard Metzler
1 sibling, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2019-08-09 14:09 UTC (permalink / raw)
To: Bernard Metzler
Cc: Doug Ledford, Jason Gunthorpe, linux-rdma, kernel-janitors
The error handling code doesn't free siw_cpu_info.tx_valid_cpus[0]. The
first iteration through the loop is a no-op so this is sort of an off
by one bug. Also Bernard pointed out that we can remove the NULL
assignment and simplify the code a bit.
Fixes: bdcf26bf9b3a ("rdma/siw: network and RDMA core interface")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Bernard Metzler <bmt@zurich.ibm.com>
---
v2: Remove the NULL assignment like Bernard Metzler pointed out.
drivers/infiniband/sw/siw/siw_main.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/infiniband/sw/siw/siw_main.c b/drivers/infiniband/sw/siw/siw_main.c
index d0f140daf659..05a92f997f60 100644
--- a/drivers/infiniband/sw/siw/siw_main.c
+++ b/drivers/infiniband/sw/siw/siw_main.c
@@ -160,10 +160,8 @@ static int siw_init_cpulist(void)
out_err:
siw_cpu_info.num_nodes = 0;
- while (i) {
+ while (--i >= 0)
kfree(siw_cpu_info.tx_valid_cpus[i]);
- siw_cpu_info.tx_valid_cpus[i--] = NULL;
- }
kfree(siw_cpu_info.tx_valid_cpus);
siw_cpu_info.tx_valid_cpus = NULL;
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] RDMA/siw: Fix a memory leak in siw_init_cpulist()
2019-08-09 14:09 ` [PATCH v2] " Dan Carpenter
@ 2019-08-09 14:28 ` Bernard Metzler
2019-08-12 14:53 ` Doug Ledford
0 siblings, 1 reply; 6+ messages in thread
From: Bernard Metzler @ 2019-08-09 14:28 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Doug Ledford, Jason Gunthorpe, linux-rdma, kernel-janitors
-----"Dan Carpenter" <dan.carpenter@oracle.com> wrote: -----
>To: "Bernard Metzler" <bmt@zurich.ibm.com>
>From: "Dan Carpenter" <dan.carpenter@oracle.com>
>Date: 08/09/2019 04:09PM
>Cc: "Doug Ledford" <dledford@redhat.com>, "Jason Gunthorpe"
><jgg@ziepe.ca>, linux-rdma@vger.kernel.org,
>kernel-janitors@vger.kernel.org
>Subject: [EXTERNAL] [PATCH v2] RDMA/siw: Fix a memory leak in
>siw_init_cpulist()
>
>The error handling code doesn't free siw_cpu_info.tx_valid_cpus[0].
>The
>first iteration through the loop is a no-op so this is sort of an off
>by one bug. Also Bernard pointed out that we can remove the NULL
>assignment and simplify the code a bit.
>
>Fixes: bdcf26bf9b3a ("rdma/siw: network and RDMA core interface")
>Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>Reviewed-by: Bernard Metzler <bmt@zurich.ibm.com>
>---
>v2: Remove the NULL assignment like Bernard Metzler pointed out.
>
> drivers/infiniband/sw/siw/siw_main.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
>diff --git a/drivers/infiniband/sw/siw/siw_main.c
>b/drivers/infiniband/sw/siw/siw_main.c
>index d0f140daf659..05a92f997f60 100644
>--- a/drivers/infiniband/sw/siw/siw_main.c
>+++ b/drivers/infiniband/sw/siw/siw_main.c
>@@ -160,10 +160,8 @@ static int siw_init_cpulist(void)
>
> out_err:
> siw_cpu_info.num_nodes = 0;
>- while (i) {
>+ while (--i >= 0)
> kfree(siw_cpu_info.tx_valid_cpus[i]);
>- siw_cpu_info.tx_valid_cpus[i--] = NULL;
>- }
> kfree(siw_cpu_info.tx_valid_cpus);
> siw_cpu_info.tx_valid_cpus = NULL;
>
>--
>2.20.1
>
>
Dan, many thanks for finding and fixing this!
Reviewed-by: Bernard Metzler <bmt@zurich.ibm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] RDMA/siw: Fix a memory leak in siw_init_cpulist()
2019-08-09 14:28 ` Bernard Metzler
@ 2019-08-12 14:53 ` Doug Ledford
0 siblings, 0 replies; 6+ messages in thread
From: Doug Ledford @ 2019-08-12 14:53 UTC (permalink / raw)
To: Bernard Metzler, Dan Carpenter
Cc: Jason Gunthorpe, linux-rdma, kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 2087 bytes --]
On Fri, 2019-08-09 at 14:28 +0000, Bernard Metzler wrote:
> -----"Dan Carpenter" <dan.carpenter@oracle.com> wrote: -----
>
> > To: "Bernard Metzler" <bmt@zurich.ibm.com>
> > From: "Dan Carpenter" <dan.carpenter@oracle.com>
> > Date: 08/09/2019 04:09PM
> > Cc: "Doug Ledford" <dledford@redhat.com>, "Jason Gunthorpe"
> > <jgg@ziepe.ca>, linux-rdma@vger.kernel.org,
> > kernel-janitors@vger.kernel.org
> > Subject: [EXTERNAL] [PATCH v2] RDMA/siw: Fix a memory leak in
> > siw_init_cpulist()
> >
> > The error handling code doesn't free siw_cpu_info.tx_valid_cpus[0].
> > The
> > first iteration through the loop is a no-op so this is sort of an
> > off
> > by one bug. Also Bernard pointed out that we can remove the NULL
> > assignment and simplify the code a bit.
> >
> > Fixes: bdcf26bf9b3a ("rdma/siw: network and RDMA core interface")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Reviewed-by: Bernard Metzler <bmt@zurich.ibm.com>
> > ---
> > v2: Remove the NULL assignment like Bernard Metzler pointed out.
> >
> > drivers/infiniband/sw/siw/siw_main.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/infiniband/sw/siw/siw_main.c
> > b/drivers/infiniband/sw/siw/siw_main.c
> > index d0f140daf659..05a92f997f60 100644
> > --- a/drivers/infiniband/sw/siw/siw_main.c
> > +++ b/drivers/infiniband/sw/siw/siw_main.c
> > @@ -160,10 +160,8 @@ static int siw_init_cpulist(void)
> >
> > out_err:
> > siw_cpu_info.num_nodes = 0;
> > - while (i) {
> > + while (--i >= 0)
> > kfree(siw_cpu_info.tx_valid_cpus[i]);
> > - siw_cpu_info.tx_valid_cpus[i--] = NULL;
> > - }
> > kfree(siw_cpu_info.tx_valid_cpus);
> > siw_cpu_info.tx_valid_cpus = NULL;
> >
> > --
> > 2.20.1
> >
> >
>
> Dan, many thanks for finding and fixing this!
>
>
> Reviewed-by: Bernard Metzler <bmt@zurich.ibm.com>
>
Thanks, applied to for-rc.
--
Doug Ledford <dledford@redhat.com>
GPG KeyID: B826A3330E572FDD
Fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-08-12 14:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-09 10:16 [PATCH] RDMA/siw: Fix a memory leak in siw_init_cpulist() Dan Carpenter
2019-08-09 11:44 ` Bernard Metzler
2019-08-09 11:59 ` Dan Carpenter
2019-08-09 14:09 ` [PATCH v2] " Dan Carpenter
2019-08-09 14:28 ` Bernard Metzler
2019-08-12 14:53 ` Doug Ledford
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).