public inbox for linux-tegra@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] usb: gadget: tegra-xudc: Fix crash in vbus_draw
@ 2023-04-05 18:18 Jon Hunter
  2023-04-05 18:18 ` [PATCH 2/2] usb: gadget: tegra-xudc: Remove unneeded return variable Jon Hunter
  2023-04-06  8:05 ` [PATCH 1/2] usb: gadget: tegra-xudc: Fix crash in vbus_draw Thierry Reding
  0 siblings, 2 replies; 8+ messages in thread
From: Jon Hunter @ 2023-04-05 18:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Thierry Reding, Nagarjuna Kristam
  Cc: linux-usb, linux-tegra, Jon Hunter

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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-04-20  6:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 1/2] usb: gadget: tegra-xudc: Fix crash in vbus_draw Thierry Reding
2023-04-06  9:35   ` Jon Hunter
2023-04-06 12:00     ` Thierry Reding
2023-04-19 21:53       ` Jon Hunter
2023-04-20  6:43         ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox