* [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
* Re: [PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check
2015-07-02 7:57 Maninder Singh
@ 2015-07-02 10:18 ` Charles Keepax
2015-07-02 11:14 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: Charles Keepax @ 2015-07-02 10:18 UTC (permalink / raw)
To: Maninder Singh; +Cc: lgirdwood, broonie, patches, linux-kernel, pankaj.m
On Thu, Jul 02, 2015 at 01:27:09PM +0530, Maninder Singh wrote:
> 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.
Thanks,
Charles
^ permalink raw reply [flat|nested] 7+ messages in thread
* 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
* Re: [PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check
2015-07-02 11:02 [PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check Maninder Singh
@ 2015-07-02 11:12 ` Charles Keepax
0 siblings, 0 replies; 7+ messages in thread
From: Charles Keepax @ 2015-07-02 11:12 UTC (permalink / raw)
To: Maninder Singh
Cc: lgirdwood@gmail.com, broonie@kernel.org,
patches@opensource.wolfsonmicro.com, linux-kernel@vger.kernel.org,
PANKAJ MISHRA
On Thu, Jul 02, 2015 at 11:02:54AM +0000, Maninder Singh wrote:
> 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.
You can't drop the NULL check because then we might dereference a
NULL pointer. ARRAY_SIZE(pdata->dcdc) is perfectly save because
sizeof only works on types so no actual dereference takes place.
Thanks,
Charles
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check
2015-07-02 10:18 ` Charles Keepax
@ 2015-07-02 11:14 ` Mark Brown
2015-07-02 11:19 ` Charles Keepax
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2015-07-02 11:14 UTC (permalink / raw)
To: Charles Keepax; +Cc: Maninder Singh, lgirdwood, patches, linux-kernel, pankaj.m
[-- Attachment #1: Type: text/plain, Size: 464 bytes --]
On Thu, Jul 02, 2015 at 11:18:49AM +0100, Charles Keepax wrote:
> On Thu, Jul 02, 2015 at 01:27:09PM +0530, Maninder Singh wrote:
> > pdata is used before NULL check, so it looks misleading.
> 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.
It's a bug - either the validation shouldn't be there or it needs to be
before the use otherwise it does nothing.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check
2015-07-02 11:14 ` Mark Brown
@ 2015-07-02 11:19 ` Charles Keepax
2015-07-02 11:33 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: Charles Keepax @ 2015-07-02 11:19 UTC (permalink / raw)
To: Mark Brown; +Cc: Maninder Singh, lgirdwood, patches, linux-kernel, pankaj.m
On Thu, Jul 02, 2015 at 12:14:56PM +0100, Mark Brown wrote:
> On Thu, Jul 02, 2015 at 11:18:49AM +0100, Charles Keepax wrote:
> > On Thu, Jul 02, 2015 at 01:27:09PM +0530, Maninder Singh wrote:
> > > pdata is used before NULL check, so it looks misleading.
>
> > 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.
>
> It's a bug - either the validation shouldn't be there or it needs to be
> before the use otherwise it does nothing.
ARRAY_SIZE being implemented with sizeof's means that no actual
dereference takes place. But if we have multiple people thinking
this looks buggy then I guess the code probably isn't clear
enough at the moment.
Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Thanks,
Charles
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check
2015-07-02 11:19 ` Charles Keepax
@ 2015-07-02 11:33 ` Mark Brown
0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2015-07-02 11:33 UTC (permalink / raw)
To: Charles Keepax; +Cc: Maninder Singh, lgirdwood, patches, linux-kernel, pankaj.m
[-- Attachment #1: Type: text/plain, Size: 582 bytes --]
On Thu, Jul 02, 2015 at 12:19:50PM +0100, Charles Keepax wrote:
> On Thu, Jul 02, 2015 at 12:14:56PM +0100, Mark Brown wrote:
> > It's a bug - either the validation shouldn't be there or it needs to be
> > before the use otherwise it does nothing.
> ARRAY_SIZE being implemented with sizeof's means that no actual
> dereference takes place. But if we have multiple people thinking
> this looks buggy then I guess the code probably isn't clear
> enough at the moment.
Ah, I see. I'd not actually looked at the patch yet only the changelog
quoted in the discussion.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [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).