* [PATCH] clk: davinci: check for devm_kasprintf() failure
@ 2018-11-23 17:33 Nicholas Mc Guire
2018-11-28 22:06 ` Stephen Boyd
0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Mc Guire @ 2018-11-23 17:33 UTC (permalink / raw)
To: David Lechner
Cc: Sekhar Nori, Michael Turquette, Stephen Boyd, linux-clk,
linux-kernel, Nicholas Mc Guire
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] clk: davinci: check for devm_kasprintf() failure
2018-11-23 17:33 [PATCH] clk: davinci: check for devm_kasprintf() failure Nicholas Mc Guire
@ 2018-11-28 22:06 ` Stephen Boyd
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2018-11-28 22:06 UTC (permalink / raw)
To: David Lechner, Nicholas Mc Guire
Cc: Sekhar Nori, Michael Turquette, linux-clk, linux-kernel,
Nicholas Mc Guire
Quoting Nicholas Mc Guire (2018-11-23 09:33:28)
> 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)
There are a bunch of other allocation issues with this driver so I'd
rather not expend the effort to review the one coccinelle script fix
here and instead I'd like to see the whole fix to this driver. Please
add proper lifetime management for all the allocations in this code.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-11-28 22:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-23 17:33 [PATCH] clk: davinci: check for devm_kasprintf() failure Nicholas Mc Guire
2018-11-28 22:06 ` Stephen Boyd
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).