From e21e264ca9a607b29cdf41909f61972f4a1a9133 Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Fri, 12 May 2023 13:48:52 -0700 Subject: [PATCH] usb: dwc3: msm: Enforce usb_data_enabled by blocking role switches Block USB enumeration from the get-go by blocking role switches away from USB_ROLE_NONE when usb_data_enabled is false. Change-Id: I0eff78e56e4a3b64262f220a085cfec5910baf30 Signed-off-by: Sultan Alsawaf --- drivers/usb/dwc3/dwc3-msm.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-msm.c b/drivers/usb/dwc3/dwc3-msm.c index abf9aeca77b0..5a3f1f27189d 100644 --- a/drivers/usb/dwc3/dwc3-msm.c +++ b/drivers/usb/dwc3/dwc3-msm.c @@ -4041,9 +4041,6 @@ static int dwc3_msm_id_notifier(struct notifier_block *nb, if (!edev || !mdwc) return NOTIFY_DONE; - if (!mdwc->usb_data_enabled) - return NOTIFY_DONE; - dwc = platform_get_drvdata(mdwc->dwc3); dbg_event(0xFF, "extcon idx", enb->idx); @@ -4098,9 +4095,6 @@ static int dwc3_msm_vbus_notifier(struct notifier_block *nb, if (!edev || !mdwc) return NOTIFY_DONE; - if (!mdwc->usb_data_enabled) - return NOTIFY_DONE; - dwc = platform_get_drvdata(mdwc->dwc3); dbg_event(0xFF, "extcon idx", enb->idx); @@ -4231,6 +4225,9 @@ static bool dwc3_msm_role_allowed(struct dwc3_msm *mdwc, enum usb_role role) if (role == USB_ROLE_DEVICE && mdwc->dr_mode == USB_DR_MODE_HOST) return false; + if (!mdwc->usb_data_enabled && role != USB_ROLE_NONE) + return false; + return true; } @@ -4714,15 +4711,14 @@ static ssize_t usb_data_enabled_store(struct device *dev, const char *buf, size_t count) { struct dwc3_msm *mdwc = dev_get_drvdata(dev); + bool enabled; - if (kstrtobool(buf, &mdwc->usb_data_enabled)) + if (kstrtobool(buf, &enabled)) return -EINVAL; - if (!mdwc->usb_data_enabled) { - mdwc->vbus_active = false; - mdwc->id_state = DWC3_ID_FLOAT; - dwc3_ext_event_notify(mdwc); - } + mdwc->usb_data_enabled = enabled; + if (!enabled) + dwc3_msm_usb_set_role(dev, USB_ROLE_NONE); return count; }