Skip to content

Commit

Permalink
SH: fix error paths in DMA driver
Browse files Browse the repository at this point in the history
If channel allocation is failing, mark the channel unused and give PM a chance
to power down the hardware.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
  • Loading branch information
Guennadi Liakhovetski authored and Paul Mundt committed Apr 26, 2010
1 parent e3a4317 commit 83515bc
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions drivers/dma/shdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ static int sh_dmae_alloc_chan_resources(struct dma_chan *chan)
struct sh_dmae_chan *sh_chan = to_sh_chan(chan);
struct sh_desc *desc;
struct sh_dmae_slave *param = chan->private;
int ret;

pm_runtime_get_sync(sh_chan->dev);

Expand All @@ -301,11 +302,15 @@ static int sh_dmae_alloc_chan_resources(struct dma_chan *chan)
struct sh_dmae_slave_config *cfg;

cfg = sh_dmae_find_slave(sh_chan, param->slave_id);
if (!cfg)
return -EINVAL;
if (!cfg) {
ret = -EINVAL;
goto efindslave;
}

if (test_and_set_bit(param->slave_id, sh_dmae_slave_used))
return -EBUSY;
if (test_and_set_bit(param->slave_id, sh_dmae_slave_used)) {
ret = -EBUSY;
goto etestused;
}

param->config = cfg;

Expand Down Expand Up @@ -334,10 +339,20 @@ static int sh_dmae_alloc_chan_resources(struct dma_chan *chan)
}
spin_unlock_bh(&sh_chan->desc_lock);

if (!sh_chan->descs_allocated)
pm_runtime_put(sh_chan->dev);
if (!sh_chan->descs_allocated) {
ret = -ENOMEM;
goto edescalloc;
}

return sh_chan->descs_allocated;

edescalloc:
if (param)
clear_bit(param->slave_id, sh_dmae_slave_used);
etestused:
efindslave:
pm_runtime_put(sh_chan->dev);
return ret;
}

/*
Expand Down

0 comments on commit 83515bc

Please sign in to comment.