Skip to contentSkip to conversation

drivers/acpi: dereference without an error test

PATCH Applied Julien Brunel 2 participants 2 messages Sep 26, 2008 – Oct 8, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/acpi: dereference without an error test

After a variable is assigned the result of backlight_device_register, an error test should be performed before a dereference.

A simplified version of the semantic match that finds this problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@def0@
expression x;
position p0;
@@

x@p0 = backlight_device_register(...)

@protected@
expression def0.x,E;
position def0.p0;
position p;
statement S;
@@
x@p0
... when != x = E
if (!IS_ERR(x) && ...) {<... x@p ...>} else S

@unprotected@
expression def0.x,E;
identifier fld;
position def0.p0;
position p != protected.p;
@@
x@p0
... when != x = E
* x@p->fld
// </smpl>

---
 drivers/acpi/video.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/video.c +2 -0
diff -u -p a/drivers/acpi/video.c b/drivers/acpi/video.c
@@ -752,6 +752,8 @@ 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);
+		if (IS_ERR(device->backlight))
+			return;
 		device->backlight->props.max_brightness = device->brightness->count-3;
 		/*
 		 * If there exists the _BQC object, the _BQC object will be
reviewer Applied
#1 lore raw

applied.

thanks,
-len

Quoted 59 lines · Julien Brunel

After a variable is assigned the result of backlight_device_register, an error test should be performed before a dereference.

A simplified version of the semantic match that finds this problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@def0@
expression x;
position p0;
@@

x@p0 = backlight_device_register(...)

@protected@
expression def0.x,E;
position def0.p0;
position p;
statement S;
@@
x@p0
... when != x = E
if (!IS_ERR(x) && ...) {<... x@p ...>} else S

@unprotected@
expression def0.x,E;
identifier fld;
position def0.p0;
position p != protected.p;
@@
x@p0
... when != x = E
* x@p->fld
// </smpl>

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

diff -u -p a/drivers/acpi/video.c b/drivers/acpi/video.c

drivers/acpi/video.c +2 -1
@@ -752,6 +752,8 @@ 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);
+		if (IS_ERR(device->backlight))
+			return;
 		device->backlight->props.max_brightness = device->brightness->count-3;
 		/*
 		 * If there exists the _BQC object, the _BQC object will be
--

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