* [PATCH 1/1] of: add NULL parameter check for of_device_is_available
@ 2012-03-13 11:40 Dong Aisheng
2012-03-13 12:46 ` Rob Herring
2012-03-13 20:34 ` David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Dong Aisheng @ 2012-03-13 11:40 UTC (permalink / raw)
To: devicetree-discuss, linux-kernel; +Cc: grant.likely, rob.herring
From: Dong Aisheng <dong.aisheng@linaro.org>
This function will return 1 even the device node passed in
is NULL which is a little error-prone.
Change to return 0 if the device node passed in is NULL.
Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org>
---
drivers/of/base.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 133908a..b9347d8 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -280,6 +280,9 @@ int of_device_is_available(const struct device_node *device)
const char *status;
int statlen;
+ if (device == NULL)
+ return 0;
+
status = of_get_property(device, "status", &statlen);
if (status == NULL)
return 1;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] of: add NULL parameter check for of_device_is_available
2012-03-13 11:40 [PATCH 1/1] of: add NULL parameter check for of_device_is_available Dong Aisheng
@ 2012-03-13 12:46 ` Rob Herring
2012-03-13 20:34 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: Rob Herring @ 2012-03-13 12:46 UTC (permalink / raw)
To: Dong Aisheng; +Cc: devicetree-discuss, linux-kernel, rob.herring
On 03/13/2012 06:40 AM, Dong Aisheng wrote:
> From: Dong Aisheng <dong.aisheng@linaro.org>
>
> This function will return 1 even the device node passed in
> is NULL which is a little error-prone.
> Change to return 0 if the device node passed in is NULL.
>
> Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org>
Applied.
Rob
> ---
> drivers/of/base.c | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 133908a..b9347d8 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -280,6 +280,9 @@ int of_device_is_available(const struct device_node *device)
> const char *status;
> int statlen;
>
> + if (device == NULL)
> + return 0;
> +
> status = of_get_property(device, "status", &statlen);
> if (status == NULL)
> return 1;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] of: add NULL parameter check for of_device_is_available
2012-03-13 11:40 [PATCH 1/1] of: add NULL parameter check for of_device_is_available Dong Aisheng
2012-03-13 12:46 ` Rob Herring
@ 2012-03-13 20:34 ` David Miller
2012-03-13 21:15 ` Rob Herring
1 sibling, 1 reply; 4+ messages in thread
From: David Miller @ 2012-03-13 20:34 UTC (permalink / raw)
To: b29396; +Cc: devicetree-discuss, linux-kernel, grant.likely, rob.herring
From: Dong Aisheng <b29396@freescale.com>
Date: Tue, 13 Mar 2012 19:40:05 +0800
> From: Dong Aisheng <dong.aisheng@linaro.org>
>
> This function will return 1 even the device node passed in
> is NULL which is a little error-prone.
> Change to return 0 if the device node passed in is NULL.
>
> Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org>
I think this is a hard error and therefore BUG_ON(!device) is
more appropriate.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] of: add NULL parameter check for of_device_is_available
2012-03-13 20:34 ` David Miller
@ 2012-03-13 21:15 ` Rob Herring
0 siblings, 0 replies; 4+ messages in thread
From: Rob Herring @ 2012-03-13 21:15 UTC (permalink / raw)
To: David Miller; +Cc: b29396, devicetree-discuss, linux-kernel
On 03/13/2012 03:34 PM, David Miller wrote:
> From: Dong Aisheng <b29396@freescale.com>
> Date: Tue, 13 Mar 2012 19:40:05 +0800
>
>> From: Dong Aisheng <dong.aisheng@linaro.org>
>>
>> This function will return 1 even the device node passed in
>> is NULL which is a little error-prone.
>> Change to return 0 if the device node passed in is NULL.
>>
>> Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org>
>
> I think this is a hard error and therefore BUG_ON(!device) is
> more appropriate.
Shouldn't removing a node from the dts and adding 'status = "disabled";'
to a node give the same behavior? Then you can do something like this:
if (of_device_is_available(of_find_compatible_node("blah")))
//foo
Rob
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-13 21:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-13 11:40 [PATCH 1/1] of: add NULL parameter check for of_device_is_available Dong Aisheng
2012-03-13 12:46 ` Rob Herring
2012-03-13 20:34 ` David Miller
2012-03-13 21:15 ` Rob Herring
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).