Commit 5cff7073 authored by Christian A. Ehrhardt's avatar Christian A. Ehrhardt Committed by sanglipeng1
Browse files

usb: typec: ucsi: Fix connector check on init

stable inclusion
from stable-v5.10.217
commit 3a970e41c34e2e94bb5b661854dfb4b0268c7d2a
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAWLXC

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=3a970e41c34e2e94bb5b661854dfb4b0268c7d2a



--------------------------------

commit ce4c8d21054ae9396cd759fe6e8157b525616dc4 upstream.

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: default avatarChristian A. Ehrhardt <lk@c--e.de>
Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20240401210515.1902048-1-lk@c--e.de


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarsanglipeng1 <sanglipeng1@jd.com>
parent bc83240b
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -1257,11 +1257,13 @@ static int ucsi_init(struct ucsi *ucsi)

	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;