usb: typec: ucsi: Fix connector check on init
authorChristian A. Ehrhardt <lk@c--e.de>
Mon, 1 Apr 2024 21:05:15 +0000 (23:05 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Apr 2024 13:17:13 +0000 (15:17 +0200)
Fix issues when initially checking for a connector change:
- Use the correct connector number not the entire CCI.
- Call ->read under the PPM lock.
- Remove a bogus READ_ONCE.

Fixes: 808a8b9e0b87 ("usb: typec: ucsi: Check for notifications after init")
Cc: stable@kernel.org
Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20240401210515.1902048-1-lk@c--e.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/ucsi/ucsi.c

index 31d8a46ae5e7cb4c5fee6f7b663517a6c367d348..bd6ae92aa39e7a4e271894e79fe38a6e3b463444 100644 (file)
@@ -1736,11 +1736,13 @@ static int ucsi_init(struct ucsi *ucsi)
        ucsi->connector = connector;
        ucsi->ntfy = ntfy;
 
+       mutex_lock(&ucsi->ppm_lock);
        ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
+       mutex_unlock(&ucsi->ppm_lock);
        if (ret)
                return ret;
-       if (UCSI_CCI_CONNECTOR(READ_ONCE(cci)))
-               ucsi_connector_change(ucsi, cci);
+       if (UCSI_CCI_CONNECTOR(cci))
+               ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci));
 
        return 0;