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 <sultan@osomprivacy.com>
This commit is contained in:
Sultan Alsawaf 2023-05-12 13:48:52 -07:00 committed by Michael Bestas
parent 257c29e6e2
commit 6c71d05108
No known key found for this signature in database
GPG Key ID: CC95044519BE6669

View File

@ -4259,9 +4259,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);
@ -4295,9 +4292,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;
if (mdwc->dwc3)
dwc = platform_get_drvdata(mdwc->dwc3);
@ -4480,6 +4474,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;
}
@ -4767,15 +4764,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_set_role(mdwc, USB_ROLE_NONE);
return count;
}