ALSA: firewire: Don't loop forever after a bus reset
cover ALSA: firewire: Don't loop forever after a bus reset
fcp_avc_transaction() and snd_efw_transaction_run() resend their command after a bus reset but never move the transaction back to STATE_PENDING. The response to the resent command is then ignored and the wait returns immediately, so both loops keep resending the command after each ERROR_DELAY_MS pause, without a retry limit, until sending fails.
Each patch sets the state back to STATE_PENDING before resending.
Found with a static analysis tool and checked by hand. Compile tested only (x86_64, W=1); I don't have FireWire audio hardware.
---
Suyuan Wang (2):
ALSA: firewire-lib: Rearm the FCP transaction after a bus reset
ALSA: fireworks: Rearm the transaction after a bus reset
sound/firewire/fcp.c | 2 ++ sound/firewire/fireworks/fireworks_transaction.c | 2 ++ 2 files changed, 4 insertions(+)
PATCH 1/2 ALSA: firewire-lib: Rearm the FCP transaction after a bus reset
From: Suyuan Wang <[email protected]>
When a bus reset happens while fcp_avc_transaction() waits for a response, fcp_bus_reset() moves the transaction to STATE_BUS_RESET and wakes the waiter, which sleeps and then sends the command again. Nothing sets the state back to STATE_PENDING, though:
wait_event_timeout(t.wait, t.state != STATE_PENDING, ...);
...
} else if (t.state == STATE_BUS_RESET) {
msleep(ERROR_DELAY_MS);
}fcp_response() only accepts a response for a transaction in STATE_PENDING, so the response to the resent command is ignored, and wait_event_timeout() returns at once because the state is still STATE_BUS_RESET. The loop then resends the command every ERROR_DELAY_MS without counting tries, and the caller never returns unless sending the command itself fails.
Set the state back to STATE_PENDING before resending, as the STATE_DEFERRED branch already does.
Found with a static analysis tool and checked by hand.
--- sound/firewire/fcp.c | 2 ++ 1 file changed, 2 insertions(+)
sound/firewire/fcp.c +2 -0
@@ -273,6 +273,8 @@ int fcp_avc_transaction(struct fw_unit *unit,break ; }else if (t.state ==STATE_BUS_RESET ) {msleep (ERROR_DELAY_MS ); +/* resend the command and wait for its response again */ + t.state =STATE_PENDING ; }else if (++tries >=ERROR_RETRIES ) {dev_err (&t.unit->device,"FCP command timed out\n" ); ret = -EIO ;
Signature · 1 line
2.34.1
PATCH 2/2 ALSA: fireworks: Rearm the transaction after a bus reset
In reply to Suyuan WangFrom: Suyuan Wang <[email protected]>
snd_efw_transaction_run() has the same problem as fcp_avc_transaction():
after snd_efw_transaction_bus_reset() moves the transaction to STATE_BUS_RESET, the loop sleeps and resends the command but leaves the state as it is. The response handler only completes a transaction in STATE_PENDING, and wait_event_timeout() returns at once on the stale state, so the command is resent every ERROR_DELAY_MS without counting tries and the caller never returns unless sending fails.
Set the state back to STATE_PENDING before resending.
Found with a static analysis tool and checked by hand.
--- sound/firewire/fireworks/fireworks_transaction.c | 2 ++ 1 file changed, 2 insertions(+)
sound/firewire/fireworks/fireworks_transaction.c +2 -0
@@ -100,6 +100,8 @@ int snd_efw_transaction_run(struct fw_unit *unit,break ; }else if (t.state ==STATE_BUS_RESET ) {msleep (ERROR_DELAY_MS ); +/* resend the command and wait for its response again */ + t.state =STATE_PENDING ; }else if (++tries >=ERROR_RETRIES ) {dev_err (&t.unit->device,"EFW transaction timed out\n" ); ret = -EIO ;
Signature · 1 line
2.34.1