All of lore.kernel.org
 help / color / mirror / Atom feed
From: fabrizio.castro@bp.renesas.com (Fabrizio Castro)
To: cip-dev@lists.cip-project.org
Subject: [cip-dev] [PATCH/RFC 4.19.y-cip 11/41] pinctrl: sh-pfc: Validate enum IDs for regs with variable-width fields
Date: Wed, 28 Aug 2019 12:21:38 +0100	[thread overview]
Message-ID: <1566991328-25476-12-git-send-email-fabrizio.castro@bp.renesas.com> (raw)
In-Reply-To: <1566991328-25476-1-git-send-email-fabrizio.castro@bp.renesas.com>

From: Geert Uytterhoeven <geert+renesas@glider.be>

commit fa4d36712f20e2425171ab1f62341ebb6416d3ea upstream.

Add a run-time check to the PINMUX_CFG_REG_VAR() macro, to ensure the
number of provided enum IDs is correct.  This cannot be done at build
time, as the number of values depends on the variable-width fields in
the config register.

This helps catching bugs early.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
---
 drivers/pinctrl/sh-pfc/core.c   | 6 ++++++
 drivers/pinctrl/sh-pfc/sh_pfc.h | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/drivers/pinctrl/sh-pfc/core.c b/drivers/pinctrl/sh-pfc/core.c
index 2c8c7b2..3ffd945 100644
--- a/drivers/pinctrl/sh-pfc/core.c
+++ b/drivers/pinctrl/sh-pfc/core.c
@@ -753,6 +753,12 @@ static void sh_pfc_check_cfg_reg(const char *drvname,
 		       drvname, cfg_reg->reg, rw, cfg_reg->reg_width);
 		sh_pfc_errors++;
 	}
+
+	if (n != cfg_reg->nr_enum_ids) {
+		pr_err("%s: reg 0x%x: enum_ids[] has %u instead of %u values\n",
+		       drvname, cfg_reg->reg, cfg_reg->nr_enum_ids, n);
+		sh_pfc_errors++;
+	}
 }
 
 static void sh_pfc_check_info(const struct sh_pfc_soc_info *info)
diff --git a/drivers/pinctrl/sh-pfc/sh_pfc.h b/drivers/pinctrl/sh-pfc/sh_pfc.h
index c02b095..499356d 100644
--- a/drivers/pinctrl/sh-pfc/sh_pfc.h
+++ b/drivers/pinctrl/sh-pfc/sh_pfc.h
@@ -114,6 +114,12 @@ struct pinmux_func {
 struct pinmux_cfg_reg {
 	u32 reg;
 	u8 reg_width, field_width;
+#ifdef DEBUG
+	u16 nr_enum_ids;	/* for variable width regs only */
+#define SET_NR_ENUM_IDS(n)	.nr_enum_ids = n,
+#else
+#define SET_NR_ENUM_IDS(n)
+#endif
 	const u16 *enum_ids;
 	const u8 *var_field_width;
 };
@@ -154,6 +160,7 @@ struct pinmux_cfg_reg {
 #define PINMUX_CFG_REG_VAR(name, r, r_width, f_widths, ids)		\
 	.reg = r, .reg_width = r_width,					\
 	.var_field_width = (const u8 []) { f_widths, 0 },		\
+	SET_NR_ENUM_IDS(sizeof((const u16 []) { ids }) / sizeof(u16))	\
 	.enum_ids = (const u16 []) { ids }
 
 struct pinmux_drive_reg_field {
-- 
2.7.4

  parent reply	other threads:[~2019-08-28 11:21 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-28 11:21 [cip-dev] [PATCH/RFC 4.19.y-cip 00/41] Fast forward sh-pfc Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 01/41] pinctrl: sh-pfc: Print actual field width for variable-width fields Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 02/41] pinctrl: sh-pfc: Validate pinmux tables at runtime when debugging Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 03/41] pinctrl: sh-pfc: Add physical pin multiplexing helper macros Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 04/41] pinctrl: sh-pfc: Validate pins/marks in pin groups at build time Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 05/41] pinctrl: sh-pfc: Make pinmux_cfg_reg.var_field_width[] variable-length Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 06/41] pinctrl: sh-pfc: Validate fixed-size field widths at build time Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 07/41] pinctrl: sh-pfc: Absorb enum IDs in PINMUX_CFG_REG() macro Fabrizio Castro
2019-08-29  8:09   ` Pavel Machek
2019-08-29  9:31     ` Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 08/41] pinctrl: sh-pfc: Absorb enum IDs in PINMUX_CFG_REG_VAR() macro Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 09/41] pinctrl: sh-pfc: Absorb enum IDs in PINMUX_DATA_REG() macro Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 10/41] pinctrl: sh-pfc: Validate enum IDs for regs with fixed-width fields Fabrizio Castro
2019-08-28 11:21 ` Fabrizio Castro [this message]
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 12/41] pinctrl: sh-pfc: Improve PINMUX_IPSR_PHYS() documentation Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 13/41] pinctrl: sh-pfc: Rename 2-parameter CPU_ALL_PORT() variant Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 14/41] pinctrl: sh-pfc: Add SH_PFC_PIN_CFG_PULL_UP_DOWN shorthand Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 15/41] pinctrl: sh-pfc: Add new non-GPIO helper macros Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 16/41] pinctrl: sh-pfc: Correct printk level of group reference warning Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 17/41] pinctrl: sh-pfc: Mark run-time debug code __init Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 18/41] pinctrl: sh-pfc: Add check for empty pinmux groups/functions Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 19/41] pinctrl: sh-pfc: Validate pin tables at runtime Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 20/41] pinctrl: sh-pfc: r8a7796: Fix VIN versioned groups Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 21/41] pinctrl: sh-pfc: r8a7796: Add I2C{0, 3, 5} pins, groups and functions Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 22/41] pinctrl: sh-pfc: r8a7796: Deduplicate VIN5 pin definitions Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 23/41] pinctrl: sh-pfc: r8a7796: Move CANFD pin groups and functions Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 24/41] pinctrl: sh-pfc: r8a77990: Rename IOCTRLx registers Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 25/41] pinctrl: sh-pfc: r8a77990: Move CANFD pin groups and functions Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 26/41] pinctrl: sh-pfc: rcar-gen3: Retain TDSELCTRL register across suspend/resume Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 27/41] pinctrl: sh-pfc: Add missing #include <linux/errno.h> Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 28/41] pinctrl: sh-pfc: rcar-gen3: Remove HDMI CEC pins, groups, and functions Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 29/41] pinctrl: sh-pfc: rcar-gen3: Remove CC5_OSCOUT pin Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 30/41] pinctrl: sh-pfc: rcar-gen3: Rename SEL_ADG_{A, B, C} to SEL_ADG{A, B, C} Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 31/41] pinctrl: sh-pfc: r8a77990: Fix MOD_SEL0 bit16 when using NFALE and NFRB_N Fabrizio Castro
2019-08-28 11:21 ` [cip-dev] [PATCH/RFC 4.19.y-cip 32/41] pinctrl: sh-pfc: r8a77990: Fix MOD_SEL1 bit31 when using SIM0_D Fabrizio Castro
2019-08-28 11:22 ` [cip-dev] [PATCH/RFC 4.19.y-cip 33/41] pinctrl: sh-pfc: r8a77990: Fix MOD_SEL1 bit30 when using SSI_SCK2 and SSI_WS2 Fabrizio Castro
2019-08-28 11:22 ` [cip-dev] [PATCH/RFC 4.19.y-cip 34/41] pinctrl: sh-pfc: rcar-gen3: Rename RTS{0, 1, 3, 4}# pin function definitions Fabrizio Castro
2019-08-28 11:22 ` [cip-dev] [PATCH/RFC 4.19.y-cip 35/41] pinctrl: sh-pfc: rcar-gen3: Rename SEL_NDFC to SEL_NDF Fabrizio Castro
2019-08-28 11:22 ` [cip-dev] [PATCH/RFC 4.19.y-cip 36/41] pinctrl: sh-pfc: Add PORT_GP_27 helper macro Fabrizio Castro
2019-08-28 11:22 ` [cip-dev] [PATCH/RFC 4.19.y-cip 37/41] pinctrl: sh-pfc: Move PIN_NONE to shared header file Fabrizio Castro
2019-08-28 11:22 ` [cip-dev] [PATCH/RFC 4.19.y-cip 38/41] pinctrl: sh-pfc: r8a77990: Use new macros for non-GPIO pins Fabrizio Castro
2019-08-28 11:22 ` [cip-dev] [PATCH/RFC 4.19.y-cip 39/41] pinctrl: sh-pfc: r8a7796: Add TPU pins, groups and functions Fabrizio Castro
2019-08-28 11:22 ` [cip-dev] [PATCH/RFC 4.19.y-cip 40/41] pinctrl: sh-pfc: r8a7796: Use new macros for non-GPIO pins Fabrizio Castro
2019-08-28 11:22 ` [cip-dev] [PATCH/RFC 4.19.y-cip 41/41] pinctrl: sh-pfc: r8a7796: Remove placeholder I2C pin data Fabrizio Castro
2019-08-29  8:12 ` [cip-dev] [PATCH/RFC 4.19.y-cip 00/41] Fast forward sh-pfc Pavel Machek
2019-08-29  9:36   ` Fabrizio Castro
2019-08-29  9:47     ` Pavel Machek
2019-08-29  9:49       ` Fabrizio Castro
2019-08-29 10:23         ` Chris Paterson
2019-08-29 11:04           ` Fabrizio Castro
2019-08-29 13:51             ` Ben Hutchings
2019-08-29 17:07               ` Fabrizio Castro
2019-08-29 20:04               ` Pavel Machek
2019-08-29 22:35           ` Pavel Machek
2019-08-30  7:26             ` Chris Paterson

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=1566991328-25476-12-git-send-email-fabrizio.castro@bp.renesas.com \
    --to=fabrizio.castro@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.