Skip to contentSkip to conversation

fix checking in probe function

PATCH In review Christoph Fritz 2 participants 2 messages Apr 10, 2010 – Apr 13, 2010

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

PATCH 1/1 fix checking in probe function

Improve device and platform data checks in probe function.

---
 drivers/leds/leds-88pm860x.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/leds/leds-88pm860x.c +8 -3
index 16a60c0..b767710 100644
@@ -256,8 +256,10 @@ static int pm860x_led_probe(struct platform_device *pdev)
 	if (pdev->dev.parent->platform_data) {
 		pm860x_pdata = pdev->dev.parent->platform_data;
 		pdata = pm860x_pdata->led;
-	} else
-		pdata = NULL;
+	} else {
+		dev_err(&pdev->dev, "missing platform data\n");
+		return -EINVAL;
+	}
 
 	data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL);
 	if (data = NULL)
@@ -268,8 +270,11 @@ static int pm860x_led_probe(struct platform_device *pdev)
 	data->i2c = (chip->id = CHIP_PM8606) ? chip->client : chip->companion;
 	data->iset = pdata->iset;
 	data->port = __check_device(pdata, data->name);
-	if (data->port < 0)
+	if (data->port < 0) {
+		dev_err(&pdev->dev, "check device failed\n");
+		kfree(data);
 		return -EINVAL;
+	}
 
 	data->current_brightness = 0;
 	data->cdev.name = data->name;
Signature · 1 line
1.5.6.5
#1 lore raw

Yes, kfree() should be used as you mentioned.

I'm OK on your patch.

Thanks
Haojian

-----Original Message-----
From: Christoph Fritz [mailto:[email protected]]
Sent: 2010Äê4ÔÂ10ÈÕ 8:41 PM
To: Haojian Zhuang
Cc: Dan Carpenter; Richard Purdie; [email protected]
Subject: [PATCH] fix checking in probe function

Improve device and platform data checks in probe function.

---
 drivers/leds/leds-88pm860x.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/leds/leds-88pm860x.c +8 -3
index 16a60c0..b767710 100644
@@ -256,8 +256,10 @@ static int pm860x_led_probe(struct platform_device *pdev)
 	if (pdev->dev.parent->platform_data) {
 		pm860x_pdata = pdev->dev.parent->platform_data;
 		pdata = pm860x_pdata->led;
-	} else
-		pdata = NULL;
+	} else {
+		dev_err(&pdev->dev, "missing platform data\n");
+		return -EINVAL;
+	}
 
 	data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL);
 	if (data = NULL)
@@ -268,8 +270,11 @@ static int pm860x_led_probe(struct platform_device *pdev)
 	data->i2c = (chip->id = CHIP_PM8606) ? chip->client : chip->companion;
 	data->iset = pdata->iset;
 	data->port = __check_device(pdata, data->name);
-	if (data->port < 0)
+	if (data->port < 0) {
+		dev_err(&pdev->dev, "check device failed\n");
+		kfree(data);
 		return -EINVAL;
+	}
 
 	data->current_brightness = 0;
 	data->cdev.name = data->name;
Signature · 4 lines
1.5.6.5


ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ¥Šwÿº{.nÇ+‰·¤z¹Ş—øÚ�+h®Ïâ�Ø^n‡r¡ö¦zË�ëh™¨è­Ú&£ûàz¿äz¹Ş—ú+€Ê+zf£¢·hšˆ§~†­†Ûiÿÿï�êÿ‘êçz_è®æj:+v‰¨ş)ߣøm