[1/4] usb: ucsi: Add missing ppm_lock

Message ID 20240107001701.130535-2-lk@c--e.de
State New
Headers
Series Make UCSI on Dell Latitude work |

Commit Message

Christian A. Ehrhardt Jan. 7, 2024, 12:16 a.m. UTC
  Calling ->sync_write must be done while holding the PPM lock as the
mailbox logic does not support concurrent commands.

Add a missing lock around the only call to
ucsi_acknowledge_connector_change. Additionally, warn in ucsi_acpi.c
if a command is started while the COMMAND_PENDING bit is already set.

Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
---
 drivers/usb/typec/ucsi/ucsi.c      | 2 ++
 drivers/usb/typec/ucsi/ucsi_acpi.c | 2 ++
 2 files changed, 4 insertions(+)
  

Patch

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 61b64558f96c..8f9dff993b3d 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -935,7 +935,9 @@  static void ucsi_handle_connector_change(struct work_struct *work)
 
 	clear_bit(EVENT_PENDING, &con->ucsi->flags);
 
+	mutex_lock(&ucsi->ppm_lock);
 	ret = ucsi_acknowledge_connector_change(ucsi);
+	mutex_unlock(&ucsi->ppm_lock);
 	if (ret)
 		dev_err(ucsi->dev, "%s: ACK failed (%d)", __func__, ret);
 
diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c
index 6bbf490ac401..8062d0a4b523 100644
--- a/drivers/usb/typec/ucsi/ucsi_acpi.c
+++ b/drivers/usb/typec/ucsi/ucsi_acpi.c
@@ -75,6 +75,8 @@  static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset,
 	struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi);
 	int ret;
 
+	WARN_ON(test_bit(COMMAND_PENDING, &ua->flags));
+
 	set_bit(COMMAND_PENDING, &ua->flags);
 
 	ret = ucsi_acpi_async_write(ucsi, offset, val, val_len);