From: Nicholas Mc Guire <hofrat@osadl.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Jacopo Mondi <jacopo+renesas@jmondi.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Nicholas Mc Guire <hofrat@osadl.org>
Subject: [PATCH V2] pinctrl: rza1: handle devm_kasprintf() failure cases
Date: Fri, 7 Dec 2018 11:34:27 +0100 [thread overview]
Message-ID: <1544178867-13169-1-git-send-email-hofrat@osadl.org> (raw)
devm_kasprintf() may return NULL on failure of internal allocation
thus the assignments are not safe if not checked. On error
rza1_pinctrl_register() respectively rza1_parse_gpiochip() return
negative values so -ENOMEM in the (unlikely) failure case of
devm_kasprintf() should be fine here.
Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Fixes: 5a49b644b307 ("pinctrl: Renesas RZ/A1 pin and gpio controller")
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Problem was located with an experimental coccinelle script
V2: drop the dev_err() messages as requested by Geert Uytterhoeven
<geert@linux-m68k.org> - thanks !
Patch was compile tested with: shmobile_defconfig (implies PINCTRL_RZA1=y)
Patch is against 4.20-rc5 (localversion-next is next-20181207)
drivers/pinctrl/pinctrl-rza1.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-rza1.c b/drivers/pinctrl/pinctrl-rza1.c
index 14eb576..9cfe9d0 100644
--- a/drivers/pinctrl/pinctrl-rza1.c
+++ b/drivers/pinctrl/pinctrl-rza1.c
@@ -1225,6 +1225,9 @@ static int rza1_parse_gpiochip(struct rza1_pinctrl *rza1_pctl,
chip->base = -1;
chip->label = devm_kasprintf(rza1_pctl->dev, GFP_KERNEL, "%pOFn",
np);
+ if (!chip->label)
+ return -ENOMEM;
+
chip->ngpio = of_args.args[2];
chip->of_node = np;
chip->parent = rza1_pctl->dev;
@@ -1326,6 +1329,8 @@ static int rza1_pinctrl_register(struct rza1_pinctrl *rza1_pctl)
pins[i].number = i;
pins[i].name = devm_kasprintf(rza1_pctl->dev, GFP_KERNEL,
"P%u-%u", port, pin);
+ if (!pins[i].name)
+ return -ENOMEM;
if (i % RZA1_PINS_PER_PORT == 0) {
/*
--
2.1.4
reply other threads:[~2018-12-07 10:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1544178867-13169-1-git-send-email-hofrat@osadl.org \
--to=hofrat@osadl.org \
--cc=geert@linux-m68k.org \
--cc=jacopo+renesas@jmondi.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@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).