Skip to contentSkip to conversation

remoteproc: mediatek: Dereferencing a pointer that might be NULL

PATCH In review Jason-ch Chen 2 participants 3 messages Mar 3, 2023 – Mar 9, 2023

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

PATCH 1/1 remoteproc: mediatek: Dereferencing a pointer that might be NULL

From: jason-ch chen <[email protected]>

The res might be NULL when calling resource_size.

---
 drivers/remoteproc/mtk_scp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/remoteproc/mtk_scp.c +3 -0
index eacdf241f4ef..863d18f63f58 100644
@@ -829,6 +829,9 @@ static int scp_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, scp);
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
+	if (!res)
+		return -ENODEV;
+
 	scp->sram_base = devm_ioremap_resource(dev, res);
 	if (IS_ERR((__force void *)scp->sram_base)) {
 		dev_err(dev, "Failed to parse and map sram memory\n");
Signature · 1 line
2.37.3
maintainer
#1 lore raw
Quoted 5 lines · Jason-ch Chen

From: jason-ch chen <[email protected]>

The res might be NULL when calling resource_size.

"resource_size" ? What is that?

Quoted 10 lines
---
 drivers/remoteproc/mtk_scp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/remoteproc/mtk_scp.c +0 -0
index eacdf241f4ef..863d18f63f58 100644

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 834

Quoted 6 lines
drivers/remoteproc/mtk_scp.c +3 -0
@@ -829,6 +829,9 @@ static int scp_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, scp);
 
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
+       if (!res)
+               return -ENODEV;
+

Please have a look at the implementation of devm_ioremap_resource() along with the function it calls and let me know if your patch is needed.

Quoted 6 lines
drivers/remoteproc/mtk_scp.c +0 -1
        scp->sram_base = devm_ioremap_resource(dev, res);
        if (IS_ERR((__force void *)scp->sram_base)) {
                dev_err(dev, "Failed to parse and map sram memory\n");
--

2.37.3

#2 lore raw

Hi Mathieu,

Quoted 24 lines · Mathieu Poirier
Quoted 5 lines · Jason-ch Chen

From: jason-ch chen <[email protected]>

The res might be NULL when calling resource_size.

"resource_size" ? What is that?

Quoted 14 lines
---
 drivers/remoteproc/mtk_scp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/remoteproc/mtk_scp.c +0 -0
index eacdf241f4ef..863d18f63f58 100644
@@ -829,6 +829,9 @@ static int scp_probe(struct platform_device
 *pdev)
        platform_set_drvdata(pdev, scp);
 
Quoted 10 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 834

Quoted 5 lines
drivers/remoteproc/mtk_scp.c +3 -0
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
 "sram");
+       if (!res)
+               return -ENODEV;
+

Please have a look at the implementation of devm_ioremap_resource() along with the function it calls and let me know if your patch is needed.

Thanks for your reply.
It seems is patch is not needed.

Quoted 7 lines
Quoted 7 lines
drivers/remoteproc/mtk_scp.c +0 -0
        scp->sram_base = devm_ioremap_resource(dev, res);

if (IS_ERR((__force void *)scp->sram_base)) {
dev_err(dev, "Failed to parse and map sram
memory\n");
--
2.37.3