Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Cong Nguyen" <congnt264@gmail.com>
Cc: linux-phy@lists.infradead.org, vkoul@kernel.org,
	neil.armstrong@linaro.org, olteanv@gmail.com
Subject: Re: [PATCH v2] phy: mapphone-mdm6600: cancel delayed work on probe error
Date: Tue, 01 Dec 2026 04:27:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-242503@kernel.org> (raw)
In-Reply-To: <20261201041928.3163542-1-congnt264@gmail.com>

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

      reply	other threads:[~2026-12-01  4:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 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=sashiko-outbox-242503@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=congnt264@gmail.com \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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