OSDN Git Service

pinctrl: sh-pfc: Validate pin tables at runtime
authorGeert Uytterhoeven <geert+renesas@glider.be>
Wed, 27 Mar 2019 10:41:36 +0000 (11:41 +0100)
committerGeert Uytterhoeven <geert+renesas@glider.be>
Tue, 21 May 2019 09:07:29 +0000 (11:07 +0200)
Extend the run-time debug code with checks to ensure there are no
conflicting pin names, numbers, or enumeration values.

This helps catching bugs early.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
drivers/pinctrl/sh-pfc/core.c

index b4ba981..b8640ad 100644 (file)
@@ -773,6 +773,35 @@ static void __init sh_pfc_check_info(const struct sh_pfc_soc_info *info)
 
        pr_info("Checking %s\n", drvname);
 
+       /* Check pins */
+       for (i = 0; i < info->nr_pins; i++) {
+               for (j = 0; j < i; j++) {
+                       if (!strcmp(info->pins[i].name, info->pins[j].name)) {
+                               pr_err("%s: pin %s/%s: name conflict\n",
+                                      drvname, info->pins[i].name,
+                                      info->pins[j].name);
+                               sh_pfc_errors++;
+                       }
+
+                       if (info->pins[i].pin != (u16)-1 &&
+                           info->pins[i].pin == info->pins[j].pin) {
+                               pr_err("%s: pin %s/%s: pin %u conflict\n",
+                                      drvname, info->pins[i].name,
+                                      info->pins[j].name, info->pins[i].pin);
+                               sh_pfc_errors++;
+                       }
+
+                       if (info->pins[i].enum_id &&
+                           info->pins[i].enum_id == info->pins[j].enum_id) {
+                               pr_err("%s: pin %s/%s: enum_id %u conflict\n",
+                                      drvname, info->pins[i].name,
+                                      info->pins[j].name,
+                                      info->pins[i].enum_id);
+                               sh_pfc_errors++;
+                       }
+               }
+       }
+
        /* Check groups and functions */
        refcnts = kcalloc(info->nr_groups, sizeof(*refcnts), GFP_KERNEL);
        if (!refcnts)