mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Prashanth K <quic_prashk@quicinc.com>
To: Kees Bakker <kees@ijzerbout.nl>,
	Prashanth K <prashanth.k@oss.qualcomm.com>
Cc: <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Peter Korsgaard <peter@korsgaard.com>,
	Sabyrzhan Tasbolatov <snovitoll@gmail.com>
Subject: Re: [PATCH v2] usb: gadget: Set self-powered based on MaxPower and bmAttributes
Date: Mon, 24 Feb 2025 09:47:02 +0530	[thread overview]
Message-ID: <53f8a9cd-c30c-47fe-b189-c632a093dc66@quicinc.com> (raw)
In-Reply-To: <a882365c-148c-410a-ac67-b7a17dafc501@ijzerbout.nl>



On 22-02-25 12:56 am, Kees Bakker wrote:
> Op 17-02-2025 om 13:03 schreef Prashanth K:
>> 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>
>> ---
>> Changes in v2:
>> - Didn't change anything from RFC.
>> - Link to RFC: https://lore.kernel.org/all/20250204105908.2255686-1-
>> 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))
> Please check this change again. From line 983-884 there is a `goto done`.
> in case `c` is NULL. So, there will be a potential NULL pointer dereference
> with your change.

Yea good catch, sorry for missing the corner case. Ill send another patch.

Regards,
Prashanth K

      reply	other threads:[~2025-02-24  4:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-17 12:03 Prashanth K
2025-02-20 18:09 ` William McVicker
2025-02-20 18:57   ` Greg Kroah-Hartman
2025-02-20 19:31     ` William McVicker
2025-02-21 19:26 ` Kees Bakker
2025-02-24  4:17   ` Prashanth K [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=53f8a9cd-c30c-47fe-b189-c632a093dc66@quicinc.com \
    --to=quic_prashk@quicinc.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kees@ijzerbout.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter@korsgaard.com \
    --cc=prashanth.k@oss.qualcomm.com \
    --cc=snovitoll@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®