From fe20edf1d3bfa6a03ee5b6e335f9634fdea55dbd Mon Sep 17 00:00:00 2001 From: Yue Wang Date: Wed, 6 Jun 2018 17:05:31 +0800 Subject: [PATCH] usb: fix possible null pointer dereference. PD#167891: usb: fix possible null pointer dereference. Change-Id: I683422ad8c6ff386eec3d0c7ace9310dca1c1fe6 Signed-off-by: Yue Wang --- drivers/amlogic/usb/phy/phy-aml-new-usb3-v2.c | 8 ++++++-- drivers/usb/dwc3/core.c | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/amlogic/usb/phy/phy-aml-new-usb3-v2.c b/drivers/amlogic/usb/phy/phy-aml-new-usb3-v2.c index 8e5648d68de6..c115c75955d1 100644 --- a/drivers/amlogic/usb/phy/phy-aml-new-usb3-v2.c +++ b/drivers/amlogic/usb/phy/phy-aml-new-usb3-v2.c @@ -108,8 +108,12 @@ static void amlogic_new_usb3phy_shutdown(struct usb_phy *x) void aml_new_usb_v2_init(void) { union usb_r5_v2 r5 = {.d32 = 0}; - unsigned long reg_addr = (unsigned long) - g_phy_v2->usb2_phy_cfg; + unsigned long reg_addr; + + if (!g_phy_v2) + return; + + reg_addr = (unsigned long)g_phy_v2->usb2_phy_cfg; r5.d32 = readl(usb_new_aml_regs_v2.usb_r_v2[5]); if (r5.b.iddig_curr == 0) { diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index f16e81872473..7a8c51c55992 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -938,10 +938,11 @@ static int dwc3_core_get_phy(struct dwc3 *dwc) } #ifdef CONFIG_AMLOGIC_USB - if (dwc->usb3_phy->flags == AML_USB3_PHY_ENABLE) - dwc->super_speed_support = 1; - else - dwc->super_speed_support = 0; + dwc->super_speed_support = 0; + + if (dwc->usb3_phy) + if (dwc->usb3_phy->flags == AML_USB3_PHY_ENABLE) + dwc->super_speed_support = 1; #endif dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");