[PATCH 4/4] regulator/wm8994-regulator: fix potential NULLdereference

From: Axel Lin
Date: Thu Aug 19 2010 - 22:00:00 EST


pdata is dereferenced earlier than tested for being NULL.
Thus move the dereference of "pdata" below the check for NULL.

Signed-off-by: Axel Lin <axel.lin@xxxxxxxxx>
---
drivers/regulator/wm8994-regulator.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index 03713bc..3ecc81f 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -202,15 +202,15 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
{
struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent);
struct wm8994_pdata *pdata = wm8994->dev->platform_data;
- int id = pdev->id % ARRAY_SIZE(pdata->ldo);
struct wm8994_ldo *ldo;
- int ret;
-
- dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
+ int id, ret;

if (!pdata)
return -ENODEV;

+ id = pdev->id % ARRAY_SIZE(pdata->ldo);
+ dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
+
ldo = kzalloc(sizeof(struct wm8994_ldo), GFP_KERNEL);
if (ldo == NULL) {
dev_err(&pdev->dev, "Unable to allocate private data\n");
--
1.7.2



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/