Commit 7e4be129 authored by Dan Carpenter's avatar Dan Carpenter Committed by Vinod Koul

dmaengine: fix error codes in channel_register()

The error codes were not set on some of these error paths.

Also the error handling was more confusing than it needed to be so I
cleaned it up and shuffled it around a bit.

Fixes: d2fb0a04 ("dmaengine: break out channel registration")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: default avatarPeter Ujfalusi <peter.ujfalusi@ti.com>
Link: https://lore.kernel.org/r/20201113101631.GE168908@mwandaSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent e773ca7d
...@@ -1039,16 +1039,15 @@ static int get_dma_id(struct dma_device *device) ...@@ -1039,16 +1039,15 @@ static int get_dma_id(struct dma_device *device)
static int __dma_async_device_channel_register(struct dma_device *device, static int __dma_async_device_channel_register(struct dma_device *device,
struct dma_chan *chan) struct dma_chan *chan)
{ {
int rc = 0; int rc;
chan->local = alloc_percpu(typeof(*chan->local)); chan->local = alloc_percpu(typeof(*chan->local));
if (!chan->local) if (!chan->local)
goto err_out; return -ENOMEM;
chan->dev = kzalloc(sizeof(*chan->dev), GFP_KERNEL); chan->dev = kzalloc(sizeof(*chan->dev), GFP_KERNEL);
if (!chan->dev) { if (!chan->dev) {
free_percpu(chan->local); rc = -ENOMEM;
chan->local = NULL; goto err_free_local;
goto err_out;
} }
/* /*
...@@ -1061,7 +1060,8 @@ static int __dma_async_device_channel_register(struct dma_device *device, ...@@ -1061,7 +1060,8 @@ static int __dma_async_device_channel_register(struct dma_device *device,
if (chan->chan_id < 0) { if (chan->chan_id < 0) {
pr_err("%s: unable to alloc ida for chan: %d\n", pr_err("%s: unable to alloc ida for chan: %d\n",
__func__, chan->chan_id); __func__, chan->chan_id);
goto err_out; rc = chan->chan_id;
goto err_free_dev;
} }
chan->dev->device.class = &dma_devclass; chan->dev->device.class = &dma_devclass;
...@@ -1082,9 +1082,10 @@ static int __dma_async_device_channel_register(struct dma_device *device, ...@@ -1082,9 +1082,10 @@ static int __dma_async_device_channel_register(struct dma_device *device,
mutex_lock(&device->chan_mutex); mutex_lock(&device->chan_mutex);
ida_free(&device->chan_ida, chan->chan_id); ida_free(&device->chan_ida, chan->chan_id);
mutex_unlock(&device->chan_mutex); mutex_unlock(&device->chan_mutex);
err_out: err_free_dev:
free_percpu(chan->local);
kfree(chan->dev); kfree(chan->dev);
err_free_local:
free_percpu(chan->local);
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment