Skip to content

Commit c69ff68

Browse files
diogoivogregkh
authored andcommitted
usb: phy: Initialize struct usb_phy list_head
As part of the registration of a new 'struct usb_phy' with the USB PHY core via either usb_add_phy(struct usb_phy *x, ...) or usb_add_phy_dev(struct usb_phy *x) these functions call list_add_tail(&x->head, phy_list) in order for the new instance x to be stored in phy_list, a static list kept internally by the core. After 7d21114 ("usb: phy: Introduce one extcon device into usb phy") when executing either of the registration functions above it is possible that usb_add_extcon() fails, leading to either function returning before the call to list_add_tail(), leaving x->head uninitialized. Then, when a driver tries to undo the failed registration by calling usb_remove_phy(struct usb_phy *x) there will be an unconditional call to list_del(&x->head) acting on an uninitialized variable, and thus a possible NULL pointer dereference. Fix this by initializing x->head before usb_add_extcon() has a chance to fail. Note that this was not needed before 7d21114 since list_add_phy() was executed unconditionally and it guaranteed that x->head was initialized. Fixes: 7d21114 ("usb: phy: Introduce one extcon device into usb phy") Cc: stable <stable@kernel.org> Signed-off-by: Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt> Link: https://patch.msgid.link/20251121-diogo-smaug_typec-v2-1-5c37c1169d57@tecnico.ulisboa.pt Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c77a654 commit c69ff68

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/usb/phy/phy.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type)
646646
return -EINVAL;
647647
}
648648

649+
INIT_LIST_HEAD(&x->head);
650+
649651
usb_charger_init(x);
650652
ret = usb_add_extcon(x);
651653
if (ret)
@@ -696,6 +698,8 @@ int usb_add_phy_dev(struct usb_phy *x)
696698
return -EINVAL;
697699
}
698700

701+
INIT_LIST_HEAD(&x->head);
702+
699703
usb_charger_init(x);
700704
ret = usb_add_extcon(x);
701705
if (ret)

0 commit comments

Comments
 (0)