]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pinctrl: devicetree: do not goto err when probing hogs in pinctrl_dt_to_map
authorValentin Caron <valentin.caron@foss.st.com>
Thu, 16 Jan 2025 17:00:09 +0000 (18:00 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Sun, 16 Feb 2025 23:16:01 +0000 (00:16 +0100)
Cross case in pinctrl framework make impossible to an hogged pin and
another, not hogged, used within the same device-tree node. For example
with this simplified device-tree :

  &pinctrl {
    pinctrl_pin_1: pinctrl-pin-1 {
      pins = "dummy-pinctrl-pin";
    };
  };

  &rtc {
    pinctrl-names = "default"
    pinctrl-0 = <&pinctrl_pin_1 &rtc_pin_1>

    rtc_pin_1: rtc-pin-1 {
      pins = "dummy-rtc-pin";
    };
  };

"pinctrl_pin_1" configuration is never set. This produces this path in
the code:

  really_probe()
    pinctrl_bind_pins()
    | devm_pinctrl_get()
    |   pinctrl_get()
    |     create_pinctrl()
    |       pinctrl_dt_to_map()
    |         // Hog pin create an abort for all pins of the node
    |         ret = dt_to_map_one_config()
    |         | /* Do not defer probing of hogs (circular loop) */
    |         | if (np_pctldev == p->dev->of_node)
    |         |   return -ENODEV;
    |         if (ret)
    |           goto err
    |
    call_driver_probe()
      stm32_rtc_probe()
        pinctrl_enable()
          pinctrl_claim_hogs()
            create_pinctrl()
              for_each_maps(maps_node, i, map)
                // Not hog pin is skipped
                if (pctldev && strcmp(dev_name(pctldev->dev),
                                      map->ctrl_dev_name))
                  continue;

At the first call of create_pinctrl() the hogged pin produces an abort to
avoid a defer of hogged pins. All other pin configurations are trashed.

At the second call, create_pinctrl is now called with pctldev parameter to
get hogs, but in this context only hogs are set. And other pins are
skipped.

To handle this, do not produce an abort in the first call of
create_pinctrl(). Classic pin configuration will be set in
pinctrl_bind_pins() context. And the hogged pin configuration will be set
in pinctrl_claim_hogs() context.

Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
Link: https://lore.kernel.org/20250116170009.2075544-1-valentin.caron@foss.st.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/devicetree.c

index 6a94ecd6a8deaeb6b7fc14c6387987f52ead306a..0b7f74beb6a6a8377893b3c5ea781c52e9ed242b 100644 (file)
@@ -143,10 +143,14 @@ static int dt_to_map_one_config(struct pinctrl *p,
                pctldev = get_pinctrl_dev_from_of_node(np_pctldev);
                if (pctldev)
                        break;
-               /* Do not defer probing of hogs (circular loop) */
+               /*
+                * Do not defer probing of hogs (circular loop)
+                *
+                * Return 1 to let the caller catch the case.
+                */
                if (np_pctldev == p->dev->of_node) {
                        of_node_put(np_pctldev);
-                       return -ENODEV;
+                       return 1;
                }
        }
        of_node_put(np_pctldev);
@@ -265,6 +269,8 @@ int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev)
                        ret = dt_to_map_one_config(p, pctldev, statename,
                                                   np_config);
                        of_node_put(np_config);
+                       if (ret == 1)
+                               continue;
                        if (ret < 0)
                                goto err;
                }