All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hansg@kernel.org>
To: Fan Wu <fanwu01@zju.edu.cn>,
	myungjoo.ham@samsung.com, cw00.choi@samsung.com
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] extcon: lc824206xa: Use devm_work_autocancel() for detect work
Date: Thu, 20 Aug 2026 11:58:06 +0200	[thread overview]
Message-ID: <23e039b9-2c7a-440c-b3dc-3274788d18b2@kernel.org> (raw)
In-Reply-To: <20260805050841.7990-1-fanwu01@zju.edu.cn>

Hi,

On 5-Aug-26 07:08, Fan Wu wrote:
> The detect work is re-armed by the threaded IRQ handler but nothing drains
> it on detach: devm frees the IRQ before kfree(data) without flushing the
> workqueue, so a pending work item can run after data is freed, leading to a
> use-after-free.
> 
> Use devm_work_autocancel() so devm LIFO order frees the IRQ before the work
> is cancelled. Register it after the regulator, extcon and power_supply
> the work callback dereferences, so those are not freed before the cancel
> either.
> 
> This issue was found by an in-house static analysis tool.
> Compile-tested only; runtime testing is appreciated.
> 
> Fixes: 9e1897cb9568 ("extcon: Add LC824206XA microUSB switch driver")
> Cc: stable@vger.kernel.org
> Assisted-by: Codex:gpt-5.6
> Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>

Regards,

Hans



> ---
>  drivers/extcon/extcon-lc824206xa.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/extcon/extcon-lc824206xa.c b/drivers/extcon/extcon-lc824206xa.c
> index 56938748aea8..adcea69ac221 100644
> --- a/drivers/extcon/extcon-lc824206xa.c
> +++ b/drivers/extcon/extcon-lc824206xa.c
> @@ -19,6 +19,7 @@
>  #include <linux/bits.h>
>  #include <linux/delay.h>
>  #include <linux/device.h>
> +#include <linux/devm-helpers.h>
>  #include <linux/extcon-provider.h>
>  #include <linux/i2c.h>
>  #include <linux/interrupt.h>
> @@ -424,7 +425,6 @@ static int lc824206xa_probe(struct i2c_client *client)
>  		return -ENOMEM;
>  
>  	data->client = client;
> -	INIT_WORK(&data->work, lc824206xa_work);
>  	data->cable = EXTCON_NONE;
>  	data->previous_cable = EXTCON_NONE;
>  	data->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN;
> @@ -463,6 +463,11 @@ static int lc824206xa_probe(struct i2c_client *client)
>  	if (IS_ERR(data->psy))
>  		return dev_err_probe(dev, PTR_ERR(data->psy), "registering power supply\n");
>  
> +	/* After all resources lc824206xa_work() derefs; before the IRQ producer. */
> +	ret = devm_work_autocancel(dev, &data->work, lc824206xa_work);
> +	if (ret)
> +		return ret;
> +
>  	ret = devm_request_threaded_irq(dev, client->irq, NULL, lc824206xa_irq,
>  					IRQF_TRIGGER_LOW | IRQF_ONESHOT,
>  					KBUILD_MODNAME, data);


      reply	other threads:[~2026-08-20  9:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  5:08 [PATCH] extcon: lc824206xa: Use devm_work_autocancel() for detect work Fan Wu
2026-08-20  9:58 ` Hans de Goede [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=23e039b9-2c7a-440c-b3dc-3274788d18b2@kernel.org \
    --to=hansg@kernel.org \
    --cc=cw00.choi@samsung.com \
    --cc=fanwu01@zju.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    --cc=stable@vger.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 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.