linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check
@ 2015-07-02 11:02 Maninder Singh
  2015-07-02 11:12 ` Charles Keepax
  0 siblings, 1 reply; 7+ messages in thread
From: Maninder Singh @ 2015-07-02 11:02 UTC (permalink / raw)
  To: Charles Keepax
  Cc: lgirdwood@gmail.com, broonie@kernel.org,
	patches@opensource.wolfsonmicro.com, linux-kernel@vger.kernel.org,
	PANKAJ MISHRA

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=windows-1252, Size: 914 bytes --]

Hello charles,
>> 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@samsung.com>
>> ---

>The patch basically looks fine, but it feels a bit like needless
>churn. The current code is perfectly correct and feels clear
>enough to me.

Reason for patch is we are checking a pointer which is already dereferenced 
before NULL check, which looks misleading.
If we know code is working correctly, Then we may simply drop NULL check,
rather than these changes. 

Thanks,
Maninder
........ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check
@ 2015-07-02  7:57 Maninder Singh
  2015-07-02 10:18 ` Charles Keepax
  0 siblings, 1 reply; 7+ messages in thread
From: Maninder Singh @ 2015-07-02  7:57 UTC (permalink / raw)
  To: lgirdwood, broonie, patches, linux-kernel; +Cc: pankaj.m, Maninder Singh

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@samsung.com>
---
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


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

end of thread, other threads:[~2015-07-02 11:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-02 11:02 [PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check Maninder Singh
2015-07-02 11:12 ` Charles Keepax
  -- strict thread matches above, loose matches on Subject: below --
2015-07-02  7:57 Maninder Singh
2015-07-02 10:18 ` Charles Keepax
2015-07-02 11:14   ` Mark Brown
2015-07-02 11:19     ` Charles Keepax
2015-07-02 11:33       ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).