linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: Don't create a pinctrl handle if no pinctrl entries exist
@ 2016-06-16 12:39 Jon Hunter
  2016-06-16 15:20 ` Jon Hunter
  0 siblings, 1 reply; 2+ messages in thread
From: Jon Hunter @ 2016-06-16 12:39 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Jon Hunter

When pinctrl_get() is called for a device, it will return a valid handle
even if the device itself has no pinctrl state entries defined in
device-tree. This is caused by the function pinctrl_dt_to_map() which
will return success even if the first pinctrl state, 'pinctrl-0', is not
found in the device-tree node for a device.

According to the pinctrl device-tree binding documentation, pinctrl
states must be numbered starting from 0 and so 'pinctrl-0' should always
be present if a device uses pinctrl and therefore, if 'pinctrl-0' is not
present it seems valid that we should not return a valid pinctrl handle.

Fix this by returning an error code if the property 'pinctrl-0' is not
present for a device.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
---

I was wondering if this meant we are creating pinctrl handles for
devices on boot that don't use pinctrl (when
calling pinctrl_bind_pins()). However, although devm_pinctrl_get()
does return successful for all devices, the subsequent call to
pinctrl_lookup_state() (to get the default state) will fail and so
we will destroy the pinctrl handle afterall.

 drivers/pinctrl/devicetree.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index fe04e748dfe4..f41c16e11a11 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -195,8 +195,11 @@ int pinctrl_dt_to_map(struct pinctrl *p)
 		propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state);
 		prop = of_find_property(np, propname, &size);
 		kfree(propname);
-		if (!prop)
+		if (!prop) {
+			if (state == 0)
+				return -ENODEV;
 			break;
+		}
 		list = prop->value;
 		size /= sizeof(*list);
 
-- 
2.1.4

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

* Re: [PATCH] pinctrl: Don't create a pinctrl handle if no pinctrl entries exist
  2016-06-16 12:39 [PATCH] pinctrl: Don't create a pinctrl handle if no pinctrl entries exist Jon Hunter
@ 2016-06-16 15:20 ` Jon Hunter
  0 siblings, 0 replies; 2+ messages in thread
From: Jon Hunter @ 2016-06-16 15:20 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel


On 16/06/16 13:39, Jon Hunter wrote:
> When pinctrl_get() is called for a device, it will return a valid handle
> even if the device itself has no pinctrl state entries defined in
> device-tree. This is caused by the function pinctrl_dt_to_map() which
> will return success even if the first pinctrl state, 'pinctrl-0', is not
> found in the device-tree node for a device.
> 
> According to the pinctrl device-tree binding documentation, pinctrl
> states must be numbered starting from 0 and so 'pinctrl-0' should always
> be present if a device uses pinctrl and therefore, if 'pinctrl-0' is not
> present it seems valid that we should not return a valid pinctrl handle.
> 
> Fix this by returning an error code if the property 'pinctrl-0' is not
> present for a device.
> 
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> ---
> 
> I was wondering if this meant we are creating pinctrl handles for
> devices on boot that don't use pinctrl (when
> calling pinctrl_bind_pins()). However, although devm_pinctrl_get()
> does return successful for all devices, the subsequent call to
> pinctrl_lookup_state() (to get the default state) will fail and so
> we will destroy the pinctrl handle afterall.
>
>  drivers/pinctrl/devicetree.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
> index fe04e748dfe4..f41c16e11a11 100644
> --- a/drivers/pinctrl/devicetree.c
> +++ b/drivers/pinctrl/devicetree.c
> @@ -195,8 +195,11 @@ int pinctrl_dt_to_map(struct pinctrl *p)
>  		propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state);
>  		prop = of_find_property(np, propname, &size);
>  		kfree(propname);
> -		if (!prop)
> +		if (!prop) {
> +			if (state == 0)

I think there should be a of_node_put() here. Will resend.

> +				return -ENODEV;
>  			break;
> +		}

Cheers
Jon

-- 
nvpublic

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

end of thread, other threads:[~2016-06-16 15:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-16 12:39 [PATCH] pinctrl: Don't create a pinctrl handle if no pinctrl entries exist Jon Hunter
2016-06-16 15:20 ` Jon Hunter

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