]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pinctrl: pinconf-generic: perform basic checks on pincfg properties
authorConor Dooley <conor.dooley@microchip.com>
Tue, 24 Feb 2026 13:39:04 +0000 (13:39 +0000)
committerLinus Walleij <linusw@kernel.org>
Fri, 27 Feb 2026 00:18:43 +0000 (01:18 +0100)
Some pinconf properties are mutually exclusive, either because they
convey the same information in different units or represent incompatible
configurations of the same pin. Attempt, in two ways, to prevent these
situations.

Firstly, for enable/disable properties, produce an error if both are
set. Since enable/disable properties share the same enum value, they can
be trivially checked via the newly added bitmap. Having both enable and
disable for the same config makes no sense at all, so produce an error
in this case.

For interactions between properties, doing them outside the loop makes
more sense as it can be evaluated once. In case there are some edge
cases that would be broken by producing an error, only warn for now.

Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
Signed-off-by: Linus Walleij <linusw@kernel.org>
drivers/pinctrl/pinconf-generic.c

index 94b1d057197c60efa56639258f7cf8cd266e2042..901a225f3531f53edf7c674d8ff67de98613fb51 100644 (file)
@@ -222,7 +222,10 @@ static int parse_dt_cfg(struct device_node *np,
                        unsigned int count, unsigned long *cfg,
                        unsigned int *ncfg)
 {
-       int i;
+       unsigned long *properties;
+       int i, test;
+
+       properties = bitmap_zalloc(count, GFP_KERNEL);
 
        for (i = 0; i < count; i++) {
                u32 val;
@@ -251,11 +254,45 @@ static int parse_dt_cfg(struct device_node *np,
                if (ret)
                        val = par->default_value;
 
+               /* if param is greater than count, these are custom properties */
+               if (par->param <= count) {
+                       ret = test_and_set_bit(par->param, properties);
+                       if (ret) {
+                               pr_err("%s: conflicting setting detected for %s\n",
+                                      np->name, par->property);
+                               bitmap_free(properties);
+                               return -EINVAL;
+                       }
+               }
+
                pr_debug("found %s with value %u\n", par->property, val);
                cfg[*ncfg] = pinconf_to_config_packed(par->param, val);
                (*ncfg)++;
        }
 
+       if (test_bit(PIN_CONFIG_DRIVE_STRENGTH, properties) &&
+                       test_bit(PIN_CONFIG_DRIVE_STRENGTH_UA, properties))
+               pr_err("%s: cannot have multiple drive strength properties\n",
+                      np->name);
+
+       test = test_bit(PIN_CONFIG_BIAS_BUS_HOLD, properties) +
+               test_bit(PIN_CONFIG_BIAS_DISABLE, properties) +
+               test_bit(PIN_CONFIG_BIAS_HIGH_IMPEDANCE, properties) +
+               test_bit(PIN_CONFIG_BIAS_PULL_UP, properties) +
+               test_bit(PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, properties) +
+               test_bit(PIN_CONFIG_BIAS_PULL_DOWN, properties);
+       if (test > 1)
+               pr_err("%s: cannot have multiple bias configurations\n",
+                      np->name);
+
+       test = test_bit(PIN_CONFIG_DRIVE_OPEN_DRAIN, properties) +
+               test_bit(PIN_CONFIG_DRIVE_OPEN_SOURCE, properties) +
+               test_bit(PIN_CONFIG_DRIVE_PUSH_PULL, properties);
+       if (test > 1)
+               pr_err("%s: cannot have multiple drive configurations\n",
+                      np->name);
+
+       bitmap_free(properties);
        return 0;
 }