Răsfoiți Sursa

soc: qcom: fix shareable channel deadlock

This change fixes a deadlock that happens,
when two shareable channels send a message at the same time,
locking each other with a different lock.

Change-Id: Ibb3efef1bdb29d2db6912e6465e6086248ab2310
Signed-off-by: Dan Bar-On <[email protected]>
Dan Bar-On 2 ani în urmă
părinte
comite
f1aa5a244e
1 a modificat fișierele cu 5 adăugiri și 3 ștergeri
  1. 5 3
      drivers/spcom.c

+ 5 - 3
drivers/spcom.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2015-2019, 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2015-2019, 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 /*
@@ -2275,6 +2275,9 @@ static int spcom_send_message(void *arg, void *buffer, bool is_modified)
 		return -ENOMEM;
 	hdr = tx_buf;
 
+	if (ch->is_sharable)
+		mutex_lock(&ch->shared_sync_lock);
+
 	mutex_lock(&ch->lock);
 
 	/* For SPCOM server, get next request size must be called before sending a response
@@ -2290,11 +2293,10 @@ static int spcom_send_message(void *arg, void *buffer, bool is_modified)
 	if (ch->is_sharable) {
 
 		if (ch->is_server) {
+			mutex_unlock(&ch->shared_sync_lock);
 			spcom_pr_err("server spcom channel cannot be shared\n");
 			goto send_message_err;
 		}
-
-		mutex_lock(&ch->shared_sync_lock);
 		ch->active_pid = current_pid();
 	}