pinctrl: OF: Don't create a pinctrl handle if no pinctrl entries exist
authorJon Hunter <jonathanh@nvidia.com>
Thu, 16 Jun 2016 15:27:41 +0000 (16:27 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Sat, 18 Jun 2016 08:40:15 +0000 (10:40 +0200)
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>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/devicetree.c

index fe04e74..54dad89 100644 (file)
@@ -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);