From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-sh@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH v3 09/10] pinctrl: sh-pfc: Validate enum IDs for regs with fixed-width fields
Date: Wed, 20 Mar 2019 11:21:40 +0100 [thread overview]
Message-ID: <20190320102141.19316-10-geert+renesas@glider.be> (raw)
In-Reply-To: <20190320102141.19316-1-geert+renesas@glider.be>
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>
---
v3:
- No changes,
v2:
- Convert from run-time to build-time check.
- Add check for PINMUX_DATA_REG().
---
drivers/pinctrl/sh-pfc/sh_pfc.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/sh-pfc/sh_pfc.h b/drivers/pinctrl/sh-pfc/sh_pfc.h
index 57e13b623b2e87ec..31acde5032a0691a 100644
--- a/drivers/pinctrl/sh-pfc/sh_pfc.h
+++ b/drivers/pinctrl/sh-pfc/sh_pfc.h
@@ -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 {
--
2.17.1
next prev parent reply other threads:[~2019-03-20 10:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-20 10:21 [PATCH v3 00/10] pinctrl: sh-pfc: Validation and compile-testing Geert Uytterhoeven
2019-03-20 10:21 ` [PATCH v3 01/10] pinctrl: sh-pfc: Validate pinmux tables at runtime when debugging Geert Uytterhoeven
2019-03-20 10:21 ` [PATCH v3 02/10] pinctrl: sh-pfc: Introduce PINCTRL_SH_FUNC_GPIO helper symbol Geert Uytterhoeven
2019-03-27 11:50 ` Simon Horman
2019-03-20 10:21 ` [PATCH v3 03/10] pinctrl: sh-pfc: Add missing #include <linux/errno.h> Geert Uytterhoeven
2019-03-27 11:46 ` Simon Horman
2019-03-20 10:21 ` [PATCH v3 04/10] sh: sh7786: Add explicit I/O cast to sh7786_mm_sel() Geert Uytterhoeven
2019-03-27 11:48 ` Simon Horman
2019-03-20 10:21 ` [PATCH v3 05/10] pinctrl: sh-pfc: Allow compile-testing of all drivers Geert Uytterhoeven
2019-03-27 11:50 ` Simon Horman
2019-03-20 10:21 ` [PATCH v3 06/10 PARTIAL] pinctrl: sh-pfc: Absorb enum IDs in PINMUX_CFG_REG() macro Geert Uytterhoeven
2019-03-20 10:21 ` [PATCH v3 07/10 PARTIAL] pinctrl: sh-pfc: Absorb enum IDs in PINMUX_CFG_REG_VAR() macro Geert Uytterhoeven
2019-03-20 10:21 ` [PATCH v3 08/10 PARTIAL] pinctrl: sh-pfc: Absorb enum IDs in PINMUX_DATA_REG() macro Geert Uytterhoeven
2019-03-20 10:21 ` Geert Uytterhoeven [this message]
2019-03-20 10:21 ` [PATCH v3 10/10] pinctrl: sh-pfc: Validate enum IDs for regs with variable-width fields Geert Uytterhoeven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190320102141.19316-10-geert+renesas@glider.be \
--to=geert+renesas@glider.be \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).