Skip to content

Commit 8f6aa39

Browse files
Xu Yanggregkh
authored andcommitted
usb: chipidea: core: convert ci_role_switch to local variable
When a system contains multiple USB controllers, the global ci_role_switch variable may be overwritten by subsequent driver initialization code. This can cause issues in the following cases: - The 2nd ci_hdrc_probe() sees ci_role_switch.fwnode as non-NULL even though the "usb-role-switch" property is not present for the controller. - When the ci_hdrc device is unbound and bound again, ci_role_switch fwnode will not be reassigned, and the old value will be used instead. Convert ci_role_switch to a local variable to fix these issues. Fixes: 05559f1 ("usb: chipidea: add role switch class support") Cc: stable <stable@kernel.org> Acked-by: Peter Chen <peter.chen@kernel.org> Reviewed-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Xu Yang <xu.yang_2@nxp.com> Link: https://patch.msgid.link/20260427075755.3611217-1-xu.yang_2@nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2796646 commit 8f6aa39

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

drivers/usb/chipidea/core.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,6 @@ static enum ci_role ci_get_role(struct ci_hdrc *ci)
655655
return role;
656656
}
657657

658-
static struct usb_role_switch_desc ci_role_switch = {
659-
.set = ci_usb_role_switch_set,
660-
.get = ci_usb_role_switch_get,
661-
.allow_userspace_control = true,
662-
};
663-
664658
static int ci_get_platdata(struct device *dev,
665659
struct ci_hdrc_platform_data *platdata)
666660
{
@@ -787,9 +781,6 @@ static int ci_get_platdata(struct device *dev,
787781
cable->connected = false;
788782
}
789783

790-
if (device_property_read_bool(dev, "usb-role-switch"))
791-
ci_role_switch.fwnode = dev->fwnode;
792-
793784
platdata->pctl = devm_pinctrl_get(dev);
794785
if (!IS_ERR(platdata->pctl)) {
795786
struct pinctrl_state *p;
@@ -1033,6 +1024,7 @@ ATTRIBUTE_GROUPS(ci);
10331024

10341025
static int ci_hdrc_probe(struct platform_device *pdev)
10351026
{
1027+
struct usb_role_switch_desc ci_role_switch = {};
10361028
struct device *dev = &pdev->dev;
10371029
struct ci_hdrc *ci;
10381030
struct resource *res;
@@ -1179,7 +1171,11 @@ static int ci_hdrc_probe(struct platform_device *pdev)
11791171
}
11801172
}
11811173

1182-
if (ci_role_switch.fwnode) {
1174+
if (device_property_read_bool(dev, "usb-role-switch")) {
1175+
ci_role_switch.set = ci_usb_role_switch_set;
1176+
ci_role_switch.get = ci_usb_role_switch_get;
1177+
ci_role_switch.allow_userspace_control = true;
1178+
ci_role_switch.fwnode = dev_fwnode(dev);
11831179
ci_role_switch.driver_data = ci;
11841180
ci->role_switch = usb_role_switch_register(dev,
11851181
&ci_role_switch);

0 commit comments

Comments
 (0)