usb: typec: ucsi: skip connector validation before init
Subsystems (3)
PATCH 1/1 usb: typec: ucsi: skip connector validation before init
Notifications can arrive before ucsi_init() has populated ucsi->cap.num_connectors via GET_CAPABILITY. At that point num_connectors is still 0, causing all valid connector numbers to be incorrectly rejected as bogus.
Skip the bounds check when num_connectors is 0 (not yet initialized). Pre-init notifications are already handled safely by the early-event guard in ucsi_connector_change().
--- drivers/usb/typec/ucsi/ucsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/typec/ucsi/ucsi.c +2 -1
@@ -43,7 +43,8 @@ void ucsi_notify_common(struct ucsi *ucsi, u32 cci)return ;if (UCSI_CCI_CONNECTOR (cci)) { -if (UCSI_CCI_CONNECTOR (cci) <= ucsi->cap.num_connectors) +if (!ucsi->cap.num_connectors || +UCSI_CCI_CONNECTOR (cci) <= ucsi->cap.num_connectors)ucsi_connector_change (ucsi,UCSI_CCI_CONNECTOR (cci));else dev_err(ucsi->dev, "bogus connector number in CCI: %lu\n",
Signature · 1 line
2.43.0.windows.1
Quoted 23 lines · Nathan Rebello
Notifications can arrive before
ucsi_init()has populateducsi->cap.num_connectorsviaGET_CAPABILITY. At that pointnum_connectorsis still 0, causing all valid connector numbers to be incorrectly rejected as bogus.Skip the bounds check when
num_connectorsis 0 (not yet initialized). Pre-init notifications are already handled safely by the early-event guard inucsi_connector_change().Reported-by Takashi Iwai <[email protected]>Fixes d2d8c17ac01a ("usb: typec: ucsi: validate connector number in ucsi_notify_common()")Signed-off-by Nathan Rebello <[email protected]>--- drivers/usb/typec/ucsi/ucsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/usb/typec/ucsi/ucsi.c +0
-0
drivers/usb/typec/ucsi/ucsi.c void ucsi_notify_common(struct ucsi *ucsi, u32 cci) · line 50
Quoted 9 lines
drivers/usb/typec/ucsi/ucsi.c +2
-1@@ -43,7 +43,8 @@ void ucsi_notify_common(struct ucsi *ucsi, u32 cci)return ;if (UCSI_CCI_CONNECTOR (cci)) { -if (UCSI_CCI_CONNECTOR (cci) <= ucsi->cap.num_connectors) +if (!ucsi->cap.num_connectors || +UCSI_CCI_CONNECTOR (cci) <= ucsi->cap.num_connectors)ucsi_connector_change (ucsi,UCSI_CCI_CONNECTOR (cci));else dev_err(ucsi->dev, "bogus connector number in CCI: %lu\n",
Confirmed that it fixes my case.
Thanks!
Takashi
Quoted 5 lines · Nathan Rebello
Notifications can arrive before
ucsi_init()has populateducsi->cap.num_connectorsviaGET_CAPABILITY. At that pointnum_connectorsis still 0, causing all valid connector numbers to be incorrectly rejected as bogus.
Quoted 8 lines
Skip the bounds check when
num_connectorsis 0 (not yet initialized). Pre-init notifications are already handled safely by the early-event guard inucsi_connector_change().Reported-by Takashi Iwai <[email protected]>Fixes d2d8c17ac01a ("usb: typec: ucsi: validate connector number in ucsi_notify_common()")Signed-off-by Nathan Rebello <[email protected]>
Quoted 20 lines
--- drivers/usb/typec/ucsi/ucsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/usb/typec/ucsi/ucsi.c +2
-1@@ -43,7 +43,8 @@ void ucsi_notify_common(struct ucsi *ucsi, u32 cci)return ;if (UCSI_CCI_CONNECTOR (cci)) { -if (UCSI_CCI_CONNECTOR (cci) <= ucsi->cap.num_connectors) +if (!ucsi->cap.num_connectors || +UCSI_CCI_CONNECTOR (cci) <= ucsi->cap.num_connectors)ucsi_connector_change (ucsi,UCSI_CCI_CONNECTOR (cci));else dev_err(ucsi->dev, "bogus connector number in CCI: %lu\n",Signature · 1 line
2.43.0.windows.1
Signature · 1 line
heikki