Skip to content

Commit 7e4be12

Browse files
Dan Carpentervinodkoul
authored andcommitted
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: d2fb0a0 ("dmaengine: break out channel registration") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Link: https://lore.kernel.org/r/20201113101631.GE168908@mwanda Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent e773ca7 commit 7e4be12

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

drivers/dma/dmaengine.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,16 +1039,15 @@ static int get_dma_id(struct dma_device *device)
10391039
static int __dma_async_device_channel_register(struct dma_device *device,
10401040
struct dma_chan *chan)
10411041
{
1042-
int rc = 0;
1042+
int rc;
10431043

10441044
chan->local = alloc_percpu(typeof(*chan->local));
10451045
if (!chan->local)
1046-
goto err_out;
1046+
return -ENOMEM;
10471047
chan->dev = kzalloc(sizeof(*chan->dev), GFP_KERNEL);
10481048
if (!chan->dev) {
1049-
free_percpu(chan->local);
1050-
chan->local = NULL;
1051-
goto err_out;
1049+
rc = -ENOMEM;
1050+
goto err_free_local;
10521051
}
10531052

10541053
/*
@@ -1061,7 +1060,8 @@ static int __dma_async_device_channel_register(struct dma_device *device,
10611060
if (chan->chan_id < 0) {
10621061
pr_err("%s: unable to alloc ida for chan: %d\n",
10631062
__func__, chan->chan_id);
1064-
goto err_out;
1063+
rc = chan->chan_id;
1064+
goto err_free_dev;
10651065
}
10661066

10671067
chan->dev->device.class = &dma_devclass;
@@ -1082,9 +1082,10 @@ static int __dma_async_device_channel_register(struct dma_device *device,
10821082
mutex_lock(&device->chan_mutex);
10831083
ida_free(&device->chan_ida, chan->chan_id);
10841084
mutex_unlock(&device->chan_mutex);
1085-
err_out:
1086-
free_percpu(chan->local);
1085+
err_free_dev:
10871086
kfree(chan->dev);
1087+
err_free_local:
1088+
free_percpu(chan->local);
10881089
return rc;
10891090
}
10901091

0 commit comments

Comments
 (0)