Skip to contentSkip to conversation

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

PATCH New Wei Yongjun 3 participants 5 messages Jan 5, 2018 – Jan 10, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: meson-axg: fix potential NULL dereference in axg_clkc_probe()

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);

---
 drivers/clk/meson/axg.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clk/meson/axg.c +2 -0
index d883bef..1294f3a 100644
@@ -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");
maintainer
#1 lore raw

PATCH 1/1 clk: meson-axg: fix potential NULL dereference in axg_clkc_probe()

Quoted 9 lines · Wei Yongjun

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;
@@

Quoted 8 lines

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

---

Looks good. Thank you.

Stephen, do you prefer to take this directly ?

#2 lore raw

PATCH 1/1 clk: meson-axg: fix potential NULL dereference in axg_clkc_probe()

Quoted 16 lines · Jerome Brunet
Quoted 15 lines · Wei Yongjun

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);

Quoted 6 lines
Quoted 2 lines

---

Looks good. Thank you.

Stephen, do you prefer to take this directly ?

Yes. Will do today.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#3 lore raw

PATCH 1/1 clk: meson-axg: fix potential NULL dereference in axg_clkc_probe()

In reply to Wei Yongjun
Quoted 9 lines · Wei Yongjun

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;
@@

Quoted 5 lines

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.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
Applied
#4 lore raw

PATCH 1/1 clk: meson-axg: fix potential NULL dereference in axg_clkc_probe()

In reply to Wei Yongjun
Quoted 9 lines · Wei Yongjun

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;
@@

Quoted 8 lines

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

---

Applied to clk-next

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project