From: Nicholas Mc Guire <hofrat@osadl.org>
To: David Lechner <david@lechnology.com>
Cc: Sekhar Nori <nsekhar@ti.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
Nicholas Mc Guire <hofrat@osadl.org>
Subject: [PATCH] clk: davinci: check for devm_kasprintf() failure
Date: Fri, 23 Nov 2018 18:33:28 +0100 [thread overview]
Message-ID: <1542994408-28466-1-git-send-email-hofrat@osadl.org> (raw)
devm_kasprintf() may return NULL on failure of internal allocation thus
the assignment to lpsc->pm_domain.name is not safe if not checked. On
error davinci_lpsc_clk_register() returns a pointer to davinci_lpsc_clk
which is checked with IS_ERR() so returning ERR_PTR(-ENOMEM) should be
fine here.
Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Fixes: c6ed4d734bc7 ("clk: davinci: New driver for davinci PSC clocks")
---
Problem located with experimental coccinelle script
Patch was compile tested with: davinci_all_defconfig
Patch is against 4.20-rc3 (localversion-next is next-20181123)
drivers/clk/davinci/psc.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/clk/davinci/psc.c b/drivers/clk/davinci/psc.c
index 5b69e24..ca9b5c3 100644
--- a/drivers/clk/davinci/psc.c
+++ b/drivers/clk/davinci/psc.c
@@ -278,6 +278,11 @@ davinci_lpsc_clk_register(struct device *dev, const char *name,
lpsc->pm_domain.name = devm_kasprintf(dev, GFP_KERNEL, "%s: %s",
best_dev_name(dev), name);
+ if (!lpsc->pm_domain.name) {
+ kfree(lpsc);
+ return ERR_PTR(-ENOMEM);
+ }
+
lpsc->pm_domain.attach_dev = davinci_psc_genpd_attach_dev;
lpsc->pm_domain.detach_dev = davinci_psc_genpd_detach_dev;
lpsc->pm_domain.flags = GENPD_FLAG_PM_CLK;
--
2.1.4
next reply other threads:[~2018-11-23 17:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-23 17:33 Nicholas Mc Guire [this message]
2018-11-28 22:06 ` [PATCH] clk: davinci: check for devm_kasprintf() failure Stephen Boyd
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=1542994408-28466-1-git-send-email-hofrat@osadl.org \
--to=hofrat@osadl.org \
--cc=david@lechnology.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=nsekhar@ti.com \
--cc=sboyd@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).