* smatch: leds: potential null deref
@ 2010-04-07 9:18 Dan Carpenter
2010-04-07 9:44 ` Dan Carpenter
2010-04-09 10:14 ` Haojian Zhuang
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2010-04-07 9:18 UTC (permalink / raw)
To: kernel-janitors
Hello,
Smatch complains about a potential null dereference but I don't know how
to fix it. Could you take a look?
drivers/leds/leds-88pm860x.c +269 pm860x_led_probe(28)
error: potential null derefence 'pdata'.
256 if (pdev->dev.parent->platform_data) {
257 pm860x_pdata = pdev->dev.parent->platform_data;
258 pdata = pm860x_pdata->led;
259 } else
260 pdata = NULL;
^^^^^^^^^^^^^
We set pdata to NULL here.
261
262 data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL);
263 if (data = NULL)
264 return -ENOMEM;
265 strncpy(data->name, res->name, MFD_NAME_SIZE);
266 dev_set_drvdata(&pdev->dev, data);
267 data->chip = chip;
268 data->i2c = (chip->id = CHIP_PM8606) ? chip->client : chip->companion;
269 data->iset = pdata->iset;
^^^^^^^^^^^^
We dereference it here.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: smatch: leds: potential null deref
2010-04-07 9:18 smatch: leds: potential null deref Dan Carpenter
@ 2010-04-07 9:44 ` Dan Carpenter
2010-04-09 10:14 ` Haojian Zhuang
1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2010-04-07 9:44 UTC (permalink / raw)
To: kernel-janitors
On Wed, Apr 07, 2010 at 12:18:50PM +0300, Dan Carpenter wrote:
> Hello,
>
> Smatch complains about a potential null dereference but I don't know how
> to fix it. Could you take a look?
>
Sorry I should have mentioned that I'll be offline for probably a week.
So don't hurry on my account. :)
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: smatch: leds: potential null deref
2010-04-07 9:18 smatch: leds: potential null deref Dan Carpenter
2010-04-07 9:44 ` Dan Carpenter
@ 2010-04-09 10:14 ` Haojian Zhuang
1 sibling, 0 replies; 3+ messages in thread
From: Haojian Zhuang @ 2010-04-09 10:14 UTC (permalink / raw)
To: kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 1431 bytes --]
Hi,
Excuse me on late response. Now I fix it.
Richard,
Could you help to review & merge this patch?
Thanks
Haojian
-----Original Message-----
From: Dan Carpenter [mailto:error27@gmail.com]
Sent: 2010年4月7日 5:19 PM
To: Haojian Zhuang
Cc: Richard Purdie; kernel-janitors@vger.kernel.org
Subject: smatch: leds: potential null deref
Hello,
Smatch complains about a potential null dereference but I don't know how
to fix it. Could you take a look?
drivers/leds/leds-88pm860x.c +269 pm860x_led_probe(28)
error: potential null derefence 'pdata'.
256 if (pdev->dev.parent->platform_data) {
257 pm860x_pdata = pdev->dev.parent->platform_data;
258 pdata = pm860x_pdata->led;
259 } else
260 pdata = NULL;
^^^^^^^^^^^^^
We set pdata to NULL here.
261
262 data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL);
263 if (data == NULL)
264 return -ENOMEM;
265 strncpy(data->name, res->name, MFD_NAME_SIZE);
266 dev_set_drvdata(&pdev->dev, data);
267 data->chip = chip;
268 data->i2c = (chip->id == CHIP_PM8606) ? chip->client : chip->companion;
269 data->iset = pdata->iset;
^^^^^^^^^^^^
We dereference it here.
regards,
dan carpenter
[-- Attachment #2: 0001-led-fix-parameter-checking.patch --]
[-- Type: application/octet-stream, Size: 1045 bytes --]
From 7b115e66a0ee22bdb50125bb834757e5eb29cda7 Mon Sep 17 00:00:00 2001
From: Haojian Zhuang <haojian.zhuang@marvell.com>
Date: Fri, 9 Apr 2010 12:57:27 -0400
Subject: [PATCH] led: fix parameter checking
If platform data isn't assigned, no error detection on this. Now check it and
exit if it's not assigned.
Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
---
drivers/leds/leds-88pm860x.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c
index 16a60c0..46efc3a 100644
--- a/drivers/leds/leds-88pm860x.c
+++ b/drivers/leds/leds-88pm860x.c
@@ -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)
--
1.5.6.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-04-09 10:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-07 9:18 smatch: leds: potential null deref Dan Carpenter
2010-04-07 9:44 ` Dan Carpenter
2010-04-09 10:14 ` Haojian Zhuang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox