linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: <Claudiu.Beznea@microchip.com>
To: <Nicolas.Ferre@microchip.com>, <alexandre.belloni@bootlin.com>,
	<linux@armlinux.org.uk>
Cc: <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ARM: at91: pm: fix imbalanced reference counter for ethernet devices
Date: Wed, 24 May 2023 08:49:34 +0000	[thread overview]
Message-ID: <2d493c1c-15eb-9895-8310-41155696582b@microchip.com> (raw)
In-Reply-To: <20230518062511.2988500-1-claudiu.beznea@microchip.com>

On 18.05.2023 09:25, Claudiu Beznea wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> The of_find_device_by_node() function is returning a struct platform_device
> object with the embedded struct device member's reference counter
> incremented. This needs to be dropped when done with the platform device
> returned by of_find_device_by_node().
> 
> at91_pm_eth_quirk_is_valid() calls of_find_device_by_node() on
> suspend and resume path. On suspend it calls of_find_device_by_node() and
> on resume and failure paths it drops the counter of
> struct platform_device::dev.
> 
> In case ethernet device may not wakeup there is a put_device() on
> at91_pm_eth_quirk_is_valid() which is wrong as it colides with
> put_device() on resume path leading to the reference counter of struct
> device embedded in struct platform_device to be messed, the following
> stack trace to be displayed (after 5 consecutive suspend/resume cycles)
> and the execution to hang:
> 

[ ... ]

> 
> Along with this the error path of at91_pm_config_quirks() had been also
> adapted to decrement propertly the reference counter of struct device
> embedded in struct platform_device.
> 
> Fixes: b7fc72c63399 ("ARM: at91: pm: add quirks for pm")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>

Applied to at91-fixes (after removing useless stack traces in commit
message), thanks!

> ---
>  arch/arm/mach-at91/pm.c | 20 +++++++++-----------
>  1 file changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
> index 60dc56d8acfb..437dd0352fd4 100644
> --- a/arch/arm/mach-at91/pm.c
> +++ b/arch/arm/mach-at91/pm.c
> @@ -334,16 +334,14 @@ static bool at91_pm_eth_quirk_is_valid(struct at91_pm_quirk_eth *eth)
>                 pdev = of_find_device_by_node(eth->np);
>                 if (!pdev)
>                         return false;
> +               /* put_device(eth->dev) is called at the end of suspend. */
>                 eth->dev = &pdev->dev;
>         }
> 
>         /* No quirks if device isn't a wakeup source. */
> -       if (!device_may_wakeup(eth->dev)) {
> -               put_device(eth->dev);
> +       if (!device_may_wakeup(eth->dev))
>                 return false;
> -       }
> 
> -       /* put_device(eth->dev) is called at the end of suspend. */
>         return true;
>  }
> 
> @@ -439,14 +437,14 @@ static int at91_pm_config_quirks(bool suspend)
>                                 pr_err("AT91: PM: failed to enable %s clocks\n",
>                                        j == AT91_PM_G_ETH ? "geth" : "eth");
>                         }
> -               } else {
> -                       /*
> -                        * Release the reference to eth->dev taken in
> -                        * at91_pm_eth_quirk_is_valid().
> -                        */
> -                       put_device(eth->dev);
> -                       eth->dev = NULL;
>                 }
> +
> +               /*
> +                * Release the reference to eth->dev taken in
> +                * at91_pm_eth_quirk_is_valid().
> +                */
> +               put_device(eth->dev);
> +               eth->dev = NULL;
>         }
> 
>         return ret;
> --
> 2.34.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      parent reply	other threads:[~2023-05-24  8:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18  6:25 [PATCH] ARM: at91: pm: fix imbalanced reference counter for ethernet devices Claudiu Beznea
2023-05-22  9:07 ` Nicolas Ferre
2023-05-22  9:11 ` Russell King (Oracle)
2023-05-24  8:49 ` Claudiu.Beznea [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2d493c1c-15eb-9895-8310-41155696582b@microchip.com \
    --to=claudiu.beznea@microchip.com \
    --cc=Nicolas.Ferre@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).