pinctrl: sh-pfc: Validate enum IDs for regs with fixed-width fields
authorGeert Uytterhoeven <geert+renesas@glider.be>
Tue, 18 Dec 2018 08:31:49 +0000 (09:31 +0100)
committerGeert Uytterhoeven <geert+renesas@glider.be>
Tue, 2 Apr 2019 07:58:04 +0000 (09:58 +0200)
Add build-time checks to the PINMUX_CFG_REG() and PINMUX_DATA_REG()
macros, to ensure the number of provided enum IDs is correct.

This helps catching bugs early.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
drivers/pinctrl/sh-pfc/sh_pfc.h

index 57e13b6..31acde5 100644 (file)
@@ -130,7 +130,9 @@ struct pinmux_cfg_reg {
  */
 #define PINMUX_CFG_REG(name, r, r_width, f_width, ids)                 \
        .reg = r, .reg_width = r_width,                                 \
-       .field_width = f_width + BUILD_BUG_ON_ZERO(r_width % f_width),  \
+       .field_width = f_width + BUILD_BUG_ON_ZERO(r_width % f_width) + \
+       BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \
+                         (r_width / f_width) * (1 << f_width)),        \
        .enum_ids = (const u16 [(r_width / f_width) * (1 << f_width)])  \
                { ids }
 
@@ -196,7 +198,9 @@ struct pinmux_data_reg {
  *          enum ID must be specified, all wrapped using the GROUP() macro.
  */
 #define PINMUX_DATA_REG(name, r, r_width, ids)                         \
-       .reg = r, .reg_width = r_width,                                 \
+       .reg = r, .reg_width = r_width +                                \
+       BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \
+                         r_width),                                     \
        .enum_ids = (const u16 [r_width]) { ids }
 
 struct pinmux_irq {