2015-07-02 07:17:38

by Maninder Singh

[permalink] [raw]
Subject: [PATCH 1/1] regulator: wm831x-dcdc: Use pointer after NULL check

pdata is used before NULL check, so it looks misleading.
If pdata validation is required then we have to
first check for pdata validation, then calculate id,
and then second check for pdata->dcdc[id].

and it is better to use !pointer then to use (pointer == NULL)

Signed-off-by: Maninder Singh <[email protected]>
---
drivers/regulator/wm831x-dcdc.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 8cbb82c..04ede43 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -738,15 +738,19 @@ static int wm831x_boostp_probe(struct platform_device *pdev)
struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
struct regulator_config config = { };
- int id = pdev->id % ARRAY_SIZE(pdata->dcdc);
+ int id;
struct wm831x_dcdc *dcdc;
struct resource *res;
int ret, irq;

+ if (!pdata)
+ 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)
- return -ENODEV;
+ if (!pdata->dcdc[id])
+ return -ENODEV;

dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL);
if (!dcdc)
--
1.7.9.5