Skip to contentSkip to conversation

pinctrl: Don't create a pinctrl handle if no pinctrl entries exist

PATCH In review Jon Hunter 2 participants 2 messages Jun 16, 2016 – Jun 18, 2016

Subsystems (2)
lore
Share & tools
lore

Jon Hunter

author
#0 lore raw

PATCH v2 1/1 pinctrl: Don't create a pinctrl handle if no pinctrl entries exist

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.

---

Changes since V1:
- Added of_node_put()

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 | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/pinctrl/devicetree.c +6 -1
index fe04e748dfe4..54dad89fc9bf 100644
@@ -195,8 +195,13 @@ 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) {
+				of_node_put(np);
+				return -ENODEV;
+			}
 			break;
+		}
 		list = prop->value;
 		size /= sizeof(*list);
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 11 lines · 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.

Quoted 4 lines

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

Patch applied (after adding OF to the subject)

It's a bit dangerous because it changes semantics but let's see if we survive it.

Quoted 6 lines

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.

It's better like this, logically. I'm just worried that there may be code in the tree that depend on the bind always getting a handle.

Yours,
Linus Walleij