[PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check

From: Maninder Singh
Date: Thu Jul 02 2015 - 03:58:10 EST


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 than (pointer == NULL)

Signed-off-by: Maninder Singh <maninder1.s@xxxxxxxxxxx>
---
v2: indentation fixes

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

--
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/