Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] phy: mapphone-mdm6600: cancel delayed work on probe error
@ 2026-12-01  4:19 Cong Nguyen
  2026-12-01  4:27 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Cong Nguyen @ 2026-12-01  4:19 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Neil Armstrong, Manivannan Sadhasivam, Tony Lindgren, linux-phy,
	linux-kernel

phy_mdm6600_probe() queues bootup_work before it can fail, and the
status IRQ and runtime resume queue status_work and modem_wake_work.
If a later step fails, nothing cancels them, and they can run after the
devres-managed ddata is freed.

Use devm_delayed_work_autocancel() for the three works. It is set up
before the devm IRQs, so devres frees the IRQs first and cancels the
works after, and the IRQ handlers cannot queue them again.

Fixes: 2ad2af081622 ("phy: mapphone-mdm6600: Improve phy related runtime PM calls")
Signed-off-by: Cong Nguyen <congnt264@gmail.com>
---
Changes in v2:
- Use devm_delayed_work_autocancel() instead of cancelling by hand in the
  probe error path. The devm IRQs can still queue status_work after a
  manual cancel (Sashiko review of v1).

 drivers/phy/motorola/phy-mapphone-mdm6600.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/motorola/phy-mapphone-mdm6600.c b/drivers/phy/motorola/phy-mapphone-mdm6600.c
index ff364a990187..cbe05f8984e8 100644
--- a/drivers/phy/motorola/phy-mapphone-mdm6600.c
+++ b/drivers/phy/motorola/phy-mapphone-mdm6600.c
@@ -5,6 +5,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/devm-helpers.h>
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/interrupt.h>
@@ -561,10 +562,21 @@ static int phy_mdm6600_probe(struct platform_device *pdev)
 	if (!ddata)
 		return -ENOMEM;
 
-	INIT_DELAYED_WORK(&ddata->bootup_work,
-			  phy_mdm6600_deferred_power_on);
-	INIT_DELAYED_WORK(&ddata->status_work, phy_mdm6600_status);
-	INIT_DELAYED_WORK(&ddata->modem_wake_work, phy_mdm6600_modem_wake);
+	error = devm_delayed_work_autocancel(&pdev->dev, &ddata->bootup_work,
+					     phy_mdm6600_deferred_power_on);
+	if (error)
+		return error;
+
+	error = devm_delayed_work_autocancel(&pdev->dev, &ddata->status_work,
+					     phy_mdm6600_status);
+	if (error)
+		return error;
+
+	error = devm_delayed_work_autocancel(&pdev->dev, &ddata->modem_wake_work,
+					     phy_mdm6600_modem_wake);
+	if (error)
+		return error;
+
 	init_completion(&ddata->ack);
 
 	ddata->dev = &pdev->dev;
-- 
2.25.1


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* Re: [PATCH v2] phy: mapphone-mdm6600: cancel delayed work on probe error
  2026-12-01  4:19 [PATCH v2] phy: mapphone-mdm6600: cancel delayed work on probe error Cong Nguyen
@ 2026-12-01  4:27 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-01  4:27 UTC (permalink / raw)
  To: Cong Nguyen; +Cc: linux-phy, vkoul, neil.armstrong, olteanv

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] phy: mapphone-mdm6600: devres frees GPIOs before work in
  phy_mdm6600_probe()
- [Medium] phy: mapphone-mdm6600: active works race with cleanup in
  phy_mdm6600_probe()
--

commit a68cd22ccc36153088e80fdbbebadb7dc12964d6
Author: Cong Nguyen <congnt264@gmail.com>

phy: mapphone-mdm6600: cancel delayed work on probe error

This commit switches bootup_work, status_work, and modem_wake_work in
phy_mdm6600_probe() to devm_delayed_work_autocancel() so they are cancelled
when probe fails or the device is removed.

> diff --git a/drivers/phy/motorola/phy-mapphone-mdm6600.c b/drivers/phy/motorola/phy-mapphone-mdm6600.c
> index fd0e0cd1c1cfb..204b282d48560 100644
> --- a/drivers/phy/motorola/phy-mapphone-mdm6600.c
> +++ b/drivers/phy/motorola/phy-mapphone-mdm6600.c

[ ... ]

> @@ -561,10 +562,21 @@ static int phy_mdm6600_probe(struct platform_device *pdev)
>  	if (!ddata)
>  		return -ENOMEM;
>  
> -	INIT_DELAYED_WORK(&ddata->bootup_work,
> -			  phy_mdm6600_deferred_power_on);
> -	INIT_DELAYED_WORK(&ddata->status_work, phy_mdm6600_status);
> -	INIT_DELAYED_WORK(&ddata->modem_wake_work, phy_mdm6600_modem_wake);
> +	error = devm_delayed_work_autocancel(&pdev->dev, &ddata->bootup_work,
> +					     phy_mdm6600_deferred_power_on);
> +	if (error)
> +		return error;
> +
> +	error = devm_delayed_work_autocancel(&pdev->dev, &ddata->status_work,
> +					     phy_mdm6600_status);
> +	if (error)
> +		return error;
> +
> +	error = devm_delayed_work_autocancel(&pdev->dev, &ddata->modem_wake_work,
> +					     phy_mdm6600_modem_wake);
> +	if (error)
> +		return error;
> +
>  	init_completion(&ddata->ack);
>  
>  	ddata->dev = &pdev->dev;

[Severity: Medium]
Does registering devm_delayed_work_autocancel() before
phy_mdm6600_init_lines() cause devres teardown to free the GPIO descriptor
arrays before cancelling the delayed works?

phy_mdm6600_init_lines() allocates ddata->mode_gpios, ddata->status_gpios,
and ddata->cmd_gpios with devm_gpiod_get_array().  Because devres releases
resources in reverse registration order, a failure in devm_phy_create() or
devm_of_phy_provider_register() frees those struct gpio_descs allocations
before devm_delayed_work_drop() cancels the works:

CPU0                              kworker
phy_mdm6600_probe()
  pm_runtime_get_sync()
    ...
      schedule_delayed_work(&ddata->modem_wake_work, ...)
  devm_phy_create() -> fails
  ...
devres_release_all()
  devm_gpiod_release_array()
    gpiod_put_array(ddata->mode_gpios)
      kfree(descs)
                                  phy_mdm6600_modem_wake()
                                    phy_mdm6600_wake_modem()
                                      ddata->mode_gpios->desc[...]
                                        <-- use-after-free
  devm_delayed_work_drop()

Registering devm_delayed_work_autocancel() after phy_mdm6600_init_lines()
and before phy_mdm6600_init_irq() ensures devres frees the status IRQs
first, cancels the works second, and releases the GPIOs last.

[Severity: Medium]
Can bootup_work and modem_wake_work also race with the cleanup path in
phy_mdm6600_probe() before devres_release_all() runs?

bootup_work (phy_mdm6600_device_power_on()) can take up to 12.2 seconds
(4200 ms of sleeps followed by an 8000 ms wait on ddata->ack), while
phy_mdm6600_probe() only sleeps 4500 ms before continuing.  If probe then
fails and jumps to cleanup, devm_delayed_work_autocancel() has not run yet,
so phy_mdm6600_device_power_off() runs concurrently with both bootup_work
(waiting on the same ddata->ack completion and toggling the power/mode
GPIOs) and modem_wake_work (pulsing mode_gpio0 every 600 ms).

Worse, after phy_mdm6600_probe() returns an error, devres_release_all()
drains dev->devres_head into a local list before waiting in
devm_delayed_work_drop() for bootup_work to finish:

CPU0                              kworker (bootup_work)
devres_release_all()
  remove_nodes()
  release_nodes()
    devm_delayed_work_drop()
      cancel_delayed_work_sync()
                                  phy_mdm6600_device_power_on()
                                    wait_for_completion_timeout(&ddata->ack, ...)
                                    devm_request_threaded_irq(..., ddata)
                                      <-- added after remove_nodes()
  devm_kfree(ddata)

Becausephy_mdm6600_device_power_on() proceeds to
devm_request_threaded_irq() even when wait_for_completion_timeout() times
out, the wake IRQ is registered onto dev->devres_head after remove_nodes()
has already drained it, leaving the IRQ active with a dangling ddata
pointer after ddata is freed.  Disabling runtime PM and cancelling
modem_wake_work and bootup_work before phy_mdm6600_device_power_off() in
the error path would avoid both races.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201041928.3163542-1-congnt264@gmail.com?part=1

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

end of thread, other threads:[~2026-12-01  4:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  4:19 [PATCH v2] phy: mapphone-mdm6600: cancel delayed work on probe error Cong Nguyen
2026-12-01  4:27 ` sashiko-bot

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