Bläddra i källkod

dsp-kernel: Handle race-condition in dsp signal

The `fastrpc_dspsignal_wait` function currently checks the
signal state before waiting for a signal from the DSP. However,
if the signal is already received before the check, it results
in an infinite loop, causing excessive resource usage.

This change addresses the race condition by checking both the
pending and signaled states. If the signal is not in the pending
state, it directly checks for the signaled state, resets the states,
and returns to avoid looping.

Change-Id: I00f80780cccf5a7b0e95f961607042efe62d9d30
Signed-off-by: quic_anane <[email protected]>
quic_anane 1 år sedan
förälder
incheckning
1d05790e68
1 ändrade filer med 5 tillägg och 0 borttagningar
  1. 5 0
      dsp/adsprpc.c

+ 5 - 0
dsp/adsprpc.c

@@ -7040,6 +7040,11 @@ int fastrpc_dspsignal_wait(struct fastrpc_file *fl,
 	if (s->state != DSPSIGNAL_STATE_PENDING) {
 		if ((s->state == DSPSIGNAL_STATE_CANCELED) || (s->state == DSPSIGNAL_STATE_UNUSED))
 			err = -EINTR;
+		if (s->state == DSPSIGNAL_STATE_SIGNALED) {
+			/* Signal already received from DSP. Reset signal state and return */
+			s->state = DSPSIGNAL_STATE_PENDING;
+			reinit_completion(&s->comp);
+		}
 		spin_unlock_irqrestore(&fl->dspsignals_lock, irq_flags);
 		DSPSIGNAL_VERBOSE("Signal %u in state %u, complete wait immediately",
 				  signal_id, s->state);