reset: hisilicon: fix potential NULL pointer dereference
PATCH 1/1 reset: hisilicon: fix potential NULL pointer dereference
There is a potential execution path in which function platform_get_resource() returns NULL. If this happens, we will end up having a NULL pointer dereference.
Fix this by adding asanity check in order to avoid a NULL pointer dereference.
This code was detected with the help of Coccinelle.
--- drivers/clk/hisilicon/reset.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/clk/hisilicon/reset.c +3 -0
@@ -109,6 +109,9 @@ struct hisi_reset_controller *hisi_reset_init(struct platform_device *pdev)return NULL ; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return NULL ; + rstc->membase =devm_ioremap (&pdev->dev, res->start,resource_size (res));if (!rstc->membase)
Signature · 1 line
2.7.4
Stephen Boyd
maintainerQuoting Gustavo A. R. Silva (2018-07-18 18:58:45)
Quoted 9 lines
There is a potential execution path in which function
platform_get_resource()returns NULL. If this happens, we will end up having a NULL pointer dereference. =Fix this by adding asanity check in order to avoid a NULL pointer dereference.
=
Quoted 5 lines
This code was detected with the help of Coccinelle. =
Fixes 97b7129cd2af ("reset: hisilicon: change the definition of hisi_res=
et_init")
drivers/clk/hisilicon/reset.c struct hisi_reset_controller *hisi_reset_init(struct =
Quoted 11 lines
Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/clk/hisilicon/reset.c | 3 +++ 1 file changed, 3 insertions(+)=
drivers/clk/hisilicon/reset.c +0
-0@@ -109,6 +109,9 @@ struct hisi_reset_controller *hisi_reset_init(struct =
platform_device *pdev)
drivers/clk/hisilicon/reset.c struct hisi_reset_controller *hisi_reset_init(struct platform_device *pdev) · line 116
Quoted 9 lines
drivers/clk/hisilicon/reset.c +3
-0return NULL ; = res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); +if (!res) +return NULL ; + rstc->membase =3D devm_ioremap(&pdev->dev, res->start,resource_size (res));
Why can't we use devm_ioremap_resource() here instead?
Hi Stephen,
Quoted 24 lines · Stephen Boyd
Quoting Gustavo A. R. Silva (2018-07-18 18:58:45)
Quoted 23 lines
There is a potential execution path in which function
platform_get_resource()returns NULL. If this happens, we will end up having a NULL pointer dereference.Fix this by adding asanity check in order to avoid a NULL pointer dereference.
This code was detected with the help of Coccinelle.
Fixes 97b7129cd2af ("reset: hisilicon: change the definition of hisi_reset_init")Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/clk/hisilicon/reset.c | 3 +++ 1 file changed, 3 insertions(+)drivers/clk/hisilicon/reset.c +0
-0@@ -109,6 +109,9 @@ struct hisi_reset_controller *hisi_reset_init(struct platform_device *pdev)return NULL ;
Quoted 9 lines
drivers/clk/hisilicon/reset.c struct hisi_reset_controller *hisi_reset_init(struct platform_device *pdev) · line 116
Quoted 6 lines
drivers/clk/hisilicon/reset.c +3
-0res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return NULL ; + rstc->membase =devm_ioremap (&pdev->dev, res->start,resource_size (res));Why can't we use
devm_ioremap_resource()here instead?
You're right. I think we can perfectly use devm_ioremap_resource here and remove the null check.
I'll send patch for this shortly.
Thanks
--
Gustavo