Skip to contentSkip to conversation

net: macb: fix an issue about leak related system resources

PATCH In review Dejin Zheng 4 participants 9 messages Apr 25, 2020 – Apr 28, 2020

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

PATCH 1/1 net: macb: fix an issue about leak related system resources

A call of the function macb_init() can fail in the function fu540_c000_init. The related system resources were not released then. use devm_ioremap() to replace ioremap() for fix it.

Fixes c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
Cc Andy Shevchenko <[email protected]>
---
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +1 -1
index a0e8c5bbabc0..edba2eb56231 100644
@@ -4178,7 +4178,7 @@ static int fu540_c000_init(struct platform_device *pdev)
 	if (!res)
 		return -ENODEV;
 
-	mgmt->reg = ioremap(res->start, resource_size(res));
+	mgmt->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
 	if (!mgmt->reg)
 		return -ENOMEM;
 
Signature · 1 line
2.25.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 42 lines

-----Original Message-----
From: Dejin Zheng <[email protected]>
Sent: 25 April 2020 18:28
To: [email protected]; Paul Walmsley <[email protected]>; [email protected]; [email protected]; Yash Shah <[email protected]>; [email protected]
Cc: [email protected]; Dejin Zheng <[email protected]>; Andy Shevchenko <[email protected]>
Subject: [PATCH net v1] net: macb: fix an issue about leak related system resources

[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe

A call of the function macb_init() can fail in the function fu540_c000_init. The related system resources were not released then. use devm_ioremap() to replace ioremap() for fix it.

Fixes c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
Cc Andy Shevchenko <[email protected]>
---
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +2 -2
index a0e8c5bbabc0..edba2eb56231 100644
@@ -4178,7 +4178,7 @@ static int fu540_c000_init(struct platform_device
 *pdev)
        if (!res)
                return -ENODEV;
 
-       mgmt->reg = ioremap(res->start, resource_size(res));
+       mgmt->reg = devm_ioremap(&pdev->dev, res->start,
+ resource_size(res));
        if (!mgmt->reg)
                return -ENOMEM;
 
--
Quoted 1 line

2.25.0

The change looks good to me.

- Yash

#2 lore raw
Quoted 41 lines · Yash Shah
Quoted 41 lines

-----Original Message-----
From: Dejin Zheng <[email protected]>
Sent: 25 April 2020 18:28
To: [email protected]; Paul Walmsley <[email protected]>; [email protected]; [email protected]; Yash Shah <[email protected]>; [email protected]
Cc: [email protected]; Dejin Zheng <[email protected]>; Andy Shevchenko <[email protected]>
Subject: [PATCH net v1] net: macb: fix an issue about leak related system resources

[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe

A call of the function macb_init() can fail in the function fu540_c000_init. The related system resources were not released then. use devm_ioremap() to replace ioremap() for fix it.

Fixes c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
Cc Andy Shevchenko <[email protected]>
---
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +2 -1
index a0e8c5bbabc0..edba2eb56231 100644
@@ -4178,7 +4178,7 @@ static int fu540_c000_init(struct platform_device
 *pdev)
        if (!res)
                return -ENODEV;
 
-       mgmt->reg = ioremap(res->start, resource_size(res));
+       mgmt->reg = devm_ioremap(&pdev->dev, res->start,
+ resource_size(res));
        if (!mgmt->reg)
                return -ENOMEM;
Quoted 6 lines
Quoted 2 lines

--
2.25.0

The change looks good to me.

Thanks Yash!

Quoted 2 lines

- Yash

#3 lore raw
In reply to Dejin Zheng
Quoted 5 lines · Dejin Zheng

A call of the function macb_init() can fail in the function fu540_c000_init. The related system resources were not released then. use devm_ioremap() to replace ioremap() for fix it.

Why not to go further and convert to use devm_platform_ioremap_resource()?

Quoted 23 lines
Fixes c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
Cc Andy Shevchenko <[email protected]>
---
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +1 -2
index a0e8c5bbabc0..edba2eb56231 100644
@@ -4178,7 +4178,7 @@ static int fu540_c000_init(struct platform_device *pdev)
        if (!res)
                return -ENODEV;
 
-       mgmt->reg = ioremap(res->start, resource_size(res));
+       mgmt->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
        if (!mgmt->reg)
                return -ENOMEM;
 
--

2.25.0

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Dejin Zheng

A call of the function macb_init() can fail in the function fu540_c000_init. The related system resources were not released then. use devm_ioremap() to replace ioremap() for fix it.

Why not to go further and convert to use devm_platform_ioremap_resource()?

devm_platform_ioremap_resource() will call devm_request_mem_region(), and here did not do it.

Quoted 28 lines
Quoted 23 lines
Fixes c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
Cc Andy Shevchenko <[email protected]>
---
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +1 -2
index a0e8c5bbabc0..edba2eb56231 100644
@@ -4178,7 +4178,7 @@ static int fu540_c000_init(struct platform_device *pdev)
        if (!res)
                return -ENODEV;
 
-       mgmt->reg = ioremap(res->start, resource_size(res));
+       mgmt->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
        if (!mgmt->reg)
                return -ENOMEM;
 
--

2.25.0

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 8 lines · Dejin Zheng
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Dejin Zheng

A call of the function macb_init() can fail in the function fu540_c000_init. The related system resources were not released then. use devm_ioremap() to replace ioremap() for fix it.

Quoted 4 lines
Quoted 2 lines

Why not to go further and convert to use devm_platform_ioremap_resource()?

devm_platform_ioremap_resource() will call devm_request_mem_region(), and here did not do it.

And what about devm_platform_get_and_ioremap_resource()? This would streamline this whole fu540_c000_init() function.

Regards,
Nicolas

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Fixes c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
Cc Andy Shevchenko <[email protected]>
---
  drivers/net/ethernet/cadence/macb_main.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +1 -1
index a0e8c5bbabc0..edba2eb56231 100644
@@ -4178,7 +4178,7 @@ static int fu540_c000_init(struct platform_device *pdev)
         if (!res)
                 return -ENODEV;
 
-       mgmt->reg = ioremap(res->start, resource_size(res));
+       mgmt->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
         if (!mgmt->reg)
                 return -ENOMEM;
 
Signature · 1 line
Nicolas Ferre
#6 lore raw
Quoted 9 lines · Nicolas Ferre
Quoted 8 lines · Dejin Zheng
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Dejin Zheng

A call of the function macb_init() can fail in the function fu540_c000_init. The related system resources were not released then. use devm_ioremap() to replace ioremap() for fix it.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Why not to go further and convert to use devm_platform_ioremap_resource()?

devm_platform_ioremap_resource() will call devm_request_mem_region(), and here did not do it.

And what about devm_platform_get_and_ioremap_resource()? This would streamline this whole fu540_c000_init() function.

Nicolas, the function devm_platform_get_and_ioremap_resource() will also call devm_request_mem_region(), after call it, These IO addresses will be monopolized by this driver. the devm_ioremap() and ioremap() are not do this. if this IO addresses will be shared with the other driver, call devm_platform_get_and_ioremap_resource() may be fail.

BR,
Dejin

Quoted 27 lines

Regards,
Nicolas

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Fixes c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
Cc Andy Shevchenko <[email protected]>
---
  drivers/net/ethernet/cadence/macb_main.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +1 -1
index a0e8c5bbabc0..edba2eb56231 100644
@@ -4178,7 +4178,7 @@ static int fu540_c000_init(struct platform_device *pdev)
         if (!res)
                 return -ENODEV;
 
-       mgmt->reg = ioremap(res->start, resource_size(res));
+       mgmt->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
         if (!mgmt->reg)
                 return -ENOMEM;
 
Signature · 1 line
Nicolas Ferre
#7 lore raw
Quoted 15 lines · Dejin Zheng
Quoted 14 lines · Nicolas Ferre
Quoted 12 lines · Dejin Zheng
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Dejin Zheng

A call of the function macb_init() can fail in the function fu540_c000_init. The related system resources were not released then. use devm_ioremap() to replace ioremap() for fix it.

Why not to go further and convert to use devm_platform_ioremap_resource()?

devm_platform_ioremap_resource() will call devm_request_mem_region(), and here did not do it.

Quoted 8 lines
Quoted 3 lines

And what about devm_platform_get_and_ioremap_resource()? This would streamline this whole fu540_c000_init() function.

Nicolas, the function devm_platform_get_and_ioremap_resource() will also call devm_request_mem_region(), after call it, These IO addresses will be monopolized by this driver. the devm_ioremap() and ioremap() are not do this. if this IO addresses will be shared with the other driver, call devm_platform_get_and_ioremap_resource() may be fail.

I guess request region is a right thing to do. If driver is sharing this IO region with something else, it is a delayed bomb attack and has to be fixed.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw
Quoted 25 lines · Andy Shevchenko
Quoted 15 lines · Dejin Zheng
Quoted 14 lines · Nicolas Ferre
Quoted 12 lines · Dejin Zheng
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Dejin Zheng

A call of the function macb_init() can fail in the function fu540_c000_init. The related system resources were not released then. use devm_ioremap() to replace ioremap() for fix it.

Why not to go further and convert to use devm_platform_ioremap_resource()?

devm_platform_ioremap_resource() will call devm_request_mem_region(), and here did not do it.

Quoted 8 lines
Quoted 3 lines

And what about devm_platform_get_and_ioremap_resource()? This would streamline this whole fu540_c000_init() function.

Nicolas, the function devm_platform_get_and_ioremap_resource() will also call devm_request_mem_region(), after call it, These IO addresses will be monopolized by this driver. the devm_ioremap() and ioremap() are not do this. if this IO addresses will be shared with the other driver, call devm_platform_get_and_ioremap_resource() may be fail.

Quoted 5 lines

I guess request region is a right thing to do. If driver is sharing this IO region with something else, it is a delayed bomb attack and has to be fixed.

I did encounter IO address sharing, for example, some registers are shared by both PHY and USB controllers on Tegra SoCs. See link[1] for details. If many people think that devm_request_mem_region() should be added here, I will send patch v2 and convert to use devm_platform_ioremap_resource(). Thanks very much!

link[1]: https://patchwork.ozlabs.org/project/linux-tegra/patch/[email protected]/

BR,
Dejin

Quoted 5 lines
Signature · 3 lines
-- 
With Best Regards,
Andy Shevchenko