Skip to contentSkip to conversation

spi: don't lock the bus in __spi_pump_messages if it is already locked

PATCH In review Heiko Stübner 2 participants 2 messages Mar 17, 2016 – Mar 18, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: don't lock the bus in __spi_pump_messages if it is already locked

External users may use spi_bus_lock to get exclusive access. This will also grab the bus_lock_mutex and may therefore result in a deadlock if __spi_pump_messages also tries to get the mutex.

Fixes 49023d2e4ead ("spi: core: Fix deadlock when sending messages")
---
 drivers/spi/spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi.c +2 -2
index de2f2f9..62f962b 100644
@@ -1160,7 +1160,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread,
 		}
 	}
 
-	if (!bus_locked)
+	if (!bus_locked && !master->bus_lock_flag)
 		mutex_lock(&master->bus_lock_mutex);
 
 	trace_spi_message_start(master->cur_msg);
@@ -1192,7 +1192,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread,
 	}
 
 out:
-	if (!bus_locked)
+	if (!bus_locked && !master->bus_lock_flag)
 		mutex_unlock(&master->bus_lock_mutex);
 
 	/* Prod the scheduler in case transfer_one() was busy waiting */
Signature · 7 lines
2.6.4


--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw
Quoted 3 lines · Heiko Stübner

External users may use spi_bus_lock to get exclusive access. This will also grab the bus_lock_mutex and may therefore result in a deadlock if __spi_pump_messages also tries to get the mutex.

I suggest bus_locked flag passed to __spi_pump_messages() by __spi_sync() be updated to take care of the fact that spi_bus_lock() may have acquired the mutex, so that below changes in __spi_pump_messages() are not needed.

Quoted 30 lines
Fixes 49023d2e4ead ("spi: core: Fix deadlock when sending messages")
---
 drivers/spi/spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi.c +2 -2
index de2f2f9..62f962b 100644
@@ -1160,7 +1160,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread,
 		}
 	}
 
-	if (!bus_locked)
+	if (!bus_locked && !master->bus_lock_flag)
 		mutex_lock(&master->bus_lock_mutex);
 
 	trace_spi_message_start(master->cur_msg);
@@ -1192,7 +1192,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread,
 	}
 
 out:
-	if (!bus_locked)
+	if (!bus_locked && !master->bus_lock_flag)
 		mutex_unlock(&master->bus_lock_mutex);
 
 	/* Prod the scheduler in case transfer_one() was busy waiting */
Signature · 6 lines
Regards
Vignesh
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html