Linux ACPI
 help / color / mirror / Atom feed
* [PATCH 9/9] drivers/acpi: correct error-handling code
@ 2009-07-28 15:56 Julia Lawall
  2009-07-29  0:53 ` Zhang Rui
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2009-07-28 15:56 UTC (permalink / raw)
  To: rui.zhang, linux-acpi, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

backlight_device_register may return an ERR_PTR value rather than a valid
pointer.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
identifier fld,fld1;
expression x,E;
@@

 x = backlight_device_register(...)
  ... when != x = E
      when != &x
      when != x->fld1
(
  ((IS_ERR(x))||...)
|
*  x->fld
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 drivers/acpi/video.c                |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 8851315..29788db 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -982,6 +982,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
 		sprintf(name, "acpi_video%d", count++);
 		device->backlight = backlight_device_register(name,
 			NULL, device, &acpi_backlight_ops);
+		if (IS_ERR(device->backlight))
+			return;
 		device->backlight->props.max_brightness = device->brightness->count-3;
 		kfree(name);
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 9/9] drivers/acpi: correct error-handling code
  2009-07-28 15:56 [PATCH 9/9] drivers/acpi: correct error-handling code Julia Lawall
@ 2009-07-29  0:53 ` Zhang Rui
  2009-07-29  2:20   ` Julia Lawall
  2009-12-30  6:51   ` Len Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Zhang Rui @ 2009-07-29  0:53 UTC (permalink / raw)
  To: Julia Lawall
  Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org

On Tue, 2009-07-28 at 23:56 +0800, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> backlight_device_register may return an ERR_PTR value rather than a valid
> pointer.
> 
> A simplified version of the semantic match that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)

> Signed-off-by: Julia Lawall <julia@diku.dk>
> 
> ---
>  drivers/acpi/video.c                |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
> index 8851315..29788db 100644
> --- a/drivers/acpi/video.c
> +++ b/drivers/acpi/video.c
> @@ -982,6 +982,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
>  		sprintf(name, "acpi_video%d", count++);
>  		device->backlight = backlight_device_register(name,
>  			NULL, device, &acpi_backlight_ops);
> +		if (IS_ERR(device->backlight))
> +			return;

we should kfree(name) here.

>  		device->backlight->props.max_brightness = device->brightness->count-3;
>  		kfree(name);

how about this one?

backlight_device_register may return an ERR_PTR value rather than a valid
pointer.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/acpi/video.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Index: linux-2.6/drivers/acpi/video.c
===================================================================
--- linux-2.6.orig/drivers/acpi/video.c
+++ linux-2.6/drivers/acpi/video.c
@@ -982,8 +982,10 @@ static void acpi_video_device_find_cap(s
 		sprintf(name, "acpi_video%d", count++);
 		device->backlight = backlight_device_register(name,
 			NULL, device, &acpi_backlight_ops);
-		device->backlight->props.max_brightness = device->brightness->count-3;
 		kfree(name);
+		if (IS_ERR(device->backlight))
+			return;
+		device->backlight->props.max_brightness = device->brightness->count-3;
 
 		result = sysfs_create_link(&device->backlight->dev.kobj,
 					   &device->dev->dev.kobj, "device");



 

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 9/9] drivers/acpi: correct error-handling code
  2009-07-29  0:53 ` Zhang Rui
@ 2009-07-29  2:20   ` Julia Lawall
  2009-12-30  6:51   ` Len Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2009-07-29  2:20 UTC (permalink / raw)
  To: Zhang Rui
  Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2163 bytes --]

On Wed, 29 Jul 2009, Zhang Rui wrote:

> On Tue, 2009-07-28 at 23:56 +0800, Julia Lawall wrote:
> > From: Julia Lawall <julia@diku.dk>
> > 
> > backlight_device_register may return an ERR_PTR value rather than a valid
> > pointer.
> > 
> > A simplified version of the semantic match that finds this problem is as
> > follows: (http://coccinelle.lip6.fr/)
> 
> > Signed-off-by: Julia Lawall <julia@diku.dk>
> > 
> > ---
> >  drivers/acpi/video.c                |    2 ++
> >  1 files changed, 2 insertions(+), 0 deletions(-)
> > 
> > diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
> > index 8851315..29788db 100644
> > --- a/drivers/acpi/video.c
> > +++ b/drivers/acpi/video.c
> > @@ -982,6 +982,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
> >  		sprintf(name, "acpi_video%d", count++);
> >  		device->backlight = backlight_device_register(name,
> >  			NULL, device, &acpi_backlight_ops);
> > +		if (IS_ERR(device->backlight))
> > +			return;
> 
> we should kfree(name) here.

Yes, good point.

thanks,
julia

> >  		device->backlight->props.max_brightness = device->brightness->count-3;
> >  		kfree(name);
> 
> how about this one?
> 
> ÿÿbacklight_device_register may return an ERR_PTR value rather than a valid
> pointer.
> 
> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
> ---
>  drivers/acpi/video.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> Index: linux-2.6/drivers/acpi/video.c
> ===================================================================
> --- linux-2.6.orig/drivers/acpi/video.c
> +++ linux-2.6/drivers/acpi/video.c
> @@ -982,8 +982,10 @@ static void acpi_video_device_find_cap(s
>  		sprintf(name, "acpi_video%d", count++);
>  		device->backlight = backlight_device_register(name,
>  			NULL, device, &acpi_backlight_ops);
> -		device->backlight->props.max_brightness = device->brightness->count-3;
>  		kfree(name);
> +		if (IS_ERR(device->backlight))
> +			return;
> +		device->backlight->props.max_brightness = device->brightness->count-3;
>  
>  		result = sysfs_create_link(&device->backlight->dev.kobj,
>  					   &device->dev->dev.kobj, "device");
> 
> 
> 
>  
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 9/9] drivers/acpi: correct error-handling code
  2009-07-29  0:53 ` Zhang Rui
  2009-07-29  2:20   ` Julia Lawall
@ 2009-12-30  6:51   ` Len Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Len Brown @ 2009-12-30  6:51 UTC (permalink / raw)
  To: Zhang Rui
  Cc: Julia Lawall, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2400 bytes --]

applied

thanks,
Len Brown, Intel Open Source Technology Center

On Wed, 29 Jul 2009, Zhang Rui wrote:

> On Tue, 2009-07-28 at 23:56 +0800, Julia Lawall wrote:
> > From: Julia Lawall <julia@diku.dk>
> > 
> > backlight_device_register may return an ERR_PTR value rather than a valid
> > pointer.
> > 
> > A simplified version of the semantic match that finds this problem is as
> > follows: (http://coccinelle.lip6.fr/)
> 
> > Signed-off-by: Julia Lawall <julia@diku.dk>
> > 
> > ---
> >  drivers/acpi/video.c                |    2 ++
> >  1 files changed, 2 insertions(+), 0 deletions(-)
> > 
> > diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
> > index 8851315..29788db 100644
> > --- a/drivers/acpi/video.c
> > +++ b/drivers/acpi/video.c
> > @@ -982,6 +982,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
> >  		sprintf(name, "acpi_video%d", count++);
> >  		device->backlight = backlight_device_register(name,
> >  			NULL, device, &acpi_backlight_ops);
> > +		if (IS_ERR(device->backlight))
> > +			return;
> 
> we should kfree(name) here.
> 
> >  		device->backlight->props.max_brightness = device->brightness->count-3;
> >  		kfree(name);
> 
> how about this one?
> 
> backlight_device_register may return an ERR_PTR value rather than a valid
> pointer.
> 
> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
> ---
>  drivers/acpi/video.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> Index: linux-2.6/drivers/acpi/video.c
> ===================================================================
> --- linux-2.6.orig/drivers/acpi/video.c
> +++ linux-2.6/drivers/acpi/video.c
> @@ -982,8 +982,10 @@ static void acpi_video_device_find_cap(s
>  		sprintf(name, "acpi_video%d", count++);
>  		device->backlight = backlight_device_register(name,
>  			NULL, device, &acpi_backlight_ops);
> -		device->backlight->props.max_brightness = device->brightness->count-3;
>  		kfree(name);
> +		if (IS_ERR(device->backlight))
> +			return;
> +		device->backlight->props.max_brightness = device->brightness->count-3;
>  
>  		result = sysfs_create_link(&device->backlight->dev.kobj,
>  					   &device->dev->dev.kobj, "device");
> 
> 
> 
>  
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-12-30  6:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-28 15:56 [PATCH 9/9] drivers/acpi: correct error-handling code Julia Lawall
2009-07-29  0:53 ` Zhang Rui
2009-07-29  2:20   ` Julia Lawall
2009-12-30  6:51   ` Len Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox