linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: Fix __of_device_is_available check
@ 2014-01-13  3:07 Xiubo Li
  2014-01-16 17:30 ` Grant Likely
  0 siblings, 1 reply; 2+ messages in thread
From: Xiubo Li @ 2014-01-13  3:07 UTC (permalink / raw)
  To: grant.likely, robh+dt; +Cc: devicetree, linux-kernel, Xiubo Li

>From IEEE 1275, there defined a standard 'status' property indicating the
operational status of one device. The 'status' property has four possible
values: 'okay/ok', 'disabled', 'fail' and 'fail-xxx'.

If it is absent, that means the status of the device is unknown or okay.

The __of_device_is_available checks the state of the 'status' property of
a device. If the property is absent or set to 'okay/ok', it returns 1.
Otherwise it returns 0.

While in __of_device_is_available:
 >	status = of_get_property(device, "status", &statlen);
 >	if (status == NULL)
 >		return 1;
The status value returned from 'of_get_property()' will be NULL in two cases:
Firstly: the 'device' value (device node) is NULL.
Secondly: the 'status' property is actaully not exist.

If the device node is NULL, the __of_device_is_available will return true,
that will mean the absent state of the 'status' property.

So this add the device node check before checking the 'status' property's
state, and if the device node is not exist, 0 will be returned.

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
---
 drivers/of/base.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index f807d0e..ba195fb 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -415,6 +415,9 @@ static int __of_device_is_available(const struct device_node *device)
 	const char *status;
 	int statlen;
 
+	if (!device)
+		return 0;
+
 	status = __of_get_property(device, "status", &statlen);
 	if (status == NULL)
 		return 1;
-- 
1.8.4



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

* Re: [PATCH] of: Fix __of_device_is_available check
  2014-01-13  3:07 [PATCH] of: Fix __of_device_is_available check Xiubo Li
@ 2014-01-16 17:30 ` Grant Likely
  0 siblings, 0 replies; 2+ messages in thread
From: Grant Likely @ 2014-01-16 17:30 UTC (permalink / raw)
  To: Xiubo Li, robh+dt; +Cc: devicetree, linux-kernel, Xiubo Li

On Mon, 13 Jan 2014 11:07:28 +0800, Xiubo Li <Li.Xiubo@freescale.com> wrote:
> From IEEE 1275, there defined a standard 'status' property indicating the
> operational status of one device. The 'status' property has four possible
> values: 'okay/ok', 'disabled', 'fail' and 'fail-xxx'.
> 
> If it is absent, that means the status of the device is unknown or okay.
> 
> The __of_device_is_available checks the state of the 'status' property of
> a device. If the property is absent or set to 'okay/ok', it returns 1.
> Otherwise it returns 0.
> 
> While in __of_device_is_available:
>  >	status = of_get_property(device, "status", &statlen);
>  >	if (status == NULL)
>  >		return 1;
> The status value returned from 'of_get_property()' will be NULL in two cases:
> Firstly: the 'device' value (device node) is NULL.
> Secondly: the 'status' property is actaully not exist.
> 
> If the device node is NULL, the __of_device_is_available will return true,
> that will mean the absent state of the 'status' property.
> 
> So this add the device node check before checking the 'status' property's
> state, and if the device node is not exist, 0 will be returned.
> 
> Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>

Applied, thanks

g.

> ---
>  drivers/of/base.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index f807d0e..ba195fb 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -415,6 +415,9 @@ static int __of_device_is_available(const struct device_node *device)
>  	const char *status;
>  	int statlen;
>  
> +	if (!device)
> +		return 0;
> +
>  	status = __of_get_property(device, "status", &statlen);
>  	if (status == NULL)
>  		return 1;
> -- 
> 1.8.4
> 
> 


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

end of thread, other threads:[~2014-01-16 17:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-13  3:07 [PATCH] of: Fix __of_device_is_available check Xiubo Li
2014-01-16 17:30 ` Grant Likely

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).