All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] regulator/wm831x-dcdc: fix potential NULL dereference
@ 2010-08-20  1:58 Axel Lin
  2010-08-20  1:59 ` [PATCH 2/4] regulator/wm831x-isink: " Axel Lin
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Axel Lin @ 2010-08-20  1:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: Mark Brown, Liam Girdwood

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@gmail.com>
---
 drivers/regulator/wm831x-dcdc.c |   36 ++++++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index dbfaf59..ed66fac 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -501,14 +501,17 @@ static __devinit int wm831x_buckv_probe(struct platform_device *pdev)
 {
 	struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
 	struct wm831x_pdata *pdata = wm831x->dev->platform_data;
-	int id = pdev->id % ARRAY_SIZE(pdata->dcdc);
 	struct wm831x_dcdc *dcdc;
 	struct resource *res;
-	int ret, irq;
+	int id, ret, irq;
 
+	if (pdata == NULL)
+		return -ENODEV;
+
+	id = pdev->id % ARRAY_SIZE(pdata->dcdc);
 	dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
 
-	if (pdata == NULL || pdata->dcdc[id] == NULL)
+	if (pdata->dcdc[id] == NULL)
 		return -ENODEV;
 
 	dcdc = kzalloc(sizeof(struct wm831x_dcdc), GFP_KERNEL);
@@ -704,14 +707,17 @@ static __devinit int wm831x_buckp_probe(struct platform_device *pdev)
 {
 	struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
 	struct wm831x_pdata *pdata = wm831x->dev->platform_data;
-	int id = pdev->id % ARRAY_SIZE(pdata->dcdc);
 	struct wm831x_dcdc *dcdc;
 	struct resource *res;
-	int ret, irq;
+	int id, ret, irq;
 
+	if (pdata == NULL)
+		return -ENODEV;
+
+	id = pdev->id % ARRAY_SIZE(pdata->dcdc);
 	dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
 
-	if (pdata == NULL || pdata->dcdc[id] == NULL)
+	if (pdata->dcdc[id] == NULL)
 		return -ENODEV;
 
 	dcdc = kzalloc(sizeof(struct wm831x_dcdc), GFP_KERNEL);
@@ -834,14 +840,17 @@ static __devinit int wm831x_boostp_probe(struct platform_device *pdev)
 {
 	struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
 	struct wm831x_pdata *pdata = wm831x->dev->platform_data;
-	int id = pdev->id % ARRAY_SIZE(pdata->dcdc);
 	struct wm831x_dcdc *dcdc;
 	struct resource *res;
-	int ret, irq;
+	int id, ret, irq;
 
+	if (pdata == NULL)
+		return -ENODEV;
+
+	id = pdev->id % ARRAY_SIZE(pdata->dcdc);
 	dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
 
-	if (pdata == NULL || pdata->dcdc[id] == NULL)
+	if (pdata->dcdc[id] == NULL)
 		return -ENODEV;
 
 	dcdc = kzalloc(sizeof(struct wm831x_dcdc), GFP_KERNEL);
@@ -940,13 +949,16 @@ static __devinit int wm831x_epe_probe(struct platform_device *pdev)
 {
 	struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
 	struct wm831x_pdata *pdata = wm831x->dev->platform_data;
-	int id = pdev->id % ARRAY_SIZE(pdata->epe);
 	struct wm831x_dcdc *dcdc;
-	int ret;
+	int id, ret;
+
+	if (pdata == NULL)
+		return -ENODEV;
 
+	id = pdev->id % ARRAY_SIZE(pdata->epe);
 	dev_dbg(&pdev->dev, "Probing EPE%d\n", id + 1);
 
-	if (pdata == NULL || pdata->epe[id] == NULL)
+	if (pdata->epe[id] == NULL)
 		return -ENODEV;
 
 	dcdc = kzalloc(sizeof(struct wm831x_dcdc), GFP_KERNEL);
-- 
1.7.2




^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-08-20 15:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-20  1:58 [PATCH 1/4] regulator/wm831x-dcdc: fix potential NULL dereference Axel Lin
2010-08-20  1:59 ` [PATCH 2/4] regulator/wm831x-isink: " Axel Lin
2010-08-20  2:01 ` [PATCH 3/4] regulator/wm831x-ldo: " Axel Lin
2010-08-20  2:02 ` [PATCH 4/4] regulator/wm8994-regulator: " Axel Lin
2010-08-20  9:03 ` [PATCH 1/4] regulator/wm831x-dcdc: " Mark Brown
2010-08-20 15:43   ` Axel Lin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.