* [PATCH 5/5] sound/aoa: Add kmalloc NULL tests
@ 2009-07-30 14:11 Julia Lawall
2009-07-30 14:17 ` Johannes Berg
0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2009-07-30 14:11 UTC (permalink / raw)
To: johannes, linuxppc-dev, alsa-devel, linux-kernel, kernel-janitors
From: Julia Lawall <julia@diku.dk>
Check that the result of kzalloc is not NULL before a dereference.
The semantic match that finds this problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@@
expression *x;
identifier f;
constant char *C;
@@
x = \(kmalloc\|kcalloc\|kzalloc\)(...);
... when != x == NULL
when != x != NULL
when != (x || ...)
(
kfree(x)
|
f(...,C,...,x,...)
|
*f(...,x,...)
|
*x->f
)
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
sound/aoa/core/gpio-pmf.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/sound/aoa/core/gpio-pmf.c b/sound/aoa/core/gpio-pmf.c
index 5ca2220..b4439ce 100644
--- a/sound/aoa/core/gpio-pmf.c
+++ b/sound/aoa/core/gpio-pmf.c
@@ -182,6 +182,12 @@ static int pmf_set_notify(struct gpio_runtime *rt,
if (!old && notify) {
irq_client = kzalloc(sizeof(struct pmf_irq_client),
GFP_KERNEL);
+ if (!irq_client) {
+ err = -ENOMEM;
+ printk(KERN_ERR "snd-aoa: gpio layer failed to"
+ " register %s irq (%d)\n", name, err);
+ goto out_unlock;
+ }
irq_client->data = notif;
irq_client->handler = pmf_handle_notify_irq;
irq_client->owner = THIS_MODULE;
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 5/5] sound/aoa: Add kmalloc NULL tests
2009-07-30 14:11 [PATCH 5/5] sound/aoa: Add kmalloc NULL tests Julia Lawall
@ 2009-07-30 14:17 ` Johannes Berg
2009-07-30 14:29 ` Julia Lawall
0 siblings, 1 reply; 7+ messages in thread
From: Johannes Berg @ 2009-07-30 14:17 UTC (permalink / raw)
To: Julia Lawall; +Cc: linuxppc-dev, alsa-devel, kernel-janitors, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 578 bytes --]
On Thu, 2009-07-30 at 16:11 +0200, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
>
> Check that the result of kzalloc is not NULL before a dereference.
> irq_client = kzalloc(sizeof(struct pmf_irq_client),
> GFP_KERNEL);
> + if (!irq_client) {
> + err = -ENOMEM;
> + printk(KERN_ERR "snd-aoa: gpio layer failed to"
> + " register %s irq (%d)\n", name, err);
> + goto out_unlock;
> + }
Looks good, thanks, but I'd really drop the printk if only to not have
the string there, that doesn't really seem interesting.
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 5/5] sound/aoa: Add kmalloc NULL tests
2009-07-30 14:17 ` Johannes Berg
@ 2009-07-30 14:29 ` Julia Lawall
2009-07-31 6:22 ` Takashi Iwai
0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2009-07-30 14:29 UTC (permalink / raw)
To: Johannes Berg; +Cc: linuxppc-dev, alsa-devel, kernel-janitors, linux-kernel
On Thu, 30 Jul 2009, Johannes Berg wrote:
> On Thu, 2009-07-30 at 16:11 +0200, Julia Lawall wrote:
> > From: Julia Lawall <julia@diku.dk>
> >
> > Check that the result of kzalloc is not NULL before a dereference.
>
> > irq_client = kzalloc(sizeof(struct pmf_irq_client),
> > GFP_KERNEL);
> > + if (!irq_client) {
> > + err = -ENOMEM;
> > + printk(KERN_ERR "snd-aoa: gpio layer failed to"
> > + " register %s irq (%d)\n", name, err);
> > + goto out_unlock;
> > + }
>
> Looks good, thanks, but I'd really drop the printk if only to not have
> the string there, that doesn't really seem interesting.
The printk is based on similar error handling code a few lines later:
if (err) {
printk(KERN_ERR "snd-aoa: gpio layer failed to"
" register %s irq (%d)\n", name,
err);
kfree(irq_client);
goto out_unlock;
}
Should the printk be removed in this case as well? Or is it ok to fail
silently in one case and not in the other?
julia
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 5/5] sound/aoa: Add kmalloc NULL tests
2009-07-30 14:29 ` Julia Lawall
@ 2009-07-31 6:22 ` Takashi Iwai
2009-07-31 6:31 ` Julia Lawall
2009-07-31 6:32 ` Julia Lawall
0 siblings, 2 replies; 7+ messages in thread
From: Takashi Iwai @ 2009-07-31 6:22 UTC (permalink / raw)
To: Julia Lawall
Cc: linuxppc-dev, Johannes Berg, kernel-janitors, alsa-devel,
linux-kernel
At Thu, 30 Jul 2009 16:29:54 +0200 (CEST),
Julia Lawall wrote:
>
> On Thu, 30 Jul 2009, Johannes Berg wrote:
>
> > On Thu, 2009-07-30 at 16:11 +0200, Julia Lawall wrote:
> > > From: Julia Lawall <julia@diku.dk>
> > >
> > > Check that the result of kzalloc is not NULL before a dereference.
> >
> > > irq_client = kzalloc(sizeof(struct pmf_irq_client),
> > > GFP_KERNEL);
> > > + if (!irq_client) {
> > > + err = -ENOMEM;
> > > + printk(KERN_ERR "snd-aoa: gpio layer failed to"
> > > + " register %s irq (%d)\n", name, err);
> > > + goto out_unlock;
> > > + }
> >
> > Looks good, thanks, but I'd really drop the printk if only to not have
> > the string there, that doesn't really seem interesting.
>
> The printk is based on similar error handling code a few lines later:
But another problem is that the same error message is reused although
the error condition is totally different. The kzalloc NULL isn't
about the registration error. So, it's rather confusing.
However, for this particular error path, I agree with Johannes; we can
skip the error message since the error code ENOMEM is obvious.
thanks,
Takashi
>
> if (err) {
> printk(KERN_ERR "snd-aoa: gpio layer failed to"
> " register %s irq (%d)\n", name,
> err);
> kfree(irq_client);
> goto out_unlock;
> }
>
> Should the printk be removed in this case as well? Or is it ok to fail
> silently in one case and not in the other?
>
> julia
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 5/5] sound/aoa: Add kmalloc NULL tests
2009-07-31 6:22 ` Takashi Iwai
@ 2009-07-31 6:31 ` Julia Lawall
2009-07-31 6:32 ` Julia Lawall
1 sibling, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2009-07-31 6:31 UTC (permalink / raw)
To: Takashi Iwai
Cc: linuxppc-dev, Johannes Berg, kernel-janitors, alsa-devel,
linux-kernel
On Fri, 31 Jul 2009, Takashi Iwai wrote:
> At Thu, 30 Jul 2009 16:29:54 +0200 (CEST),
> Julia Lawall wrote:
> >
> > On Thu, 30 Jul 2009, Johannes Berg wrote:
> >
> > > On Thu, 2009-07-30 at 16:11 +0200, Julia Lawall wrote:
> > > > From: Julia Lawall <julia@diku.dk>
> > > >
> > > > Check that the result of kzalloc is not NULL before a dereference.
> > >
> > > > irq_client = kzalloc(sizeof(struct pmf_irq_client),
> > > > GFP_KERNEL);
> > > > + if (!irq_client) {
> > > > + err = -ENOMEM;
> > > > + printk(KERN_ERR "snd-aoa: gpio layer failed to"
> > > > + " register %s irq (%d)\n", name, err);
> > > > + goto out_unlock;
> > > > + }
> > >
> > > Looks good, thanks, but I'd really drop the printk if only to not have
> > > the string there, that doesn't really seem interesting.
> >
> > The printk is based on similar error handling code a few lines later:
>
> But another problem is that the same error message is reused although
> the error condition is totally different. The kzalloc NULL isn't
> about the registration error. So, it's rather confusing.
>
> However, for this particular error path, I agree with Johannes; we can
> skip the error message since the error code ENOMEM is obvious.
OK, I will send a new patch.
julia
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 5/5] sound/aoa: Add kmalloc NULL tests
2009-07-31 6:22 ` Takashi Iwai
2009-07-31 6:31 ` Julia Lawall
@ 2009-07-31 6:32 ` Julia Lawall
2009-07-31 8:16 ` Takashi Iwai
1 sibling, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2009-07-31 6:32 UTC (permalink / raw)
To: Takashi Iwai
Cc: linuxppc-dev, Johannes Berg, kernel-janitors, alsa-devel,
linux-kernel
From: Julia Lawall <julia@diku.dk>
Check that the result of kzalloc is not NULL before a dereference.
The semantic match that finds this problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@@
expression *x;
identifier f;
constant char *C;
@@
x = \(kmalloc\|kcalloc\|kzalloc\)(...);
... when != x == NULL
when != x != NULL
when != (x || ...)
(
kfree(x)
|
f(...,C,...,x,...)
|
*f(...,x,...)
|
*x->f
)
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
sound/aoa/core/gpio-pmf.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/var/linuxes/linux-next/sound/aoa/core/gpio-pmf.c b/var/julia/linuxcopy/sound/aoa/core/gpio-pmf.c
index 5ca2220..1dd0c28 100644
--- a/var/linuxes/linux-next/sound/aoa/core/gpio-pmf.c
+++ b/var/julia/linuxcopy/sound/aoa/core/gpio-pmf.c
@@ -182,6 +182,10 @@ static int pmf_set_notify(struct gpio_runtime *rt,
if (!old && notify) {
irq_client = kzalloc(sizeof(struct pmf_irq_client),
GFP_KERNEL);
+ if (!irq_client) {
+ err = -ENOMEM;
+ goto out_unlock;
+ }
irq_client->data = notif;
irq_client->handler = pmf_handle_notify_irq;
irq_client->owner = THIS_MODULE;
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 5/5] sound/aoa: Add kmalloc NULL tests
2009-07-31 6:32 ` Julia Lawall
@ 2009-07-31 8:16 ` Takashi Iwai
0 siblings, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2009-07-31 8:16 UTC (permalink / raw)
To: Julia Lawall
Cc: linuxppc-dev, Johannes Berg, kernel-janitors, alsa-devel,
linux-kernel
At Fri, 31 Jul 2009 08:32:03 +0200 (CEST),
Julia Lawall wrote:
>
> From: Julia Lawall <julia@diku.dk>
>
> Check that the result of kzalloc is not NULL before a dereference.
>
> The semantic match that finds this problem is as follows:
> (http://www.emn.fr/x-info/coccinelle/)
>
> // <smpl>
> @@
> expression *x;
> identifier f;
> constant char *C;
> @@
>
> x = \(kmalloc\|kcalloc\|kzalloc\)(...);
> ... when != x == NULL
> when != x != NULL
> when != (x || ...)
> (
> kfree(x)
> |
> f(...,C,...,x,...)
> |
> *f(...,x,...)
> |
> *x->f
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
Applied now.
But, please fix the path of the file correctly applicable to linux
kernel tree at the next time. It includes /var/x/y, and confuses git
am totally.
thanks,
Takashi
>
> ---
> sound/aoa/core/gpio-pmf.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/var/linuxes/linux-next/sound/aoa/core/gpio-pmf.c b/var/julia/linuxcopy/sound/aoa/core/gpio-pmf.c
> index 5ca2220..1dd0c28 100644
> --- a/var/linuxes/linux-next/sound/aoa/core/gpio-pmf.c
> +++ b/var/julia/linuxcopy/sound/aoa/core/gpio-pmf.c
> @@ -182,6 +182,10 @@ static int pmf_set_notify(struct gpio_runtime *rt,
> if (!old && notify) {
> irq_client = kzalloc(sizeof(struct pmf_irq_client),
> GFP_KERNEL);
> + if (!irq_client) {
> + err = -ENOMEM;
> + goto out_unlock;
> + }
> irq_client->data = notif;
> irq_client->handler = pmf_handle_notify_irq;
> irq_client->owner = THIS_MODULE;
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-07-31 8:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-30 14:11 [PATCH 5/5] sound/aoa: Add kmalloc NULL tests Julia Lawall
2009-07-30 14:17 ` Johannes Berg
2009-07-30 14:29 ` Julia Lawall
2009-07-31 6:22 ` Takashi Iwai
2009-07-31 6:31 ` Julia Lawall
2009-07-31 6:32 ` Julia Lawall
2009-07-31 8:16 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox