[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260204015726.ercycq7uto6ofuhk@synopsys.com>
Date: Wed, 4 Feb 2026 01:57:30 +0000
From: Thinh Nguyen <Thinh.Nguyen@...opsys.com>
To: Prashanth K <prashanth.k@....qualcomm.com>
CC: Thinh Nguyen <Thinh.Nguyen@...opsys.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"linux-usb@...r.kernel.org" <linux-usb@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"stable@...r.kernel.org" <stable@...r.kernel.org>,
Samuel Wu <wusamuel@...gle.com>
Subject: Re: [PATCH v2] usb: dwc3: gadget: Move vbus draw to workqueue context
On Tue, Feb 03, 2026, Prashanth K wrote:
> Currently dwc3_gadget_vbus_draw() can be called from atomic
> context, which in turn invokes power-supply-core APIs. And
> some these PMIC APIs have operations that may sleep, leading
> to kernel panic.
>
> Fix this by moving the vbus_draw into a workqueue context.
>
> Fixes: 66e0ea341a2a ("usb: dwc3: core: Defer the probe until USB power supply ready")
> Cc: stable@...r.kernel.org
> Tested-by: Samuel Wu <wusamuel@...gle.com>
> Signed-off-by: Prashanth K <prashanth.k@....qualcomm.com>
> ---
> Changes in v2:
> - Renamed vbus_draw_to_current limit, and rearranged the new variables.
> - Link to v1: https://urldefense.com/v3/__https://lore.kernel.org/all/20260129111403.3081730-1-prashanth.k@oss.qualcomm.com/__;!!A4F2R9G_pg!bl1yJ9-uG6IeinQxL1i7wcDCS24W96tCBWixv0H3dVzlFqpACS6H8pnWvJGVJ6-kA0Y5MIzs_iL2gHhcEer_m5QRE9yu3o4$
>
> drivers/usb/dwc3/core.c | 19 ++++++++++++++++++-
> drivers/usb/dwc3/core.h | 4 ++++
> drivers/usb/dwc3/gadget.c | 8 +++-----
> 3 files changed, 25 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index f32b67bf73a4..cb5e829aaae8 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -2155,6 +2155,20 @@ static int dwc3_get_num_ports(struct dwc3 *dwc)
> return 0;
> }
>
> +static void dwc3_vbus_draw_work(struct work_struct *work)
> +{
> + struct dwc3 *dwc = container_of(work, struct dwc3, vbus_draw_work);
> + union power_supply_propval val = {0};
> + int ret;
> +
> + val.intval = 1000 * (dwc->current_limit);
> + ret = power_supply_set_property(dwc->usb_psy, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val);
> +
> + if (ret < 0)
> + dev_dbg(dwc->dev, "Error (%d) setting vbus draw (%d mA)\n",
> + ret, dwc->current_limit);
> +}
> +
> static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc)
> {
> struct power_supply *usb_psy;
> @@ -2169,6 +2183,7 @@ static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc)
> if (!usb_psy)
> return ERR_PTR(-EPROBE_DEFER);
>
> + INIT_WORK(&dwc->vbus_draw_work, dwc3_vbus_draw_work);
> return usb_psy;
> }
>
> @@ -2395,8 +2410,10 @@ void dwc3_core_remove(struct dwc3 *dwc)
>
> dwc3_free_event_buffers(dwc);
>
> - if (dwc->usb_psy)
> + if (dwc->usb_psy) {
> + cancel_work_sync(&dwc->vbus_draw_work);
> power_supply_put(dwc->usb_psy);
> + }
> }
> EXPORT_SYMBOL_GPL(dwc3_core_remove);
>
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 08cc6f2b5c23..42cd1667a91b 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1058,6 +1058,8 @@ struct dwc3_glue_ops {
> * @role_switch_default_mode: default operation mode of controller while
> * usb role is USB_ROLE_NONE.
> * @usb_psy: pointer to power supply interface.
> + * @vbus_draw_work: Work used for scheduling vbus_draw_work
This description isn't very helpful. Please update the description here
as note previously:
"Work to set the vbus drawing limit" or the equivalent.
After update, you can add this:
Acked-by: Thinh Nguyen <Thinh.Nguyen@...opsys.com>
Thanks,
Thinh
Powered by blists - more mailing lists