linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: typec: ucsi: Fix connector check on init
@ 2024-04-01 21:05 Christian A. Ehrhardt
  2024-04-03 10:42 ` Heikki Krogerus
  0 siblings, 1 reply; 2+ messages in thread
From: Christian A. Ehrhardt @ 2024-04-01 21:05 UTC (permalink / raw)
  To: linux-kernel, Dmitry Baryshkov
  Cc: Christian A. Ehrhardt, stable, Heikki Krogerus,
	Greg Kroah-Hartman, Prashant Malani, Jameson Thies,
	Abhishek Pandit-Subedi, Neil Armstrong, Uwe Kleine-König,
	Samuel Čavoj, linux-usb

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>
---
 drivers/usb/typec/ucsi/ucsi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 31d8a46ae5e7..bd6ae92aa39e 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -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;
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: typec: ucsi: Fix connector check on init
  2024-04-01 21:05 [PATCH] usb: typec: ucsi: Fix connector check on init Christian A. Ehrhardt
@ 2024-04-03 10:42 ` Heikki Krogerus
  0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2024-04-03 10:42 UTC (permalink / raw)
  To: Christian A. Ehrhardt
  Cc: linux-kernel, Dmitry Baryshkov, stable, Greg Kroah-Hartman,
	Prashant Malani, Jameson Thies, Abhishek Pandit-Subedi,
	Neil Armstrong, Uwe Kleine-König, Samuel Čavoj,
	linux-usb

On Mon, Apr 01, 2024 at 11:05:15PM +0200, Christian A. Ehrhardt wrote:
> 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>

> ---
>  drivers/usb/typec/ucsi/ucsi.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 31d8a46ae5e7..bd6ae92aa39e 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -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;
>  
> -- 
> 2.40.1

-- 
heikki

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-03 10:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01 21:05 [PATCH] usb: typec: ucsi: Fix connector check on init Christian A. Ehrhardt
2024-04-03 10:42 ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).