Commit 83515bc7df812555e20cda48614674e2f346f9f5
Committed by
Paul Mundt
1 parent
e3a4317e1d
Exists in
master
and in
7 other branches
SH: fix error paths in DMA driver
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>
Showing 1 changed file with 21 additions and 6 deletions Side-by-side Diff
drivers/dma/shdma.c
... | ... | @@ -290,6 +290,7 @@ |
290 | 290 | struct sh_dmae_chan *sh_chan = to_sh_chan(chan); |
291 | 291 | struct sh_desc *desc; |
292 | 292 | struct sh_dmae_slave *param = chan->private; |
293 | + int ret; | |
293 | 294 | |
294 | 295 | pm_runtime_get_sync(sh_chan->dev); |
295 | 296 | |
296 | 297 | |
... | ... | @@ -301,11 +302,15 @@ |
301 | 302 | struct sh_dmae_slave_config *cfg; |
302 | 303 | |
303 | 304 | cfg = sh_dmae_find_slave(sh_chan, param->slave_id); |
304 | - if (!cfg) | |
305 | - return -EINVAL; | |
305 | + if (!cfg) { | |
306 | + ret = -EINVAL; | |
307 | + goto efindslave; | |
308 | + } | |
306 | 309 | |
307 | - if (test_and_set_bit(param->slave_id, sh_dmae_slave_used)) | |
308 | - return -EBUSY; | |
310 | + if (test_and_set_bit(param->slave_id, sh_dmae_slave_used)) { | |
311 | + ret = -EBUSY; | |
312 | + goto etestused; | |
313 | + } | |
309 | 314 | |
310 | 315 | param->config = cfg; |
311 | 316 | |
312 | 317 | |
... | ... | @@ -334,10 +339,20 @@ |
334 | 339 | } |
335 | 340 | spin_unlock_bh(&sh_chan->desc_lock); |
336 | 341 | |
337 | - if (!sh_chan->descs_allocated) | |
338 | - pm_runtime_put(sh_chan->dev); | |
342 | + if (!sh_chan->descs_allocated) { | |
343 | + ret = -ENOMEM; | |
344 | + goto edescalloc; | |
345 | + } | |
339 | 346 | |
340 | 347 | return sh_chan->descs_allocated; |
348 | + | |
349 | +edescalloc: | |
350 | + if (param) | |
351 | + clear_bit(param->slave_id, sh_dmae_slave_used); | |
352 | +etestused: | |
353 | +efindslave: | |
354 | + pm_runtime_put(sh_chan->dev); | |
355 | + return ret; | |
341 | 356 | } |
342 | 357 | |
343 | 358 | /* |