Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753029AbbGBHRi (ORCPT ); Thu, 2 Jul 2015 03:17:38 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:56051 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753195AbbGBHRH (ORCPT ); Thu, 2 Jul 2015 03:17:07 -0400 X-AuditID: cbfee691-f79ca6d00000456a-76-5594e5717e98 From: Maninder Singh To: lgirdwood@gmail.com, broonie@kernel.org, patches@opensource.wolfsonmicro.com, linux-kernel@vger.kernel.org Cc: pankaj.m@samsung.com, Maninder Singh Subject: [PATCH 1/1] regulator: wm831x-dcdc: Use pointer after NULL check Date: Thu, 02 Jul 2015 12:46:11 +0530 Message-id: <1435821371-25536-1-git-send-email-maninder1.s@samsung.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNLMWRmVeSWpSXmKPExsWyRsSkSrfw6ZRQg9YTYhZTHz5hs/h2pYPJ 4vKuOWwWh+e3sVjce7OVyWL52/9sDmweO2fdZffYtKqTzePlxN9sHn1bVjF6fN4kF8AaxWWT kpqTWZZapG+XwJWx9OEq1oI7XBWrVp5kamB8ydHFyMkhIWAisevrPXYIW0ziwr31bCC2kMBS RomT8xRhapq3TAWq4QKKT2eUmLb8GyOE85NRYtaCr2AdbAJ6Eqt27WEBsUUECiR+b53G3MXI wcEs4CQx/aseSFhYwFNi8bJ2RhCbRUBV4uqSN2A2r4C7RP+hxUwg5RICChJzJtlA7P3NJrF+ pRNEuYDEt8mHWCBKZCU2HWCGKJGUOLjiBssERsEFjAyrGEVTC5ILipPSi0z1ihNzi0vz0vWS 83M3MQLD9PS/ZxN3MN4/YH2IUYCDUYmHd0XNlFAh1sSy4srcQ4ymQBsmMkuJJucDoyGvJN7Q 2MzIwtTE1NjI3NJMSZxXR/pnsJBAemJJanZqakFqUXxRaU5q8SFGJg5OqQbGzdcuO3LZRnGX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@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1575 Lines: 47 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 --- 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/