Skip to content

Commit 38b1927

Browse files
Colin Ian Kingvinodkoul
authored andcommitted
phy: sun4i-usb: fix dereference of pointer phy0 before it is null checked
Currently pointer phy0 is being dereferenced via the assignment of phy on the call to phy_get_drvdata before phy0 is null checked, this can lead to a null pointer dereference. Fix this by performing the null check on phy0 before the call to phy_get_drvdata. Also replace the phy0 == NULL check with the more usual !phy0 idiom. Addresses-Coverity: ("Dereference before null check") Fixes: e6f32ef ("phy: sun4i-usb: Make sure to disable PHY0 passby for peripheral mode") Signed-off-by: Colin Ian King <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent fdc355a commit 38b1927

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/phy/allwinner/phy-sun4i-usb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,14 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
545545
struct sun4i_usb_phy_data *data =
546546
container_of(work, struct sun4i_usb_phy_data, detect.work);
547547
struct phy *phy0 = data->phys[0].phy;
548-
struct sun4i_usb_phy *phy = phy_get_drvdata(phy0);
548+
struct sun4i_usb_phy *phy;
549549
bool force_session_end, id_notify = false, vbus_notify = false;
550550
int id_det, vbus_det;
551551

552-
if (phy0 == NULL)
552+
if (!phy0)
553553
return;
554554

555+
phy = phy_get_drvdata(phy0);
555556
id_det = sun4i_usb_phy0_get_id_det(data);
556557
vbus_det = sun4i_usb_phy0_get_vbus_det(data);
557558

0 commit comments

Comments
 (0)