* [PATCH] sparc: kernel/sbus.c: fix memory leakage
@ 2013-01-14 21:36 ` Cong Ding
0 siblings, 0 replies; 18+ messages in thread
From: Cong Ding @ 2013-01-14 21:36 UTC (permalink / raw)
To: David S. Miller, Cong Ding, sparclinux, linux-kernel
the variable iommu and strbuf are not freed if it goes to error.
Signed-off-by: Cong Ding <dinggnu@gmail.com>
---
arch/sparc/kernel/sbus.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
index 1271b3a..0b66e53 100644
--- a/arch/sparc/kernel/sbus.c
+++ b/arch/sparc/kernel/sbus.c
@@ -555,10 +555,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
if (!iommu)
- goto fatal_memory_error;
+ goto fatal_iommu_memory_error;
strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
if (!strbuf)
- goto fatal_memory_error;
+ goto fatal_strbuf_memory_error;
op->dev.archdata.iommu = iommu;
op->dev.archdata.stc = strbuf;
@@ -656,6 +656,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
return;
fatal_memory_error:
+ kfree(strbuf);
+fatal_strbuf_memory_error:
+ kfree(iommu);
+fatal_iommu_memory_error:
prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH] sparc: kernel/sbus.c: fix memory leakage
@ 2013-01-14 21:36 ` Cong Ding
0 siblings, 0 replies; 18+ messages in thread
From: Cong Ding @ 2013-01-14 21:36 UTC (permalink / raw)
To: David S. Miller, Cong Ding, sparclinux, linux-kernel
the variable iommu and strbuf are not freed if it goes to error.
Signed-off-by: Cong Ding <dinggnu@gmail.com>
---
arch/sparc/kernel/sbus.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
index 1271b3a..0b66e53 100644
--- a/arch/sparc/kernel/sbus.c
+++ b/arch/sparc/kernel/sbus.c
@@ -555,10 +555,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
if (!iommu)
- goto fatal_memory_error;
+ goto fatal_iommu_memory_error;
strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
if (!strbuf)
- goto fatal_memory_error;
+ goto fatal_strbuf_memory_error;
op->dev.archdata.iommu = iommu;
op->dev.archdata.stc = strbuf;
@@ -656,6 +656,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
return;
fatal_memory_error:
+ kfree(strbuf);
+fatal_strbuf_memory_error:
+ kfree(iommu);
+fatal_iommu_memory_error:
prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH] sparc: kernel/sbus.c: fix memory leakage
2013-01-14 21:36 ` Cong Ding
@ 2013-01-16 21:13 ` Sam Ravnborg
-1 siblings, 0 replies; 18+ messages in thread
From: Sam Ravnborg @ 2013-01-16 21:13 UTC (permalink / raw)
To: Cong Ding; +Cc: David S. Miller, sparclinux, linux-kernel
On Mon, Jan 14, 2013 at 10:36:08PM +0100, Cong Ding wrote:
> the variable iommu and strbuf are not freed if it goes to error.
>
> Signed-off-by: Cong Ding <dinggnu@gmail.com>
> ---
> arch/sparc/kernel/sbus.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
> index 1271b3a..0b66e53 100644
> --- a/arch/sparc/kernel/sbus.c
> +++ b/arch/sparc/kernel/sbus.c
> @@ -555,10 +555,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
>
> iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
> if (!iommu)
> - goto fatal_memory_error;
> + goto fatal_iommu_memory_error;
> strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
> if (!strbuf)
> - goto fatal_memory_error;
> + goto fatal_strbuf_memory_error;
>
> op->dev.archdata.iommu = iommu;
> op->dev.archdata.stc = strbuf;
> @@ -656,6 +656,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
> return;
>
> fatal_memory_error:
> + kfree(strbuf);
> +fatal_strbuf_memory_error:
> + kfree(iommu);
> +fatal_iommu_memory_error:
> prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
> }
kfree is a noop if passed a null pointer.
So you can just add the missing kfree's to fix this.
Sam
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] sparc: kernel/sbus.c: fix memory leakage
@ 2013-01-16 21:13 ` Sam Ravnborg
0 siblings, 0 replies; 18+ messages in thread
From: Sam Ravnborg @ 2013-01-16 21:13 UTC (permalink / raw)
To: Cong Ding; +Cc: David S. Miller, sparclinux, linux-kernel
On Mon, Jan 14, 2013 at 10:36:08PM +0100, Cong Ding wrote:
> the variable iommu and strbuf are not freed if it goes to error.
>
> Signed-off-by: Cong Ding <dinggnu@gmail.com>
> ---
> arch/sparc/kernel/sbus.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
> index 1271b3a..0b66e53 100644
> --- a/arch/sparc/kernel/sbus.c
> +++ b/arch/sparc/kernel/sbus.c
> @@ -555,10 +555,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
>
> iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
> if (!iommu)
> - goto fatal_memory_error;
> + goto fatal_iommu_memory_error;
> strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
> if (!strbuf)
> - goto fatal_memory_error;
> + goto fatal_strbuf_memory_error;
>
> op->dev.archdata.iommu = iommu;
> op->dev.archdata.stc = strbuf;
> @@ -656,6 +656,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
> return;
>
> fatal_memory_error:
> + kfree(strbuf);
> +fatal_strbuf_memory_error:
> + kfree(iommu);
> +fatal_iommu_memory_error:
> prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
> }
kfree is a noop if passed a null pointer.
So you can just add the missing kfree's to fix this.
Sam
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] sparc: kernel/sbus.c: fix memory leakage
2013-01-16 21:13 ` Sam Ravnborg
@ 2013-01-16 21:17 ` Cong Ding
-1 siblings, 0 replies; 18+ messages in thread
From: Cong Ding @ 2013-01-16 21:17 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: David S. Miller, sparclinux, linux-kernel
On Wed, Jan 16, 2013 at 10:13:09PM +0100, Sam Ravnborg wrote:
> On Mon, Jan 14, 2013 at 10:36:08PM +0100, Cong Ding wrote:
> > the variable iommu and strbuf are not freed if it goes to error.
> >
> > Signed-off-by: Cong Ding <dinggnu@gmail.com>
> > ---
> > arch/sparc/kernel/sbus.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
> > index 1271b3a..0b66e53 100644
> > --- a/arch/sparc/kernel/sbus.c
> > +++ b/arch/sparc/kernel/sbus.c
> > @@ -555,10 +555,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
> >
> > iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
> > if (!iommu)
> > - goto fatal_memory_error;
> > + goto fatal_iommu_memory_error;
> > strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
> > if (!strbuf)
> > - goto fatal_memory_error;
> > + goto fatal_strbuf_memory_error;
> >
> > op->dev.archdata.iommu = iommu;
> > op->dev.archdata.stc = strbuf;
> > @@ -656,6 +656,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
> > return;
> >
> > fatal_memory_error:
> > + kfree(strbuf);
> > +fatal_strbuf_memory_error:
> > + kfree(iommu);
> > +fatal_iommu_memory_error:
> > prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
> > }
> kfree is a noop if passed a null pointer.
> So you can just add the missing kfree's to fix this.
>
> Sam
as far as I know, most codes in the kernel are in the same style as this
patch, but if you really prefer to do in the way you described I can send
a new version.
Let me know.
- cong
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] sparc: kernel/sbus.c: fix memory leakage
@ 2013-01-16 21:17 ` Cong Ding
0 siblings, 0 replies; 18+ messages in thread
From: Cong Ding @ 2013-01-16 21:17 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: David S. Miller, sparclinux, linux-kernel
On Wed, Jan 16, 2013 at 10:13:09PM +0100, Sam Ravnborg wrote:
> On Mon, Jan 14, 2013 at 10:36:08PM +0100, Cong Ding wrote:
> > the variable iommu and strbuf are not freed if it goes to error.
> >
> > Signed-off-by: Cong Ding <dinggnu@gmail.com>
> > ---
> > arch/sparc/kernel/sbus.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
> > index 1271b3a..0b66e53 100644
> > --- a/arch/sparc/kernel/sbus.c
> > +++ b/arch/sparc/kernel/sbus.c
> > @@ -555,10 +555,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
> >
> > iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
> > if (!iommu)
> > - goto fatal_memory_error;
> > + goto fatal_iommu_memory_error;
> > strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
> > if (!strbuf)
> > - goto fatal_memory_error;
> > + goto fatal_strbuf_memory_error;
> >
> > op->dev.archdata.iommu = iommu;
> > op->dev.archdata.stc = strbuf;
> > @@ -656,6 +656,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
> > return;
> >
> > fatal_memory_error:
> > + kfree(strbuf);
> > +fatal_strbuf_memory_error:
> > + kfree(iommu);
> > +fatal_iommu_memory_error:
> > prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
> > }
> kfree is a noop if passed a null pointer.
> So you can just add the missing kfree's to fix this.
>
> Sam
as far as I know, most codes in the kernel are in the same style as this
patch, but if you really prefer to do in the way you described I can send
a new version.
Let me know.
- cong
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] sparc: kernel/sbus.c: fix memory leakage
2013-01-16 21:17 ` Cong Ding
@ 2013-01-16 22:00 ` Sam Ravnborg
-1 siblings, 0 replies; 18+ messages in thread
From: Sam Ravnborg @ 2013-01-16 22:00 UTC (permalink / raw)
To: Cong Ding; +Cc: David S. Miller, sparclinux, linux-kernel
On Wed, Jan 16, 2013 at 10:17:26PM +0100, Cong Ding wrote:
> On Wed, Jan 16, 2013 at 10:13:09PM +0100, Sam Ravnborg wrote:
> > On Mon, Jan 14, 2013 at 10:36:08PM +0100, Cong Ding wrote:
> > > the variable iommu and strbuf are not freed if it goes to error.
> > >
> > > Signed-off-by: Cong Ding <dinggnu@gmail.com>
> > > ---
> > > arch/sparc/kernel/sbus.c | 8 ++++++--
> > > 1 file changed, 6 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
> > > index 1271b3a..0b66e53 100644
> > > --- a/arch/sparc/kernel/sbus.c
> > > +++ b/arch/sparc/kernel/sbus.c
> > > @@ -555,10 +555,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
> > >
> > > iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
> > > if (!iommu)
> > > - goto fatal_memory_error;
> > > + goto fatal_iommu_memory_error;
> > > strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
> > > if (!strbuf)
> > > - goto fatal_memory_error;
> > > + goto fatal_strbuf_memory_error;
> > >
> > > op->dev.archdata.iommu = iommu;
> > > op->dev.archdata.stc = strbuf;
> > > @@ -656,6 +656,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
> > > return;
> > >
> > > fatal_memory_error:
> > > + kfree(strbuf);
> > > +fatal_strbuf_memory_error:
> > > + kfree(iommu);
> > > +fatal_iommu_memory_error:
> > > prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
> > > }
> > kfree is a noop if passed a null pointer.
> > So you can just add the missing kfree's to fix this.
> >
> > Sam
> as far as I know, most codes in the kernel are in the same style as this
> patch, but if you really prefer to do in the way you described I can send
> a new version.
I prefer the simpler variant.
Please redo.
Sam
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] sparc: kernel/sbus.c: fix memory leakage
@ 2013-01-16 22:00 ` Sam Ravnborg
0 siblings, 0 replies; 18+ messages in thread
From: Sam Ravnborg @ 2013-01-16 22:00 UTC (permalink / raw)
To: Cong Ding; +Cc: David S. Miller, sparclinux, linux-kernel
On Wed, Jan 16, 2013 at 10:17:26PM +0100, Cong Ding wrote:
> On Wed, Jan 16, 2013 at 10:13:09PM +0100, Sam Ravnborg wrote:
> > On Mon, Jan 14, 2013 at 10:36:08PM +0100, Cong Ding wrote:
> > > the variable iommu and strbuf are not freed if it goes to error.
> > >
> > > Signed-off-by: Cong Ding <dinggnu@gmail.com>
> > > ---
> > > arch/sparc/kernel/sbus.c | 8 ++++++--
> > > 1 file changed, 6 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
> > > index 1271b3a..0b66e53 100644
> > > --- a/arch/sparc/kernel/sbus.c
> > > +++ b/arch/sparc/kernel/sbus.c
> > > @@ -555,10 +555,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
> > >
> > > iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
> > > if (!iommu)
> > > - goto fatal_memory_error;
> > > + goto fatal_iommu_memory_error;
> > > strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
> > > if (!strbuf)
> > > - goto fatal_memory_error;
> > > + goto fatal_strbuf_memory_error;
> > >
> > > op->dev.archdata.iommu = iommu;
> > > op->dev.archdata.stc = strbuf;
> > > @@ -656,6 +656,10 @@ static void __init sbus_iommu_init(struct platform_device *op)
> > > return;
> > >
> > > fatal_memory_error:
> > > + kfree(strbuf);
> > > +fatal_strbuf_memory_error:
> > > + kfree(iommu);
> > > +fatal_iommu_memory_error:
> > > prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
> > > }
> > kfree is a noop if passed a null pointer.
> > So you can just add the missing kfree's to fix this.
> >
> > Sam
> as far as I know, most codes in the kernel are in the same style as this
> patch, but if you really prefer to do in the way you described I can send
> a new version.
I prefer the simpler variant.
Please redo.
Sam
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2] sparc: kernel/sbus.c: fix memory leakage
2013-01-16 22:00 ` Sam Ravnborg
@ 2013-01-16 22:01 ` Cong Ding
-1 siblings, 0 replies; 18+ messages in thread
From: Cong Ding @ 2013-01-16 22:01 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: David S. Miller, sparclinux, linux-kernel
the variable iommu and strbuf are not freed if it goes to error.
Signed-off-by: Cong Ding <dinggnu@gmail.com>
---
arch/sparc/kernel/sbus.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
index 1271b3a..78aa26b 100644
--- a/arch/sparc/kernel/sbus.c
+++ b/arch/sparc/kernel/sbus.c
@@ -656,6 +656,8 @@ static void __init sbus_iommu_init(struct platform_device *op)
return;
fatal_memory_error:
+ kfree(strbuf);
+ kfree(iommu);
prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2] sparc: kernel/sbus.c: fix memory leakage
@ 2013-01-16 22:01 ` Cong Ding
0 siblings, 0 replies; 18+ messages in thread
From: Cong Ding @ 2013-01-16 22:01 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: David S. Miller, sparclinux, linux-kernel
the variable iommu and strbuf are not freed if it goes to error.
Signed-off-by: Cong Ding <dinggnu@gmail.com>
---
arch/sparc/kernel/sbus.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
index 1271b3a..78aa26b 100644
--- a/arch/sparc/kernel/sbus.c
+++ b/arch/sparc/kernel/sbus.c
@@ -656,6 +656,8 @@ static void __init sbus_iommu_init(struct platform_device *op)
return;
fatal_memory_error:
+ kfree(strbuf);
+ kfree(iommu);
prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH v2] sparc: kernel/sbus.c: fix memory leakage
2013-01-16 22:01 ` Cong Ding
(?)
@ 2013-01-17 10:41 ` Richard Mortimer
2013-01-17 11:56 ` Cong Ding
-1 siblings, 1 reply; 18+ messages in thread
From: Richard Mortimer @ 2013-01-17 10:41 UTC (permalink / raw)
To: Cong Ding; +Cc: Sam Ravnborg, David S. Miller, sparclinux, linux-kernel
On 16/01/2013 22:01, Cong Ding wrote:
> the variable iommu and strbuf are not freed if it goes to error.
>
> Signed-off-by: Cong Ding <dinggnu@gmail.com>
> ---
> arch/sparc/kernel/sbus.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
> index 1271b3a..78aa26b 100644
> --- a/arch/sparc/kernel/sbus.c
> +++ b/arch/sparc/kernel/sbus.c
> @@ -656,6 +656,8 @@ static void __init sbus_iommu_init(struct platform_device *op)
> return;
>
> fatal_memory_error:
> + kfree(strbuf);
strbuf will be uninitialized if the iommu allocation fails. I don't have
a particular preference for how to fix this but tend to dislike initial
assignment with NULL because it hides other control flow issues.
Regards
Richard
> + kfree(iommu);
> prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
> }
>
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2] sparc: kernel/sbus.c: fix memory leakage
2013-01-17 10:41 ` Richard Mortimer
@ 2013-01-17 11:56 ` Cong Ding
2013-01-17 12:30 ` Richard Mortimer
0 siblings, 1 reply; 18+ messages in thread
From: Cong Ding @ 2013-01-17 11:56 UTC (permalink / raw)
To: Richard Mortimer; +Cc: Sam Ravnborg, David S. Miller, sparclinux, linux-kernel
On Thu, Jan 17, 2013 at 10:41:59AM +0000, Richard Mortimer wrote:
>
>
> On 16/01/2013 22:01, Cong Ding wrote:
> >the variable iommu and strbuf are not freed if it goes to error.
> >
> >Signed-off-by: Cong Ding <dinggnu@gmail.com>
> >---
> > arch/sparc/kernel/sbus.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> >diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
> >index 1271b3a..78aa26b 100644
> >--- a/arch/sparc/kernel/sbus.c
> >+++ b/arch/sparc/kernel/sbus.c
> >@@ -656,6 +656,8 @@ static void __init sbus_iommu_init(struct platform_device *op)
> > return;
> >
> > fatal_memory_error:
> >+ kfree(strbuf);
>
> strbuf will be uninitialized if the iommu allocation fails. I don't
> have a particular preference for how to fix this but tend to dislike
> initial assignment with NULL because it hides other control flow
> issues.
Sorry I didn't notice strbuf will be uninitialized here. But if we don't
initially assign a NULL value to strbuf, I cannot find a way to handle it
besides the first version patch. Did you have any suggestions? For me, I like
the first version.
- cong
>
> Regards
>
> Richard
>
> >+ kfree(iommu);
> > prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
> > }
> >
> >
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2] sparc: kernel/sbus.c: fix memory leakage
2013-01-17 11:56 ` Cong Ding
@ 2013-01-17 12:30 ` Richard Mortimer
2013-01-17 13:16 ` Cong Ding
2013-01-17 13:28 ` [PATCH v3] " Cong Ding
0 siblings, 2 replies; 18+ messages in thread
From: Richard Mortimer @ 2013-01-17 12:30 UTC (permalink / raw)
To: Cong Ding; +Cc: Sam Ravnborg, David S. Miller, sparclinux, linux-kernel
On 17/01/2013 11:56, Cong Ding wrote:
> On Thu, Jan 17, 2013 at 10:41:59AM +0000, Richard Mortimer wrote:
>>
>>
>> On 16/01/2013 22:01, Cong Ding wrote:
>>> the variable iommu and strbuf are not freed if it goes to error.
>>>
>>> Signed-off-by: Cong Ding <dinggnu@gmail.com>
>>> ---
>>> arch/sparc/kernel/sbus.c | 2 ++
>>> 1 file changed, 2 insertions(+)
>>>
>>> diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
>>> index 1271b3a..78aa26b 100644
>>> --- a/arch/sparc/kernel/sbus.c
>>> +++ b/arch/sparc/kernel/sbus.c
>>> @@ -656,6 +656,8 @@ static void __init sbus_iommu_init(struct platform_device *op)
>>> return;
>>>
>>> fatal_memory_error:
>>> + kfree(strbuf);
>>
>> strbuf will be uninitialized if the iommu allocation fails. I don't
>> have a particular preference for how to fix this but tend to dislike
>> initial assignment with NULL because it hides other control flow
>> issues.
> Sorry I didn't notice strbuf will be uninitialized here. But if we don't
> initially assign a NULL value to strbuf, I cannot find a way to handle it
> besides the first version patch. Did you have any suggestions? For me, I like
> the first version.
Two thoughts...
1 - just use a goto target for the iommu allocation failure and make
that skip the strbuf free call. The others use the existing
fatal_memory_error label.
2 - Move the strbuf kzalloc up 2 lines so that it occurs before the test
for iommu.
2b - In case (2) above the failure test could be changed to
if (!iommu || !strbuf)
to remove duplication of goto.
I'd probably go for 2/2b to address Sam's initial comment.
Regards
Richard
> - cong
>>
>> Regards
>>
>> Richard
>>
>>> + kfree(iommu);
>>> prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
>>> }
>>>
>>>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2] sparc: kernel/sbus.c: fix memory leakage
2013-01-17 12:30 ` Richard Mortimer
@ 2013-01-17 13:16 ` Cong Ding
2013-01-17 13:28 ` [PATCH v3] " Cong Ding
1 sibling, 0 replies; 18+ messages in thread
From: Cong Ding @ 2013-01-17 13:16 UTC (permalink / raw)
To: Richard Mortimer; +Cc: Sam Ravnborg, David S. Miller, sparclinux, linux-kernel
On Thu, Jan 17, 2013 at 12:30:11PM +0000, Richard Mortimer wrote:
>
>
> On 17/01/2013 11:56, Cong Ding wrote:
> >On Thu, Jan 17, 2013 at 10:41:59AM +0000, Richard Mortimer wrote:
> >>
> >>
> >>On 16/01/2013 22:01, Cong Ding wrote:
> >>>the variable iommu and strbuf are not freed if it goes to error.
> >>>
> >>>Signed-off-by: Cong Ding <dinggnu@gmail.com>
> >>>---
> >>> arch/sparc/kernel/sbus.c | 2 ++
> >>> 1 file changed, 2 insertions(+)
> >>>
> >>>diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
> >>>index 1271b3a..78aa26b 100644
> >>>--- a/arch/sparc/kernel/sbus.c
> >>>+++ b/arch/sparc/kernel/sbus.c
> >>>@@ -656,6 +656,8 @@ static void __init sbus_iommu_init(struct platform_device *op)
> >>> return;
> >>>
> >>> fatal_memory_error:
> >>>+ kfree(strbuf);
> >>
> >>strbuf will be uninitialized if the iommu allocation fails. I don't
> >>have a particular preference for how to fix this but tend to dislike
> >>initial assignment with NULL because it hides other control flow
> >>issues.
> >Sorry I didn't notice strbuf will be uninitialized here. But if we don't
> >initially assign a NULL value to strbuf, I cannot find a way to handle it
> >besides the first version patch. Did you have any suggestions? For me, I like
> >the first version.
>
> Two thoughts...
>
> 1 - just use a goto target for the iommu allocation failure and make
> that skip the strbuf free call. The others use the existing
> fatal_memory_error label.
this looks ugly. If we do in this way, why not version 1?
>
> 2 - Move the strbuf kzalloc up 2 lines so that it occurs before the
> test for iommu.
>
> 2b - In case (2) above the failure test could be changed to
> if (!iommu || !strbuf)
> to remove duplication of goto.
I will send a new version by using this solution.
Thanks, - cong
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v3] sparc: kernel/sbus.c: fix memory leakage
2013-01-17 12:30 ` Richard Mortimer
2013-01-17 13:16 ` Cong Ding
@ 2013-01-17 13:28 ` Cong Ding
2013-01-21 22:20 ` Richard Mortimer
1 sibling, 1 reply; 18+ messages in thread
From: Cong Ding @ 2013-01-17 13:28 UTC (permalink / raw)
To: Richard Mortimer; +Cc: Sam Ravnborg, David S. Miller, sparclinux, linux-kernel
The variable iommu and strbuf are not freed properly if it goes to error.
Signed-off-by: Cong Ding <dinggnu@gmail.com>
---
arch/sparc/kernel/sbus.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
index 1271b3a..be5bdf9 100644
--- a/arch/sparc/kernel/sbus.c
+++ b/arch/sparc/kernel/sbus.c
@@ -554,10 +554,8 @@ static void __init sbus_iommu_init(struct platform_device *op)
regs = pr->phys_addr;
iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
- if (!iommu)
- goto fatal_memory_error;
strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
- if (!strbuf)
+ if (!iommu || !strbuf)
goto fatal_memory_error;
op->dev.archdata.iommu = iommu;
@@ -656,6 +654,8 @@ static void __init sbus_iommu_init(struct platform_device *op)
return;
fatal_memory_error:
+ kfree(iommu);
+ kfree(strbuf);
prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
}
--
1.7.4.5
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH v3] sparc: kernel/sbus.c: fix memory leakage
2013-01-17 13:28 ` [PATCH v3] " Cong Ding
@ 2013-01-21 22:20 ` Richard Mortimer
2013-01-21 22:34 ` David Miller
0 siblings, 1 reply; 18+ messages in thread
From: Richard Mortimer @ 2013-01-21 22:20 UTC (permalink / raw)
To: Cong Ding; +Cc: Sam Ravnborg, David S. Miller, sparclinux, linux-kernel
Reviewed-by: Richard Mortimer <richm@oldelvet.org.uk>
On 17/01/2013 13:28, Cong Ding wrote:
> The variable iommu and strbuf are not freed properly if it goes to error.
>
> Signed-off-by: Cong Ding <dinggnu@gmail.com>
> ---
> arch/sparc/kernel/sbus.c | 6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/sparc/kernel/sbus.c b/arch/sparc/kernel/sbus.c
> index 1271b3a..be5bdf9 100644
> --- a/arch/sparc/kernel/sbus.c
> +++ b/arch/sparc/kernel/sbus.c
> @@ -554,10 +554,8 @@ static void __init sbus_iommu_init(struct platform_device *op)
> regs = pr->phys_addr;
>
> iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
> - if (!iommu)
> - goto fatal_memory_error;
> strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
> - if (!strbuf)
> + if (!iommu || !strbuf)
> goto fatal_memory_error;
>
> op->dev.archdata.iommu = iommu;
> @@ -656,6 +654,8 @@ static void __init sbus_iommu_init(struct platform_device *op)
> return;
>
> fatal_memory_error:
> + kfree(iommu);
> + kfree(strbuf);
> prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
> }
>
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v3] sparc: kernel/sbus.c: fix memory leakage
2013-01-21 22:20 ` Richard Mortimer
@ 2013-01-21 22:34 ` David Miller
0 siblings, 0 replies; 18+ messages in thread
From: David Miller @ 2013-01-21 22:34 UTC (permalink / raw)
To: richm; +Cc: dinggnu, sam, sparclinux, linux-kernel
From: Richard Mortimer <richm@oldelvet.org.uk>
Date: Mon, 21 Jan 2013 22:20:36 +0000
> Reviewed-by: Richard Mortimer <richm@oldelvet.org.uk>
>
> On 17/01/2013 13:28, Cong Ding wrote:
>> The variable iommu and strbuf are not freed properly if it goes to
>> error.
>>
>> Signed-off-by: Cong Ding <dinggnu@gmail.com>
Applied, thanks everyone.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v3] sparc: kernel/sbus.c: fix memory leakage
@ 2013-01-21 22:34 ` David Miller
0 siblings, 0 replies; 18+ messages in thread
From: David Miller @ 2013-01-21 22:34 UTC (permalink / raw)
To: richm; +Cc: dinggnu, sam, sparclinux, linux-kernel
From: Richard Mortimer <richm@oldelvet.org.uk>
Date: Mon, 21 Jan 2013 22:20:36 +0000
> Reviewed-by: Richard Mortimer <richm@oldelvet.org.uk>
>
> On 17/01/2013 13:28, Cong Ding wrote:
>> The variable iommu and strbuf are not freed properly if it goes to
>> error.
>>
>> Signed-off-by: Cong Ding <dinggnu@gmail.com>
Applied, thanks everyone.
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2013-01-21 22:34 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-14 21:36 [PATCH] sparc: kernel/sbus.c: fix memory leakage Cong Ding
2013-01-14 21:36 ` Cong Ding
2013-01-16 21:13 ` Sam Ravnborg
2013-01-16 21:13 ` Sam Ravnborg
2013-01-16 21:17 ` Cong Ding
2013-01-16 21:17 ` Cong Ding
2013-01-16 22:00 ` Sam Ravnborg
2013-01-16 22:00 ` Sam Ravnborg
2013-01-16 22:01 ` [PATCH v2] " Cong Ding
2013-01-16 22:01 ` Cong Ding
2013-01-17 10:41 ` Richard Mortimer
2013-01-17 11:56 ` Cong Ding
2013-01-17 12:30 ` Richard Mortimer
2013-01-17 13:16 ` Cong Ding
2013-01-17 13:28 ` [PATCH v3] " Cong Ding
2013-01-21 22:20 ` Richard Mortimer
2013-01-21 22:34 ` David Miller
2013-01-21 22:34 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.