* [PATCH net] phy: fix error case of phy_led_triggers_(un)register
@ 2016-11-23 21:39 Woojung.Huh
2016-11-23 21:55 ` Sergei Shtylyov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Woojung.Huh @ 2016-11-23 21:39 UTC (permalink / raw)
To: zach.brown, davem, netdev; +Cc: f.fainelli
From: Woojung Huh <woojung.huh@microchip.com>
When phy_init_hw() fails at phy_attach_direct();
- phy_detach() calls phy_led_triggers_unregister() without
previous call of phy_led_triggers_register().
- still call phy_led_triggers_register() and cause memory leak.
Signed-off-by: Woojung Huh <woojung.huh@microchip.com>
---
drivers/net/phy/phy_device.c | 6 +++---
drivers/net/phy/phy_led_triggers.c | 3 +++
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 9e8f048..094a959 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -915,10 +915,10 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
err = phy_init_hw(phydev);
if (err)
phy_detach(phydev);
- else
+ else {
phy_resume(phydev);
-
- phy_led_triggers_register(phydev);
+ phy_led_triggers_register(phydev);
+ }
return err;
diff --git a/drivers/net/phy/phy_led_triggers.c b/drivers/net/phy/phy_led_triggers.c
index cda600a..3b0b726 100644
--- a/drivers/net/phy/phy_led_triggers.c
+++ b/drivers/net/phy/phy_led_triggers.c
@@ -128,6 +128,9 @@ void phy_led_triggers_unregister(struct phy_device *phy)
{
int i;
+ if (!phy->phy_num_led_triggers)
+ return;
+
for (i = 0; i < phy->phy_num_led_triggers; i++)
phy_led_trigger_unregister(&phy->phy_led_triggers[i]);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net] phy: fix error case of phy_led_triggers_(un)register
2016-11-23 21:39 [PATCH net] phy: fix error case of phy_led_triggers_(un)register Woojung.Huh
@ 2016-11-23 21:55 ` Sergei Shtylyov
2016-11-23 22:15 ` Andrew Lunn
2016-11-23 23:02 ` Florian Fainelli
2 siblings, 0 replies; 4+ messages in thread
From: Sergei Shtylyov @ 2016-11-23 21:55 UTC (permalink / raw)
To: Woojung.Huh, zach.brown, davem, netdev; +Cc: f.fainelli
Hello.
On 11/24/2016 12:39 AM, Woojung.Huh@microchip.com wrote:
> From: Woojung Huh <woojung.huh@microchip.com>
>
> When phy_init_hw() fails at phy_attach_direct();
> - phy_detach() calls phy_led_triggers_unregister() without
> previous call of phy_led_triggers_register().
> - still call phy_led_triggers_register() and cause memory leak.
>
> Signed-off-by: Woojung Huh <woojung.huh@microchip.com>
> ---
> drivers/net/phy/phy_device.c | 6 +++---
> drivers/net/phy/phy_led_triggers.c | 3 +++
> 2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 9e8f048..094a959 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -915,10 +915,10 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
> err = phy_init_hw(phydev);
> if (err)
> phy_detach(phydev);
> - else
> + else {
CodingStyle: all *if* branches should have {} if at least one has {}.
> phy_resume(phydev);
> -
> - phy_led_triggers_register(phydev);
> + phy_led_triggers_register(phydev);
> + }
>
> return err;
>
[...]
MBR, Sergei
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] phy: fix error case of phy_led_triggers_(un)register
2016-11-23 21:39 [PATCH net] phy: fix error case of phy_led_triggers_(un)register Woojung.Huh
2016-11-23 21:55 ` Sergei Shtylyov
@ 2016-11-23 22:15 ` Andrew Lunn
2016-11-23 23:02 ` Florian Fainelli
2 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2016-11-23 22:15 UTC (permalink / raw)
To: Woojung.Huh; +Cc: zach.brown, davem, netdev, f.fainelli
On Wed, Nov 23, 2016 at 09:39:37PM +0000, Woojung.Huh@microchip.com wrote:
> From: Woojung Huh <woojung.huh@microchip.com>
>
> When phy_init_hw() fails at phy_attach_direct();
> - phy_detach() calls phy_led_triggers_unregister() without
> previous call of phy_led_triggers_register().
> - still call phy_led_triggers_register() and cause memory leak.
>
> Signed-off-by: Woojung Huh <woojung.huh@microchip.com>
> ---
> drivers/net/phy/phy_device.c | 6 +++---
> drivers/net/phy/phy_led_triggers.c | 3 +++
> 2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 9e8f048..094a959 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -915,10 +915,10 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
> err = phy_init_hw(phydev);
> if (err)
> phy_detach(phydev);
> - else
> + else {
> phy_resume(phydev);
> -
> - phy_led_triggers_register(phydev);
> + phy_led_triggers_register(phydev);
> + }
Hi Woojung
The code layout is rather unusual, putting the success case inside the
else {}. It would be better to do a goto out: on error, and detach the
phy there.
>
> return err;
>
> diff --git a/drivers/net/phy/phy_led_triggers.c b/drivers/net/phy/phy_led_triggers.c
> index cda600a..3b0b726 100644
> --- a/drivers/net/phy/phy_led_triggers.c
> +++ b/drivers/net/phy/phy_led_triggers.c
> @@ -128,6 +128,9 @@ void phy_led_triggers_unregister(struct phy_device *phy)
> {
> int i;
>
> + if (!phy->phy_num_led_triggers)
> + return;
> +
> for (i = 0; i < phy->phy_num_led_triggers; i++)
> phy_led_trigger_unregister(&phy->phy_led_triggers[i]);
And this seems to be the wrong fix. The point of devm_kzalloc() is
that you don't need to free it, it will happen automatically. So why
not just remove the devm_kfree(&phy->mdio.dev, phy->phy_led_triggers).
Andrew
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] phy: fix error case of phy_led_triggers_(un)register
2016-11-23 21:39 [PATCH net] phy: fix error case of phy_led_triggers_(un)register Woojung.Huh
2016-11-23 21:55 ` Sergei Shtylyov
2016-11-23 22:15 ` Andrew Lunn
@ 2016-11-23 23:02 ` Florian Fainelli
2 siblings, 0 replies; 4+ messages in thread
From: Florian Fainelli @ 2016-11-23 23:02 UTC (permalink / raw)
To: Woojung.Huh, zach.brown, davem, netdev
Le 23/11/2016 à 13:39, Woojung.Huh@microchip.com a écrit :
> From: Woojung Huh <woojung.huh@microchip.com>
>
> When phy_init_hw() fails at phy_attach_direct();
> - phy_detach() calls phy_led_triggers_unregister() without
> previous call of phy_led_triggers_register().
> - still call phy_led_triggers_register() and cause memory leak.
>
> Signed-off-by: Woojung Huh <woojung.huh@microchip.com>
Since you probably have to resubmit this, can you also add a Fixes tag:
Fixes: 2e0bc452f472 ("net: phy: leds: add support for led triggers on
phy link state change")
Thanks!
--
Florian
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-11-23 23:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-23 21:39 [PATCH net] phy: fix error case of phy_led_triggers_(un)register Woojung.Huh
2016-11-23 21:55 ` Sergei Shtylyov
2016-11-23 22:15 ` Andrew Lunn
2016-11-23 23:02 ` Florian Fainelli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox