diff mbox

[-next] clk: meson-axg: fix potential NULL dereference in axg_clkc_probe()

Message ID 1515117059-176004-1-git-send-email-weiyongjun1@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Yongjun Jan. 5, 2018, 1:50 a.m. UTC
platform_get_resource() may return NULL, add proper
check to avoid potential NULL dereferencing.

This is detected by Coccinelle semantic patch.

@@
expression pdev, res, n, t, e, e1, e2;
@@

res = platform_get_resource(pdev, t, n);
+ if (!res)
+   return -EINVAL;
... when != res == NULL
e = devm_ioremap(e1, res->start, e2);

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 drivers/clk/meson/axg.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Jerome Brunet Jan. 5, 2018, 9:09 a.m. UTC | #1
On Fri, 2018-01-05 at 01:50 +0000, Wei Yongjun wrote:
> platform_get_resource() may return NULL, add proper
> check to avoid potential NULL dereferencing.
> 
> This is detected by Coccinelle semantic patch.
> 
> @@
> expression pdev, res, n, t, e, e1, e2;
> @@
> 
> res = platform_get_resource(pdev, t, n);
> + if (!res)
> +   return -EINVAL;
> ... when != res == NULL
> e = devm_ioremap(e1, res->start, e2);
> 
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---

Looks good. Thank you.

Stephen, do you prefer to take this directly ?
Stephen Boyd Jan. 5, 2018, 4:24 p.m. UTC | #2
On 01/05, Jerome Brunet wrote:
> On Fri, 2018-01-05 at 01:50 +0000, Wei Yongjun wrote:
> > platform_get_resource() may return NULL, add proper
> > check to avoid potential NULL dereferencing.
> > 
> > This is detected by Coccinelle semantic patch.
> > 
> > @@
> > expression pdev, res, n, t, e, e1, e2;
> > @@
> > 
> > res = platform_get_resource(pdev, t, n);
> > + if (!res)
> > +   return -EINVAL;
> > ... when != res == NULL
> > e = devm_ioremap(e1, res->start, e2);
> > 
> > Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> > ---
> 
> Looks good. Thank you.
> 
> Stephen, do you prefer to take this directly ?

Yes. Will do today.
Stephen Boyd Jan. 10, 2018, 9:18 p.m. UTC | #3
On 01/05, Wei Yongjun wrote:
> platform_get_resource() may return NULL, add proper
> check to avoid potential NULL dereferencing.
> 
> This is detected by Coccinelle semantic patch.
> 
> @@
> expression pdev, res, n, t, e, e1, e2;
> @@
> 
> res = platform_get_resource(pdev, t, n);
> + if (!res)
> +   return -EINVAL;
> ... when != res == NULL
> e = devm_ioremap(e1, res->start, e2);

Can this script be put into scripts/coccinelle/? I'd like to be
able to run it instead of getting emails from you after patches
merge.
Stephen Boyd Jan. 10, 2018, 9:24 p.m. UTC | #4
On 01/05, Wei Yongjun wrote:
> platform_get_resource() may return NULL, add proper
> check to avoid potential NULL dereferencing.
> 
> This is detected by Coccinelle semantic patch.
> 
> @@
> expression pdev, res, n, t, e, e1, e2;
> @@
> 
> res = platform_get_resource(pdev, t, n);
> + if (!res)
> +   return -EINVAL;
> ... when != res == NULL
> e = devm_ioremap(e1, res->start, e2);
> 
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---

Applied to clk-next
diff mbox

Patch

diff --git a/drivers/clk/meson/axg.c b/drivers/clk/meson/axg.c
index d883bef..1294f3a 100644
--- a/drivers/clk/meson/axg.c
+++ b/drivers/clk/meson/axg.c
@@ -879,6 +879,8 @@  static int axg_clkc_probe(struct platform_device *pdev)
 
 	/*  Generic clocks and PLLs */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 	clk_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
 	if (!clk_base) {
 		dev_err(&pdev->dev, "Unable to map clk base\n");