net: macb: fix an issue about leak related system resources
Subsystems (3)
PATCH v2 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_platform_ioremap_resource() to replace ioremap() to fix it.
---
v1 -> v2:
- Nicolas and Andy suggest use devm_platform_ioremap_resource() to repalce devm_ioremap() to fix this issue. Thanks Nicolas and Andy.
- Yash help me to review this patch, Thanks Yash!
drivers/net/ethernet/cadence/macb_main.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +1 -7
@@ -4172,13 +4172,7 @@ static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk,static int fu540_c000_init (struct platform_device *pdev) { -struct resource *res; - - res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); -if (!res) -return -ENODEV ; - - mgmt->reg =ioremap (res->start,resource_size (res)); + mgmt->reg =devm_platform_ioremap_resource (pdev,1 );if (!mgmt->reg)return -ENOMEM ;
Signature · 1 line
2.25.0
Quoted 28 lines · Dejin Zheng
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
A call of the function
macb_init()can fail in the functionfu540_c000_init. The related system resources were not released then. usedevm_platform_ioremap_resource()to replaceioremap()to fix it.Fixes c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")Cc Andy Shevchenko <[email protected]>Reviewed-by Yash Shah <[email protected]>Signed-off-by Dejin Zheng <[email protected]>---
v1 -> v2:
- Nicolas and Andy suggest usedevm_platform_ioremap_resource()to repalcedevm_ioremap()to fix this issue. Thanks Nicolas and Andy.
- Yash help me to review this patch, Thanks Yash!drivers/net/ethernet/cadence/macb_main.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)drivers/net/ethernet/cadence/macb_main.c +0
-0@@ -4172,13 +4172,7 @@ static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk,static int fu540_c000_init (struct platform_device *pdev)
drivers/net/ethernet/cadence/macb_main.c static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk, · line 4176
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +1
-7{ -struct resource *res; - - res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); -if (!res) -return -ENODEV ; - - mgmt->reg =ioremap (res->start,resource_size (res)); + mgmt->reg =devm_platform_ioremap_resource (pdev,1 );if (!mgmt->reg)
Is your test valid then?
Please use:
if (IS_ERR(base))
return PTR_ERR(base);
As advised by:lib/devres.c:156
Regards,
Nicolas
Quoted 5 lines
drivers/net/ethernet/cadence/macb_main.c +0
-1return -ENOMEM ; --2.25.0
Signature · 1 line
Nicolas Ferre
Quoted 28 lines · Nicolas Ferre
Quoted 27 lines · Dejin Zheng
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
A call of the function
macb_init()can fail in the functionfu540_c000_init. The related system resources were not released then. usedevm_platform_ioremap_resource()to replaceioremap()to fix it.Fixes c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")Cc Andy Shevchenko <[email protected]>Reviewed-by Yash Shah <[email protected]>Signed-off-by Dejin Zheng <[email protected]>---
v1 -> v2:
- Nicolas and Andy suggest usedevm_platform_ioremap_resource()to repalcedevm_ioremap()to fix this issue. Thanks Nicolas and Andy.
- Yash help me to review this patch, Thanks Yash!drivers/net/ethernet/cadence/macb_main.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)drivers/net/ethernet/cadence/macb_main.c +0
-0@@ -4172,13 +4172,7 @@ static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk,
Quoted 14 lines
drivers/net/ethernet/cadence/macb_main.c static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk, · line 4176
Quoted 11 lines
drivers/net/ethernet/cadence/macb_main.c +1
-7static int fu540_c000_init (struct platform_device *pdev) { -struct resource *res; - - res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); -if (!res) -return -ENODEV ; - - mgmt->reg =ioremap (res->start,resource_size (res)); + mgmt->reg =devm_platform_ioremap_resource (pdev,1 );if (!mgmt->reg)Is your test valid then?
Hi Nicolas:
I just compiled it successfully and I didn't have the hardware of this driver, so I did not tested it. and this patch only affects the driver of "sifive,fu540-macb", if these IO addresses can be monopolized by this driver, this change should be ok.
Hi Yash:
Do you know that these IO addresses can be occupied by this driver alone? Thank you very much!
BR,
Dejin
Quoted 6 lines
Please use:
if (IS_ERR(base))
returnPTR_ERR(base);
As advised by:lib/devres.c:156
Thanks!, I will sent it in patch v3.
Quoted 12 lines
Regards,
NicolasQuoted 5 lines
drivers/net/ethernet/cadence/macb_main.c +0
-1return -ENOMEM ; --2.25.0
Signature · 1 line
Nicolas Ferre