pinctrl: single: Fix PIN_CONFIG_BIAS_DISABLE handling
authorMatthijs Kooijman <matthijs@stdin.nl>
Tue, 19 Mar 2024 11:06:34 +0000 (12:06 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Thu, 4 Apr 2024 19:03:25 +0000 (21:03 +0200)
The pinctrl-single driver handles pin_config_set by looking up the
requested setting in a DT-defined lookup table, which defines what bits
correspond to each setting. There is no way to add
PIN_CONFIG_BIAS_DISABLE entries to the table, since there is instead
code to disable the bias by applying the disable values of both the
pullup and pulldown entries in the table.

However, this code is inside the table-lookup loop, so it would only
execute if there is an entry for PIN_CONFIG_BIAS_DISABLE in the table,
which can never exist, so this code never runs.

This commit lifts the offending code out of the loop, so it just
executes directly whenever PIN_CONFIG_BIAS_DISABLE is requested,
skippipng the table lookup loop.

This also introduces a new `param` variable to make the code slightly
more readable.

This bug seems to have existed when this code was first merged in commit
9dddb4df90d13 ("pinctrl: single: support generic pinconf"). Earlier
versions of this patch did have an entry for PIN_CONFIG_BIAS_DISABLE in
the lookup table, but that was removed, which is probably how this bug
was introduced.

Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
Reviewed-by: Haojian Zhuang <haojian.zhuang@linaro.org>
Reviewed-by: Tony Lindgren <tony@atomide.com>
Message-ID: <20240319110633.230329-1-matthijs@stdin.nl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/pinctrl-single.c

index b4f8aa609b972b59743102ed7b7a2960b7ce662a..a798f31d6954240b6aa0a1a6ed00ca9727b96bc8 100644 (file)
@@ -550,21 +550,30 @@ static int pcs_pinconf_set(struct pinctrl_dev *pctldev,
        unsigned offset = 0, shift = 0, i, data, ret;
        u32 arg;
        int j;
+       enum pin_config_param param;
 
        ret = pcs_get_function(pctldev, pin, &func);
        if (ret)
                return ret;
 
        for (j = 0; j < num_configs; j++) {
+               param = pinconf_to_config_param(configs[j]);
+
+               /* BIAS_DISABLE has no entry in the func->conf table */
+               if (param == PIN_CONFIG_BIAS_DISABLE) {
+                       /* This just disables all bias entries */
+                       pcs_pinconf_clear_bias(pctldev, pin);
+                       continue;
+               }
+
                for (i = 0; i < func->nconfs; i++) {
-                       if (pinconf_to_config_param(configs[j])
-                               != func->conf[i].param)
+                       if (param != func->conf[i].param)
                                continue;
 
                        offset = pin * (pcs->width / BITS_PER_BYTE);
                        data = pcs->read(pcs->base + offset);
                        arg = pinconf_to_config_argument(configs[j]);
-                       switch (func->conf[i].param) {
+                       switch (param) {
                        /* 2 parameters */
                        case PIN_CONFIG_INPUT_SCHMITT:
                        case PIN_CONFIG_DRIVE_STRENGTH:
@@ -576,9 +585,6 @@ static int pcs_pinconf_set(struct pinctrl_dev *pctldev,
                                data |= (arg << shift) & func->conf[i].mask;
                                break;
                        /* 4 parameters */
-                       case PIN_CONFIG_BIAS_DISABLE:
-                               pcs_pinconf_clear_bias(pctldev, pin);
-                               break;
                        case PIN_CONFIG_BIAS_PULL_DOWN:
                        case PIN_CONFIG_BIAS_PULL_UP:
                                if (arg)