All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v1] net: macb: fix an issue about leak related system resources
@ 2020-04-25 12:57 Dejin Zheng
  2020-04-27  8:25 ` Yash Shah
  2020-04-27 10:33 ` Andy Shevchenko
  0 siblings, 2 replies; 9+ messages in thread
From: Dejin Zheng @ 2020-04-25 12:57 UTC (permalink / raw)
  To: davem, paul.walmsley, palmer, nicolas.ferre, 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_ioremap() to replace ioremap() for fix it.

Fixes: c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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


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

* RE: [PATCH net v1] net: macb: fix an issue about leak related system resources
  2020-04-25 12:57 [PATCH net v1] net: macb: fix an issue about leak related system resources Dejin Zheng
@ 2020-04-27  8:25 ` Yash Shah
  2020-04-28  3:25   ` Dejin Zheng
  2020-04-27 10:33 ` Andy Shevchenko
  1 sibling, 1 reply; 9+ messages in thread
From: Yash Shah @ 2020-04-27  8:25 UTC (permalink / raw)
  To: Dejin Zheng, davem, Paul Walmsley, palmer, nicolas.ferre, netdev
  Cc: linux-kernel, Andy Shevchenko

> -----Original Message-----
> From: Dejin Zheng <zhengdejin5@gmail.com>
> Sent: 25 April 2020 18:28
> To: davem@davemloft.net; Paul Walmsley <paul.walmsley@sifive.com>;
> palmer@dabbelt.com; nicolas.ferre@microchip.com; Yash Shah
> <yash.shah@sifive.com>; netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org; Dejin Zheng <zhengdejin5@gmail.com>;
> Andy Shevchenko <andy.shevchenko@gmail.com>
> 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 <andy.shevchenko@gmail.com>
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> ---
>  drivers/net/ethernet/cadence/macb_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb_main.c
> b/drivers/net/ethernet/cadence/macb_main.c
> index a0e8c5bbabc0..edba2eb56231 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -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

The change looks good to me.
Reviewed-by: Yash Shah <yash.shah@sifive.com>

- Yash


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

* Re: [PATCH net v1] net: macb: fix an issue about leak related system resources
  2020-04-25 12:57 [PATCH net v1] net: macb: fix an issue about leak related system resources Dejin Zheng
  2020-04-27  8:25 ` Yash Shah
@ 2020-04-27 10:33 ` Andy Shevchenko
  2020-04-28  3:24   ` Dejin Zheng
  1 sibling, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2020-04-27 10:33 UTC (permalink / raw)
  To: Dejin Zheng
  Cc: David S. Miller, Paul Walmsley, Palmer Dabbelt, Nicolas Ferre,
	yash.shah, netdev, Linux Kernel Mailing List

On Sat, Apr 25, 2020 at 3:57 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
>
> 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()?

> Fixes: c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
> Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> ---
>  drivers/net/ethernet/cadence/macb_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index a0e8c5bbabc0..edba2eb56231 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -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
>


-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH net v1] net: macb: fix an issue about leak related system resources
  2020-04-27 10:33 ` Andy Shevchenko
@ 2020-04-28  3:24   ` Dejin Zheng
  2020-04-28  8:42     ` Nicolas Ferre
  0 siblings, 1 reply; 9+ messages in thread
From: Dejin Zheng @ 2020-04-28  3:24 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: David S. Miller, Paul Walmsley, Palmer Dabbelt, Nicolas Ferre,
	yash.shah, netdev, Linux Kernel Mailing List

On Mon, Apr 27, 2020 at 01:33:41PM +0300, Andy Shevchenko wrote:
> On Sat, Apr 25, 2020 at 3:57 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> >
> > 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.

> > Fixes: c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
> > Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
> > Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> > ---
> >  drivers/net/ethernet/cadence/macb_main.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> > index a0e8c5bbabc0..edba2eb56231 100644
> > --- a/drivers/net/ethernet/cadence/macb_main.c
> > +++ b/drivers/net/ethernet/cadence/macb_main.c
> > @@ -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
> >
> 
> 
> -- 
> With Best Regards,
> Andy Shevchenko

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

* Re: [PATCH net v1] net: macb: fix an issue about leak related system resources
  2020-04-27  8:25 ` Yash Shah
@ 2020-04-28  3:25   ` Dejin Zheng
  0 siblings, 0 replies; 9+ messages in thread
From: Dejin Zheng @ 2020-04-28  3:25 UTC (permalink / raw)
  To: Yash Shah
  Cc: davem, Paul Walmsley, palmer, nicolas.ferre, netdev,
	linux-kernel, Andy Shevchenko

On Mon, Apr 27, 2020 at 08:25:41AM +0000, Yash Shah wrote:
> > -----Original Message-----
> > From: Dejin Zheng <zhengdejin5@gmail.com>
> > Sent: 25 April 2020 18:28
> > To: davem@davemloft.net; Paul Walmsley <paul.walmsley@sifive.com>;
> > palmer@dabbelt.com; nicolas.ferre@microchip.com; Yash Shah
> > <yash.shah@sifive.com>; netdev@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org; Dejin Zheng <zhengdejin5@gmail.com>;
> > Andy Shevchenko <andy.shevchenko@gmail.com>
> > 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 <andy.shevchenko@gmail.com>
> > Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> > ---
> >  drivers/net/ethernet/cadence/macb_main.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/cadence/macb_main.c
> > b/drivers/net/ethernet/cadence/macb_main.c
> > index a0e8c5bbabc0..edba2eb56231 100644
> > --- a/drivers/net/ethernet/cadence/macb_main.c
> > +++ b/drivers/net/ethernet/cadence/macb_main.c
> > @@ -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
> 
> The change looks good to me.
> Reviewed-by: Yash Shah <yash.shah@sifive.com>
>
Thanks Yash!

> - Yash
> 

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

* Re: [PATCH net v1] net: macb: fix an issue about leak related system resources
  2020-04-28  3:24   ` Dejin Zheng
@ 2020-04-28  8:42     ` Nicolas Ferre
  2020-04-28 13:11       ` Dejin Zheng
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Ferre @ 2020-04-28  8:42 UTC (permalink / raw)
  To: Dejin Zheng, Andy Shevchenko
  Cc: David S. Miller, Paul Walmsley, Palmer Dabbelt, yash.shah,
	netdev, Linux Kernel Mailing List, Claudiu Beznea

On 28/04/2020 at 05:24, Dejin Zheng wrote:
> On Mon, Apr 27, 2020 at 01:33:41PM +0300, Andy Shevchenko wrote:
>> On Sat, Apr 25, 2020 at 3:57 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
>>>
>>> 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.

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

Regards,
   Nicolas

>>> Fixes: c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
>>> Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
>>> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
>>> ---
>>>   drivers/net/ethernet/cadence/macb_main.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
>>> index a0e8c5bbabc0..edba2eb56231 100644
>>> --- a/drivers/net/ethernet/cadence/macb_main.c
>>> +++ b/drivers/net/ethernet/cadence/macb_main.c
>>> @@ -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;
>>>


-- 
Nicolas Ferre

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

* Re: [PATCH net v1] net: macb: fix an issue about leak related system resources
  2020-04-28  8:42     ` Nicolas Ferre
@ 2020-04-28 13:11       ` Dejin Zheng
  2020-04-28 14:04         ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Dejin Zheng @ 2020-04-28 13:11 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: Andy Shevchenko, David S. Miller, Paul Walmsley, Palmer Dabbelt,
	yash.shah, netdev, Linux Kernel Mailing List, Claudiu Beznea

On Tue, Apr 28, 2020 at 10:42:56AM +0200, Nicolas Ferre wrote:
> On 28/04/2020 at 05:24, Dejin Zheng wrote:
> > On Mon, Apr 27, 2020 at 01:33:41PM +0300, Andy Shevchenko wrote:
> > > On Sat, Apr 25, 2020 at 3:57 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> > > > 
> > > > 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.
> 
> 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

> Regards,
>   Nicolas
> 
> > > > Fixes: c218ad559020ff9 ("macb: Add support for SiFive FU540-C000")
> > > > Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
> > > > Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> > > > ---
> > > >   drivers/net/ethernet/cadence/macb_main.c | 2 +-
> > > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> > > > index a0e8c5bbabc0..edba2eb56231 100644
> > > > --- a/drivers/net/ethernet/cadence/macb_main.c
> > > > +++ b/drivers/net/ethernet/cadence/macb_main.c
> > > > @@ -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;
> > > > 
> 
> 
> -- 
> Nicolas Ferre

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

* Re: [PATCH net v1] net: macb: fix an issue about leak related system resources
  2020-04-28 13:11       ` Dejin Zheng
@ 2020-04-28 14:04         ` Andy Shevchenko
  2020-04-28 14:52           ` Dejin Zheng
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2020-04-28 14:04 UTC (permalink / raw)
  To: Dejin Zheng
  Cc: Nicolas Ferre, David S. Miller, Paul Walmsley, Palmer Dabbelt,
	yash.shah, netdev, Linux Kernel Mailing List, Claudiu Beznea

On Tue, Apr 28, 2020 at 4:12 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> On Tue, Apr 28, 2020 at 10:42:56AM +0200, Nicolas Ferre wrote:
> > On 28/04/2020 at 05:24, Dejin Zheng wrote:
> > > On Mon, Apr 27, 2020 at 01:33:41PM +0300, Andy Shevchenko wrote:
> > > > On Sat, Apr 25, 2020 at 3:57 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> > > > >
> > > > > 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.
> >
> > 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.




-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH net v1] net: macb: fix an issue about leak related system resources
  2020-04-28 14:04         ` Andy Shevchenko
@ 2020-04-28 14:52           ` Dejin Zheng
  0 siblings, 0 replies; 9+ messages in thread
From: Dejin Zheng @ 2020-04-28 14:52 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Nicolas Ferre, David S. Miller, Paul Walmsley, Palmer Dabbelt,
	yash.shah, netdev, Linux Kernel Mailing List, Claudiu Beznea

On Tue, Apr 28, 2020 at 05:04:32PM +0300, Andy Shevchenko wrote:
> On Tue, Apr 28, 2020 at 4:12 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> > On Tue, Apr 28, 2020 at 10:42:56AM +0200, Nicolas Ferre wrote:
> > > On 28/04/2020 at 05:24, Dejin Zheng wrote:
> > > > On Mon, Apr 27, 2020 at 01:33:41PM +0300, Andy Shevchenko wrote:
> > > > > On Sat, Apr 25, 2020 at 3:57 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> > > > > >
> > > > > > 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.
> > >
> > > 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.
> 
>
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/20200127135841.17935-1-zhengdejin5@gmail.com/

BR,
Dejin
> 
> 
> -- 
> With Best Regards,
> Andy Shevchenko

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

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

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-25 12:57 [PATCH net v1] net: macb: fix an issue about leak related system resources Dejin Zheng
2020-04-27  8:25 ` Yash Shah
2020-04-28  3:25   ` Dejin Zheng
2020-04-27 10:33 ` Andy Shevchenko
2020-04-28  3:24   ` Dejin Zheng
2020-04-28  8:42     ` Nicolas Ferre
2020-04-28 13:11       ` Dejin Zheng
2020-04-28 14:04         ` Andy Shevchenko
2020-04-28 14:52           ` Dejin Zheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.