Skip to content

Commit 316fa9e

Browse files
charleskeepaxbroonie
authored andcommitted
ASoC: samsung: Use IRQ safe spin lock calls
Lockdep warns of a potential lock inversion, i2s->lock is held numerous times whilst we are under the substream lock (snd_pcm_stream_lock). If we use the IRQ unsafe spin lock calls, you can also end up locking snd_pcm_stream_lock whilst under i2s->lock (if an IRQ happens whilst we are holding i2s->lock). This could result in deadlock. [ 18.147001] CPU0 CPU1 [ 18.151509] ---- ---- [ 18.156022] lock(&(&pri_dai->spinlock)->rlock); [ 18.160701] local_irq_disable(); [ 18.166622] lock(&(&substream->self_group.lock)->rlock); [ 18.174595] lock(&(&pri_dai->spinlock)->rlock); [ 18.181806] <Interrupt> [ 18.184408] lock(&(&substream->self_group.lock)->rlock); [ 18.190045] [ 18.190045] *** DEADLOCK *** This patch changes to using the irq safe spinlock calls, to avoid this issue. Fixes: ce8bcdb ("ASoC: samsung: i2s: Protect more registers with a spinlock") Signed-off-by: Charles Keepax <[email protected]> Tested-by: Anand Moon <[email protected]> Signed-off-by: Mark Brown <[email protected]> Cc: [email protected]
1 parent 92e963f commit 316fa9e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

sound/soc/samsung/i2s.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,11 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
481481
unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off;
482482
unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off;
483483
u32 mod, mask, val = 0;
484+
unsigned long flags;
484485

485-
spin_lock(i2s->lock);
486+
spin_lock_irqsave(i2s->lock, flags);
486487
mod = readl(i2s->addr + I2SMOD);
487-
spin_unlock(i2s->lock);
488+
spin_unlock_irqrestore(i2s->lock, flags);
488489

489490
switch (clk_id) {
490491
case SAMSUNG_I2S_OPCLK:
@@ -575,11 +576,11 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
575576
return -EINVAL;
576577
}
577578

578-
spin_lock(i2s->lock);
579+
spin_lock_irqsave(i2s->lock, flags);
579580
mod = readl(i2s->addr + I2SMOD);
580581
mod = (mod & ~mask) | val;
581582
writel(mod, i2s->addr + I2SMOD);
582-
spin_unlock(i2s->lock);
583+
spin_unlock_irqrestore(i2s->lock, flags);
583584

584585
return 0;
585586
}
@@ -590,6 +591,7 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
590591
struct i2s_dai *i2s = to_info(dai);
591592
int lrp_shift, sdf_shift, sdf_mask, lrp_rlow, mod_slave;
592593
u32 mod, tmp = 0;
594+
unsigned long flags;
593595

594596
lrp_shift = i2s->variant_regs->lrp_off;
595597
sdf_shift = i2s->variant_regs->sdf_off;
@@ -649,15 +651,15 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
649651
return -EINVAL;
650652
}
651653

652-
spin_lock(i2s->lock);
654+
spin_lock_irqsave(i2s->lock, flags);
653655
mod = readl(i2s->addr + I2SMOD);
654656
/*
655657
* Don't change the I2S mode if any controller is active on this
656658
* channel.
657659
*/
658660
if (any_active(i2s) &&
659661
((mod & (sdf_mask | lrp_rlow | mod_slave)) != tmp)) {
660-
spin_unlock(i2s->lock);
662+
spin_unlock_irqrestore(i2s->lock, flags);
661663
dev_err(&i2s->pdev->dev,
662664
"%s:%d Other DAI busy\n", __func__, __LINE__);
663665
return -EAGAIN;
@@ -666,7 +668,7 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
666668
mod &= ~(sdf_mask | lrp_rlow | mod_slave);
667669
mod |= tmp;
668670
writel(mod, i2s->addr + I2SMOD);
669-
spin_unlock(i2s->lock);
671+
spin_unlock_irqrestore(i2s->lock, flags);
670672

671673
return 0;
672674
}
@@ -676,6 +678,7 @@ static int i2s_hw_params(struct snd_pcm_substream *substream,
676678
{
677679
struct i2s_dai *i2s = to_info(dai);
678680
u32 mod, mask = 0, val = 0;
681+
unsigned long flags;
679682

680683
if (!is_secondary(i2s))
681684
mask |= (MOD_DC2_EN | MOD_DC1_EN);
@@ -744,11 +747,11 @@ static int i2s_hw_params(struct snd_pcm_substream *substream,
744747
return -EINVAL;
745748
}
746749

747-
spin_lock(i2s->lock);
750+
spin_lock_irqsave(i2s->lock, flags);
748751
mod = readl(i2s->addr + I2SMOD);
749752
mod = (mod & ~mask) | val;
750753
writel(mod, i2s->addr + I2SMOD);
751-
spin_unlock(i2s->lock);
754+
spin_unlock_irqrestore(i2s->lock, flags);
752755

753756
samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
754757

0 commit comments

Comments
 (0)