public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v2] net: macb: fix an issue about leak related system resources
@ 2020-04-29 13:56 Dejin Zheng
  2020-04-29 14:15 ` Nicolas Ferre
  0 siblings, 1 reply; 3+ messages in thread
From: Dejin Zheng @ 2020-04-29 13:56 UTC (permalink / raw)
  To: nicolas.ferre, davem, paul.walmsley, palmer, yash.shah, netdev
  Cc: linux-kernel, Dejin Zheng, Andy Shevchenko

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.

Fixes: c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Yash Shah <yash.shah@sifive.com>
Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
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(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index a0e8c5bbabc0..99354e327d1f 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -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;
 
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v2] net: macb: fix an issue about leak related system resources
  2020-04-29 13:56 [PATCH net v2] net: macb: fix an issue about leak related system resources Dejin Zheng
@ 2020-04-29 14:15 ` Nicolas Ferre
  2020-04-29 14:45   ` Dejin Zheng
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Ferre @ 2020-04-29 14:15 UTC (permalink / raw)
  To: Dejin Zheng, davem, paul.walmsley, palmer, yash.shah, netdev
  Cc: linux-kernel, Andy Shevchenko

On 29/04/2020 at 15:56, Dejin Zheng wrote:
> 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 function
> fu540_c000_init. The related system resources were not released
> then. use devm_platform_ioremap_resource() to replace ioremap()
> to fix it.
> 
> Fixes: c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
> Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
> Reviewed-by: Yash Shah <yash.shah@sifive.com>
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> ---
> 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(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index a0e8c5bbabc0..99354e327d1f 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -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)

Is your test valid then?

Please use:
if (IS_ERR(base))
    return PTR_ERR(base);
As advised by:
lib/devres.c:156

Regards,
   Nicolas

>                  return -ENOMEM;
> 
> --
> 2.25.0
> 


-- 
Nicolas Ferre

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net v2] net: macb: fix an issue about leak related system resources
  2020-04-29 14:15 ` Nicolas Ferre
@ 2020-04-29 14:45   ` Dejin Zheng
  0 siblings, 0 replies; 3+ messages in thread
From: Dejin Zheng @ 2020-04-29 14:45 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: davem, paul.walmsley, palmer, yash.shah, netdev, linux-kernel,
	Andy Shevchenko

On Wed, Apr 29, 2020 at 04:15:56PM +0200, Nicolas Ferre wrote:
> On 29/04/2020 at 15:56, Dejin Zheng wrote:
> > 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 function
> > fu540_c000_init. The related system resources were not released
> > then. use devm_platform_ioremap_resource() to replace ioremap()
> > to fix it.
> > 
> > Fixes: c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
> > Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
> > Reviewed-by: Yash Shah <yash.shah@sifive.com>
> > Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> > ---
> > 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(-)
> > 
> > diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> > index a0e8c5bbabc0..99354e327d1f 100644
> > --- a/drivers/net/ethernet/cadence/macb_main.c
> > +++ b/drivers/net/ethernet/cadence/macb_main.c
> > @@ -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)
> 
> 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

> Please use:
> if (IS_ERR(base))
>    return PTR_ERR(base);
> As advised by:
> lib/devres.c:156
>
Thanks!, I will sent it in patch v3.

> Regards,
>   Nicolas
> 
> >                  return -ENOMEM;
> > 
> > --
> > 2.25.0
> > 
> 
> 
> -- 
> Nicolas Ferre

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-29 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-29 13:56 [PATCH net v2] net: macb: fix an issue about leak related system resources Dejin Zheng
2020-04-29 14:15 ` Nicolas Ferre
2020-04-29 14:45   ` Dejin Zheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox