]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
gpio-uclass: fix gpio lookup by label
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>
Mon, 3 Oct 2022 09:02:45 +0000 (11:02 +0200)
committerSimon Glass <sjg@chromium.org>
Sat, 29 Oct 2022 13:36:33 +0000 (07:36 -0600)
Matching anything that just happens to have the sought-for label as a
prefix is wrong. For example, if the board designer has designated 10
lines for debug purposes, named "debug1" through "debug10", and we are
looking up "debug1", if debug10 happens to be met first during the
iteration we'd wrongly return that.

In theory, this can break existing users that could rely on this
quirk, but OTOH keeping the current broken semantics can cause a lot
of grief for people hitting this in the future and not understanding
why they don't find the line they expect. Considering how few in-tree
defconfigs currently set DM_GPIO_LOOKUP_LABEL (ignoring sandbox, only
four "real" boards), let's fix it before the use becomes more
widespread.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
drivers/gpio/gpio-uclass.c

index a00880e446c8631de4b1d2128d2ded554b5fbe17..65033258f47887d26f5afe1cd14c02e8ce277cb5 100644 (file)
@@ -91,15 +91,13 @@ static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc)
 static int dm_gpio_lookup_label(const char *name,
                                struct gpio_dev_priv *uc_priv, ulong *offset)
 {
-       int len;
        int i;
 
        *offset = -1;
-       len = strlen(name);
        for (i = 0; i < uc_priv->gpio_count; i++) {
                if (!uc_priv->name[i])
                        continue;
-               if (!strncmp(name, uc_priv->name[i], len)) {
+               if (!strcmp(name, uc_priv->name[i])) {
                        *offset = i;
                        return 0;
                }