From: Thierry Reding <thierry.reding@gmail.com>
To: Jon Hunter <jonathanh@nvidia.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Nagarjuna Kristam <nkristam@nvidia.com>,
linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: Re: [PATCH 1/2] usb: gadget: tegra-xudc: Fix crash in vbus_draw
Date: Thu, 6 Apr 2023 10:05:40 +0200 [thread overview]
Message-ID: <ZC59VDIEYzbR1YKF@orome> (raw)
In-Reply-To: <20230405181854.42355-1-jonathanh@nvidia.com>
[-- Attachment #1: Type: text/plain, Size: 1734 bytes --]
On Wed, Apr 05, 2023 at 07:18:53PM +0100, Jon Hunter wrote:
> Commit ac82b56bda5f ("usb: gadget: tegra-xudc: Add vbus_draw support")
> populated the vbus_draw callback for the Tegra XUDC driver. The function
> tegra_xudc_gadget_vbus_draw(), that was added by this commit, assumes
> that the pointer 'curr_usbphy' has been initialised, which is not always
> the case because this is only initialised when the USB role is updated.
> Fix this crash, by checking that the 'curr_usbphy' is valid before
> dereferencing.
>
> Fixes: ac82b56bda5f ("usb: gadget: tegra-xudc: Add vbus_draw support")
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> ---
> drivers/usb/gadget/udc/tegra-xudc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c
> index 2b71b33725f1..5bccd64847ff 100644
> --- a/drivers/usb/gadget/udc/tegra-xudc.c
> +++ b/drivers/usb/gadget/udc/tegra-xudc.c
> @@ -2167,7 +2167,7 @@ static int tegra_xudc_gadget_vbus_draw(struct usb_gadget *gadget,
>
> dev_dbg(xudc->dev, "%s: %u mA\n", __func__, m_a);
>
> - if (xudc->curr_usbphy->chg_type == SDP_TYPE)
> + if (xudc->curr_usbphy && xudc->curr_usbphy->chg_type == SDP_TYPE)
> ret = usb_phy_set_power(xudc->curr_usbphy, m_a);
>
> return ret;
Looking at tegra_xudc_probe(), that calls tegra_xudc_update_data_role()
for all PHYs, so shouldn't that be enough to get curr_usbphy set? Or is
there perhaps a race between ->vbus_draw() and the data role update? Is
->vbus_draw() perhaps called as part of usb_add_gadget_udc()? Should we
reorder those to make sure the role is properly updated before the
gadget is registered?
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-04-06 8:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 18:18 [PATCH 1/2] usb: gadget: tegra-xudc: Fix crash in vbus_draw Jon Hunter
2023-04-05 18:18 ` [PATCH 2/2] usb: gadget: tegra-xudc: Remove unneeded return variable Jon Hunter
2023-04-06 8:06 ` Thierry Reding
2023-04-06 8:05 ` Thierry Reding [this message]
2023-04-06 9:35 ` [PATCH 1/2] usb: gadget: tegra-xudc: Fix crash in vbus_draw Jon Hunter
2023-04-06 12:00 ` Thierry Reding
2023-04-19 21:53 ` Jon Hunter
2023-04-20 6:43 ` Greg Kroah-Hartman
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=ZC59VDIEYzbR1YKF@orome \
--to=thierry.reding@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jonathanh@nvidia.com \
--cc=linux-tegra@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkristam@nvidia.com \
/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;
as well as URLs for NNTP newsgroup(s).