* [PATCH RFC] usb: gadget: Set self-powered based on MaxPower and bmAttributes
@ 2025-02-04 10:59 Prashanth K
2025-02-14 8:02 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Prashanth K @ 2025-02-04 10:59 UTC (permalink / raw)
To: Greg Kroah-Hartman, Thinh Nguyen, Peter Korsgaard,
Sabyrzhan Tasbolatov
Cc: linux-usb, linux-kernel, Prashanth K, stable
Currently the USB gadget will be set as bus-powered based solely
on whether its bMaxPower is greater than 100mA, but this may miss
devices that may legitimately draw less than 100mA but still want
to report as bus-powered. Similarly during suspend & resume, USB
gadget is incorrectly marked as bus/self powered without checking
the bmAttributes field. Fix these by configuring the USB gadget
as self or bus powered based on bmAttributes, and explicitly set
it as bus-powered if it draws more than 100mA.
Cc: stable@vger.kernel.org
Fixes: 5e5caf4fa8d3 ("usb: gadget: composite: Inform controller driver of self-powered")
Signed-off-by: Prashanth K <prashanth.k@oss.qualcomm.com>
---
drivers/usb/gadget/composite.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index bdda8c74602d..1fb28bbf6c45 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1050,10 +1050,11 @@ static int set_config(struct usb_composite_dev *cdev,
else
usb_gadget_set_remote_wakeup(gadget, 0);
done:
- if (power <= USB_SELF_POWER_VBUS_MAX_DRAW)
- usb_gadget_set_selfpowered(gadget);
- else
+ if (power > USB_SELF_POWER_VBUS_MAX_DRAW ||
+ !(c->bmAttributes & USB_CONFIG_ATT_SELFPOWER))
usb_gadget_clear_selfpowered(gadget);
+ else
+ usb_gadget_set_selfpowered(gadget);
usb_gadget_vbus_draw(gadget, power);
if (result >= 0 && cdev->delayed_status)
@@ -2615,7 +2616,9 @@ void composite_suspend(struct usb_gadget *gadget)
cdev->suspended = 1;
- usb_gadget_set_selfpowered(gadget);
+ if (cdev->config->bmAttributes & USB_CONFIG_ATT_SELFPOWER)
+ usb_gadget_set_selfpowered(gadget);
+
usb_gadget_vbus_draw(gadget, 2);
}
@@ -2649,8 +2652,11 @@ void composite_resume(struct usb_gadget *gadget)
else
maxpower = min(maxpower, 900U);
- if (maxpower > USB_SELF_POWER_VBUS_MAX_DRAW)
+ if (maxpower > USB_SELF_POWER_VBUS_MAX_DRAW ||
+ !(cdev->config->bmAttributes & USB_CONFIG_ATT_SELFPOWER))
usb_gadget_clear_selfpowered(gadget);
+ else
+ usb_gadget_set_selfpowered(gadget);
usb_gadget_vbus_draw(gadget, maxpower);
} else {
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH RFC] usb: gadget: Set self-powered based on MaxPower and bmAttributes
2025-02-04 10:59 [PATCH RFC] usb: gadget: Set self-powered based on MaxPower and bmAttributes Prashanth K
@ 2025-02-14 8:02 ` Greg Kroah-Hartman
2025-02-14 8:56 ` Prashanth K
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2025-02-14 8:02 UTC (permalink / raw)
To: Prashanth K
Cc: Thinh Nguyen, Peter Korsgaard, Sabyrzhan Tasbolatov, linux-usb,
linux-kernel, stable
On Tue, Feb 04, 2025 at 04:29:08PM +0530, Prashanth K wrote:
> Currently the USB gadget will be set as bus-powered based solely
> on whether its bMaxPower is greater than 100mA, but this may miss
> devices that may legitimately draw less than 100mA but still want
> to report as bus-powered. Similarly during suspend & resume, USB
> gadget is incorrectly marked as bus/self powered without checking
> the bmAttributes field. Fix these by configuring the USB gadget
> as self or bus powered based on bmAttributes, and explicitly set
> it as bus-powered if it draws more than 100mA.
>
> Cc: stable@vger.kernel.org
> Fixes: 5e5caf4fa8d3 ("usb: gadget: composite: Inform controller driver of self-powered")
> Signed-off-by: Prashanth K <prashanth.k@oss.qualcomm.com>
> ---
> drivers/usb/gadget/composite.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
What type of "comments" are you wanting here?
For obvious reasons, I can't apply patches tagged "RFC" but I don't see
what you are wanting us to do here.
confused,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH RFC] usb: gadget: Set self-powered based on MaxPower and bmAttributes
2025-02-14 8:02 ` Greg Kroah-Hartman
@ 2025-02-14 8:56 ` Prashanth K
0 siblings, 0 replies; 3+ messages in thread
From: Prashanth K @ 2025-02-14 8:56 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Thinh Nguyen, Peter Korsgaard, Sabyrzhan Tasbolatov, linux-usb,
linux-kernel, stable
On 14-02-25 01:32 pm, Greg Kroah-Hartman wrote:
> On Tue, Feb 04, 2025 at 04:29:08PM +0530, Prashanth K wrote:
>> Currently the USB gadget will be set as bus-powered based solely
>> on whether its bMaxPower is greater than 100mA, but this may miss
>> devices that may legitimately draw less than 100mA but still want
>> to report as bus-powered. Similarly during suspend & resume, USB
>> gadget is incorrectly marked as bus/self powered without checking
>> the bmAttributes field. Fix these by configuring the USB gadget
>> as self or bus powered based on bmAttributes, and explicitly set
>> it as bus-powered if it draws more than 100mA.
>>
>> Cc: stable@vger.kernel.org
>> Fixes: 5e5caf4fa8d3 ("usb: gadget: composite: Inform controller driver of self-powered")
>> Signed-off-by: Prashanth K <prashanth.k@oss.qualcomm.com>
>> ---
>> drivers/usb/gadget/composite.c | 16 +++++++++++-----
>> 1 file changed, 11 insertions(+), 5 deletions(-)
>
> What type of "comments" are you wanting here?
>
> For obvious reasons, I can't apply patches tagged "RFC" but I don't see
> what you are wanting us to do here.
>
> confused,
>
> greg k-h
Sent an RFC since I got some comments last time while changing few
things on this path, was expecting the same thing this time, Will send a v2.
Thanks,
Prashanth K
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-14 8:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-04 10:59 [PATCH RFC] usb: gadget: Set self-powered based on MaxPower and bmAttributes Prashanth K
2025-02-14 8:02 ` Greg Kroah-Hartman
2025-02-14 8:56 ` Prashanth K
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox