Skip to contentSkip to conversation

input/tps6507x-ts: dereferencing before checking

PATCH In review Dan Carpenter 2 participants 3 messages May 31, 2010

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

PATCH 1/2 input/tps6507x-ts: dereferencing before checking

This patch moves the dereference after the check for NULL.

drivers/input/touchscreen/tps6507x-ts.c +2 -1
index 5de80a1..b99db09 100644
@@ -355,10 +355,11 @@ static int __devexit tps6507x_ts_remove(struct platform_device *pdev)
 {
 	struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
 	struct tps6507x_ts *tsc = tps6507x_dev->ts;
-	struct input_dev *input_dev = tsc->input_dev;
+	struct input_dev *input_dev;
 
 	if (!tsc)
 		return 0;
+	input_dev = tsc->input_dev;
 
 	cancel_delayed_work(&tsc->work);
 	flush_workqueue(tsc->wq);
maintainer
#1 lore raw
Quoted 9 lines · Dan Carpenter

This patch moves the dereference after the check for NULL.

drivers/input/touchscreen/tps6507x-ts.c +0 -0
index 5de80a1..b99db09 100644

drivers/input/touchscreen/tps6507x-ts.c static int __devexit tps6507x_ts_remove(struct platform_device *pdev) · line 363

Quoted 10 lines
drivers/input/touchscreen/tps6507x-ts.c +2 -1
@@ -355,10 +355,11 @@ static int __devexit tps6507x_ts_remove(struct platform_device *pdev)
 {
 	struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
 	struct tps6507x_ts *tsc = tps6507x_dev->ts;
-	struct input_dev *input_dev = tsc->input_dev;
+	struct input_dev *input_dev;
 
 	if (!tsc)
 		return 0;
+	input_dev = tsc->input_dev;
 

Why would tsc ever be NULL?

Also I really do not like that pdev's driver data that is supposed to be driver-private data is being used by the parent. Parent should be using it's own drvdata and leave child's data alone. We should probably do in platform code what I2C is about to do and clear drvdata on unbind automatically to prevent this kind of misuse.

Signature · 1 line
Dmitry
#2 lore raw
Quoted 16 lines · Dmitry Torokhov

drivers/input/touchscreen/tps6507x-ts.c static int __devexit tps6507x_ts_remove(struct platform_device *pdev) · line 363

Quoted 13 lines
drivers/input/touchscreen/tps6507x-ts.c +2 -1
@@ -355,10 +355,11 @@ static int __devexit tps6507x_ts_remove(struct platform_device *pdev)
 {
 	struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
 	struct tps6507x_ts *tsc = tps6507x_dev->ts;
-	struct input_dev *input_dev = tsc->input_dev;
+	struct input_dev *input_dev;
 
 	if (!tsc)
 		return 0;
+	input_dev = tsc->input_dev;
 

Why would tsc ever be NULL?

Quoted 6 lines

Also I really do not like that pdev's driver data that is supposed to be driver-private data is being used by the parent. Parent should be using it's own drvdata and leave child's data alone. We should probably do in platform code what I2C is about to do and clear drvdata on unbind automatically to prevent this kind of misuse.

Uh... Sorry I was just messing with my static checker and didn't look into it deeply enough.

All your points are valid ones of course. This is fairly new driver so we might be able to ask the maintainer. :) Todd, do you want to help us out?

regards,
dan carpenter