linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH 3/4] pinctrl: sh-pfc: Add check for empty pinmux groups/functions
Date: Thu, 25 Apr 2019 11:55:41 +0200	[thread overview]
Message-ID: <20190425095542.726-4-geert+renesas@glider.be> (raw)
In-Reply-To: <20190425095542.726-1-geert+renesas@glider.be>

The pinmux groups and functions arrays may contain two parts, to ease
supporting SoCs that expose pin subsets of other related SoCs.  Both
parts need to be declared with explicit sizes, which thus need to be
updated when adding support for more groups and functions.

If a size is too small, the compiler will detect this at build time
("excess elements in array initializer").
If a size is too large, this may go undetected (for pin groups), lead to
pin controller registration failures (for pin functions: "pinmux ops has
no name for functionN"), or crash the optional run-time debug code (for
pin groups).

Extend the run-time debug code with checks to detect this, to help
catching bugs early.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/pinctrl/sh-pfc/core.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/sh-pfc/core.c b/drivers/pinctrl/sh-pfc/core.c
index 868b9551438efb0a..889e5af281022e1d 100644
--- a/drivers/pinctrl/sh-pfc/core.c
+++ b/drivers/pinctrl/sh-pfc/core.c
@@ -780,9 +780,15 @@ static void __init sh_pfc_check_info(const struct sh_pfc_soc_info *info)
 
 	for (i = 0; i < info->nr_functions; i++) {
 		func = &info->functions[i];
+		if (!func->name) {
+			pr_err("%s: empty function %u\n", drvname, i);
+			sh_pfc_errors++;
+			continue;
+		}
 		for (j = 0; j < func->nr_groups; j++) {
 			for (k = 0; k < info->nr_groups; k++) {
-				if (!strcmp(func->groups[j],
+				if (info->groups[k].name &&
+				    !strcmp(func->groups[j],
 					    info->groups[k].name)) {
 					refcnts[k]++;
 					break;
@@ -798,6 +804,11 @@ static void __init sh_pfc_check_info(const struct sh_pfc_soc_info *info)
 	}
 
 	for (i = 0; i < info->nr_groups; i++) {
+		if (!info->groups[i].name) {
+			pr_err("%s: empty group %u\n", drvname, i);
+			sh_pfc_errors++;
+			continue;
+		}
 		if (!refcnts[i]) {
 			pr_err("%s: orphan group %s\n", drvname,
 			       info->groups[i].name);
-- 
2.17.1


  parent reply	other threads:[~2019-04-25  9:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25  9:55 [PATCH 0/4] pinctrl: sh-pfc: Run-time debug code fixes and enhancements Geert Uytterhoeven
2019-04-25  9:55 ` [PATCH 1/4] pinctrl: sh-pfc: Correct printk level of group referral warning Geert Uytterhoeven
2019-04-26  9:21   ` Simon Horman
2019-04-29  8:38     ` Geert Uytterhoeven
2019-04-29  8:49       ` Simon Horman
2019-04-25  9:55 ` [PATCH 2/4] pinctrl: sh-pfc: Mark run-time debug code __init Geert Uytterhoeven
2019-04-26  9:29   ` Simon Horman
2019-04-25  9:55 ` Geert Uytterhoeven [this message]
2019-04-26  9:34   ` [PATCH 3/4] pinctrl: sh-pfc: Add check for empty pinmux groups/functions Simon Horman
2019-04-26  9:42     ` Geert Uytterhoeven
2019-04-26  9:53       ` Simon Horman
2019-04-25  9:55 ` [PATCH 4/4] pinctrl: sh-pfc: Validate pin tables at runtime Geert Uytterhoeven
2019-04-26  9:36   ` Simon Horman
2019-05-03  7:25 ` [PATCH 0/4] pinctrl: sh-pfc: Run-time debug code fixes and enhancements Linus Walleij
2019-05-03  7:33   ` 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=20190425095542.726-4-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 \
    /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).