Skip to content

Commit fee12f3

Browse files
rfvirgilvinodkoul
authored andcommitted
soundwire: stream: Poll for DP prepare to avoid interrupt deadlock
Replace the wait_for_completion_timeout() in sdw_prep_deprep_slave_ports() with a read_poll_timeout(). The original intent of the wait_for_completion_timeout() was to wait for the port prepare interrupt. But at this time the code is holding the bus_lock, which prevents the interrupt handler from running. Because of this, the port_prep completion will not be signaled and the wait_for_completion_timeout() will always timeout. Rewriting the code to avoid taking the bus_lock carries risks, and needs careful consideration of the consequences. It is safer and simpler to replace the completion with a simple register poll. As the code is holding the bus_lock, it is already blocking other activity so consuming control channel bandwidth for polling isn't really a concern. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Link: https://patch.msgid.link/20260227111648.175548-1-rf@opensource.cirrus.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 27ab4f1 commit fee12f3

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

drivers/soundwire/stream.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/delay.h>
99
#include <linux/device.h>
1010
#include <linux/init.h>
11+
#include <linux/iopoll.h>
1112
#include <linux/module.h>
1213
#include <linux/mod_devicetable.h>
1314
#include <linux/slab.h>
@@ -18,6 +19,8 @@
1819
#include <sound/soc.h>
1920
#include "bus.h"
2021

22+
#define SDW_PORT_PREP_POLL_USEC 1000
23+
2124
/*
2225
* Array of supported rows and columns as per MIPI SoundWire Specification 1.1
2326
*
@@ -443,7 +446,6 @@ static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus,
443446
struct sdw_port_runtime *p_rt,
444447
bool prep)
445448
{
446-
struct completion *port_ready;
447449
struct sdw_dpn_prop *dpn_prop;
448450
struct sdw_prepare_ch prep_ch;
449451
u32 imp_def_interrupts;
@@ -518,14 +520,18 @@ static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus,
518520
return ret;
519521
}
520522

521-
/* Wait for completion on port ready */
522-
port_ready = &s_rt->slave->port_ready[prep_ch.num];
523-
wait_for_completion_timeout(port_ready,
524-
msecs_to_jiffies(ch_prep_timeout));
523+
/*
524+
* Poll for NOT_PREPARED==0. Cannot use the interrupt because
525+
* this code holds bus_lock which blocks interrupt handling.
526+
*/
527+
ret = read_poll_timeout(sdw_read_no_pm, val,
528+
(val < 0) || ((val & p_rt->ch_mask) == 0),
529+
SDW_PORT_PREP_POLL_USEC, ch_prep_timeout * USEC_PER_MSEC,
530+
false, s_rt->slave, SDW_DPN_PREPARESTATUS(p_rt->num));
531+
if (ret || (val < 0)) {
532+
if (val < 0)
533+
ret = val;
525534

526-
val = sdw_read_no_pm(s_rt->slave, SDW_DPN_PREPARESTATUS(p_rt->num));
527-
if ((val < 0) || (val & p_rt->ch_mask)) {
528-
ret = (val < 0) ? val : -ETIMEDOUT;
529535
dev_err(&s_rt->slave->dev,
530536
"Chn prep failed for port %d: %d\n", prep_ch.num, ret);
531537
return ret;

0 commit comments

Comments
 (0)