diff --git a/drivers/audio/wm8776.c b/drivers/audio/wm8776.c index 79c770aac22..f7d409723ec 100644 --- a/drivers/audio/wm8776.c +++ b/drivers/audio/wm8776.c @@ -494,7 +494,7 @@ static void wm8776_senddone(FAR struct i2s_dev_s *i2s, * against that possibility. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&priv->lock); /* Add the completed buffer to the end of our doneq. We do not yet * decrement the reference count. @@ -512,7 +512,7 @@ static void wm8776_senddone(FAR struct i2s_dev_s *i2s, /* REVISIT: This can be overwritten */ priv->result = result; - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&priv->lock, flags); /* Now send a message to the worker thread, informing it that there are * buffers in the done queue that need to be cleaned up. @@ -547,13 +547,13 @@ static void wm8776_returnbuffers(FAR struct wm8776_dev_s *priv) * use interrupt controls to protect against that possibility. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&priv->lock); while (dq_peek(&priv->doneq) != NULL) { /* Take the next buffer from the queue of completed transfers */ apb = (FAR struct ap_buffer_s *)dq_remfirst(&priv->doneq); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&priv->lock, flags); audinfo("Returning: apb=%p curbyte=%d nbytes=%d flags=%04x\n", apb, apb->curbyte, apb->nbytes, apb->flags); @@ -588,10 +588,10 @@ static void wm8776_returnbuffers(FAR struct wm8776_dev_s *priv) #else priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_DEQUEUE, apb, OK); #endif - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&priv->lock); } - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&priv->lock, flags); } /**************************************************************************** @@ -644,9 +644,9 @@ static int wm8776_sendbuffer(FAR struct wm8776_dev_s *priv) * to avoid a possible race condition. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&priv->lock); priv->inflight++; - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&priv->lock, flags); shift = (priv->bpsamp == 8) ? 14 - 3 : 14 - 4; shift -= (priv->nchannels > 1) ? 1 : 0; diff --git a/drivers/audio/wm8776.h b/drivers/audio/wm8776.h index 55a772f4882..4dc5c23843b 100644 --- a/drivers/audio/wm8776.h +++ b/drivers/audio/wm8776.h @@ -36,6 +36,7 @@ #include #include #include +#include #ifdef CONFIG_AUDIO @@ -107,6 +108,7 @@ struct wm8776_dev_s #endif bool reserved; /* True: Device is reserved */ volatile int result; /* The result of the last transfer */ + spinlock_t lock; /* Spinlock */ }; #endif /* CONFIG_AUDIO */