Skip to contentSkip to conversation

drivers/video: Bad error test before a dereference

PATCH In review Julien Brunel 2 participants 3 messages Sep 26, 2008 – Nov 13, 2008

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

PATCH 1/1 drivers/video: Bad error test before a dereference

The error test that follows the call to backlight_device_register semms not to concern the right variable.

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;
identifier fld;
position def0.p0;
position p != protected.p;
@@
x@p0
... when != x = E
* x@p->fld
// </smpl>

---
 drivers/video/atmel_lcdfb.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/atmel_lcdfb.c +1 -1
diff -u -p a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
@@ -132,7 +132,7 @@ static void init_backlight(struct atmel_
 
 	bl = backlight_device_register("backlight", &sinfo->pdev->dev,
 			sinfo, &atmel_lcdc_bl_ops);
-	if (IS_ERR(sinfo->backlight)) {
+	if (IS_ERR(bl)) {
 		dev_err(&sinfo->pdev->dev, "error %ld on backlight register\n",
 				PTR_ERR(bl));
 		return;
Acked-by on v1 1/1
#1 lore raw

Julien Brunel :

Quoted 34 lines

The error test that follows the call to backlight_device_register semms not to concern the right variable.

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;
identifier fld;
position def0.p0;
position p != protected.p;
@@
x@p0
... when != x = E
* x@p->fld
// </smpl>

Quoted 2 lines
Quoted 10 lines
---
 drivers/video/atmel_lcdfb.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

drivers/video/atmel_lcdfb.c static void init_backlight(struct atmel_ · line 138

Quoted 8 lines
drivers/video/atmel_lcdfb.c +1 -1
@@ -132,7 +132,7 @@ static void init_backlight(struct atmel_
 
 	bl = backlight_device_register("backlight", &sinfo->pdev->dev,
 			sinfo, &atmel_lcdc_bl_ops);
-	if (IS_ERR(sinfo->backlight)) {
+	if (IS_ERR(bl)) {
 		dev_err(&sinfo->pdev->dev, "error %ld on backlight register\n",
 				PTR_ERR(bl));
 		return;

Thanks, regards,

Signature · 1 line
Nicolas Ferre
#2 lore raw

Hi Andrew,

Nicolas Ferre :

Quoted 35 lines

Julien Brunel :

Quoted 34 lines

The error test that follows the call to backlight_device_register semms not to concern the right variable.

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;
identifier fld;
position def0.p0;
position p != protected.p;
@@
x@p0
... when != x = E
* x@p->fld
// </smpl>

Quoted 4 lines
Quoted 2 lines

I do not know if you noticed this little patch but I think it will be good if we can queue it for -final.

Do you want me to reformulate the submission or the original email ok for you ?

Quoted 9 lines
Quoted 9 lines
---
 drivers/video/atmel_lcdfb.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

drivers/video/atmel_lcdfb.c +0 -0
@@ -132,7 +132,7 @@ static void init_backlight(struct atmel_
 
Quoted 7 lines

drivers/video/atmel_lcdfb.c static void init_backlight(struct atmel_ · line 138

Quoted 7 lines
drivers/video/atmel_lcdfb.c +1 -1
 	bl = backlight_device_register("backlight", &sinfo->pdev->dev,
 			sinfo, &atmel_lcdc_bl_ops);
-	if (IS_ERR(sinfo->backlight)) {
+	if (IS_ERR(bl)) {
 		dev_err(&sinfo->pdev->dev, "error %ld on backlight register\n",
 				PTR_ERR(bl));
 		return;

Thanks, regards,

Signature · 1 line
Nicolas Ferre