From patchwork Sun Oct 22 14:54:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10021723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CA0AB60224 for ; Sun, 22 Oct 2017 14:55:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B32A3284F8 for ; Sun, 22 Oct 2017 14:55:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A64BC2854A; Sun, 22 Oct 2017 14:55:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E451284F8 for ; Sun, 22 Oct 2017 14:55:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751217AbdJVOzL (ORCPT ); Sun, 22 Oct 2017 10:55:11 -0400 Received: from mout.web.de ([217.72.192.78]:61171 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751014AbdJVOzK (ORCPT ); Sun, 22 Oct 2017 10:55:10 -0400 Received: from [192.168.1.2] ([77.182.45.221]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MWSBi-1difB1265y-00XbI4; Sun, 22 Oct 2017 16:55:01 +0200 To: dmaengine@vger.kernel.org, Dan Williams , Peter Ujfalusi , Vinod Koul Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] dmaengine: edma: Use common error handling code in three functions Message-ID: Date: Sun, 22 Oct 2017 16:54:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Language: en-GB X-Provags-ID: V03:K0:rH3fGSv8juosohqtuEGkB2x0cyt8nVUAx+2pTmsnnUZ26nXPDUf NCaoR7M5n3ZllEfpHGmVPvmfQMSGWAYArffql20O/Haj9qbQv58uVqyDG1MbHTU35wnDKMy 22a0wltQE375m14wlcbrlv2LAWFuE+FppzQzGm9rDmAbyeTbwt2253R3e2x1wxoocjiBD9T RcSyjoHUef1FTAm6skbUw== X-UI-Out-Filterresults: notjunk:1; V01:K0:CMm5VhE3lgg=:AanHlR/f/wR+dMGyPkUP8t 9CTHDKhTGOy87ZcwsBVSBM3/6XUtE5U6X11abD88VzpaXgalf+6ZWGXxSA/VRm1Ljh4ooD9tH TtPfWUOaT8YVuEZ1KGbA3ZIPojh8quX4LxeDA3kcYrcgD2XK8Z4guu4yhhkw0pwIO57H8spp/ AbMd9FfNwtafW+cKE3KeD+/kAC8SfXy7wE5RDmOxXfmjimtw6jWM/rdel9M+9xnHuoVWrhm+O 0HMjJ9XxYhd2bTfS9LrRRtAjTKuBBv+/1WiDPLlLf5pIYNO5hj56e4jLYClorT3Yps7DbMJ59 K2jBIlPSYFBHdI+I2RyK1OS1kBN2W1Xq+xrHVONMeyJPm99awRjOXzg9a3Wm2h8rjyN6AwbEZ HTKO93dV/JudYtoK09z/5BC7OA+GkWCD9/yPd5U2UFHruodUARhRlaSxkmCb80BTN2+8epmNt q2X9OVpTpBxhfG6yGziH2sGJrfgENAEd6ubZ5jOhKGj7oK+N3VOrI9ub/l+U3PAKWlVYMy9/G FpMoRYotFnTO+dricGLJbwc3L5XI+qH1bVNkVxc4KvUwlvqsy1Kqn4VfESUHOm8XGrD6tJdXs RpIyVO/SAC+PtzO8xVgCvJt8Tw6YWx81nwiOH5L+GCHvnR3PndKNUg1XoeJDgY8cvJhgoc/oh BFaygUWEtcsd0c92B2kSQf+ex/agVXWjmsFwoZcDXT8AjbDg9qXX8Zkr8zxLOAgOiop5r+Zco d1eztcnrL6Os0vTNtNWlpcWCpNVAXsMv41dRVcf3farupNksZyIKtmgjeb3RgKHUymV0vWZAr ocIFNYlIwg4totizfMyYRkO6CQMx5MvsoDh+HBy1/yycmM1tMA= Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 22 Oct 2017 16:46:34 +0200 Add a jump target so that a bit of exception handling can be better reused at the end of these functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Acked-by: Peter Ujfalusi --- drivers/dma/edma.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/drivers/dma/edma.c b/drivers/dma/edma.c index a7ea20e7b8e9..c973ea97467f 100644 --- a/drivers/dma/edma.c +++ b/drivers/dma/edma.c @@ -1091,10 +1091,9 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg( echan->slot[i] = edma_alloc_slot(echan->ecc, EDMA_SLOT_ANY); if (echan->slot[i] < 0) { - kfree(edesc); dev_err(dev, "%s: Failed to allocate slot\n", __func__); - return NULL; + goto free_desc; } } } @@ -1110,10 +1109,8 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg( ret = edma_config_pset(chan, &edesc->pset[i], src_addr, dst_addr, burst, dev_width, sg_dma_len(sg), direction); - if (ret < 0) { - kfree(edesc); - return NULL; - } + if (ret < 0) + goto free_desc; edesc->absync = ret; edesc->residue += sg_dma_len(sg); @@ -1133,6 +1130,10 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg( edesc->residue_stat = edesc->residue; return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags); + +free_desc: + kfree(edesc); + return NULL; } static struct dma_async_tx_descriptor *edma_prep_dma_memcpy( @@ -1203,10 +1204,8 @@ static struct dma_async_tx_descriptor *edma_prep_dma_memcpy( ret = edma_config_pset(chan, &edesc->pset[0], src, dest, 1, width, pset_len, DMA_MEM_TO_MEM); - if (ret < 0) { - kfree(edesc); - return NULL; - } + if (ret < 0) + goto free_desc; edesc->absync = ret; @@ -1222,10 +1221,9 @@ static struct dma_async_tx_descriptor *edma_prep_dma_memcpy( echan->slot[1] = edma_alloc_slot(echan->ecc, EDMA_SLOT_ANY); if (echan->slot[1] < 0) { - kfree(edesc); dev_err(dev, "%s: Failed to allocate slot\n", __func__); - return NULL; + goto free_desc; } } dest += pset_len; @@ -1234,16 +1232,18 @@ static struct dma_async_tx_descriptor *edma_prep_dma_memcpy( ret = edma_config_pset(chan, &edesc->pset[1], src, dest, 1, width, pset_len, DMA_MEM_TO_MEM); - if (ret < 0) { - kfree(edesc); - return NULL; - } + if (ret < 0) + goto free_desc; edesc->pset[1].param.opt |= ITCCHEN; edesc->pset[1].param.opt |= TCINTEN; } return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags); + +free_desc: + kfree(edesc); + return NULL; } static struct dma_async_tx_descriptor *edma_prep_dma_cyclic( @@ -1334,10 +1334,9 @@ static struct dma_async_tx_descriptor *edma_prep_dma_cyclic( echan->slot[i] = edma_alloc_slot(echan->ecc, EDMA_SLOT_ANY); if (echan->slot[i] < 0) { - kfree(edesc); dev_err(dev, "%s: Failed to allocate slot\n", __func__); - return NULL; + goto free_desc; } } @@ -1350,10 +1349,8 @@ static struct dma_async_tx_descriptor *edma_prep_dma_cyclic( ret = edma_config_pset(chan, &edesc->pset[i], src_addr, dst_addr, burst, dev_width, period_len, direction); - if (ret < 0) { - kfree(edesc); - return NULL; - } + if (ret < 0) + goto free_desc; if (direction == DMA_DEV_TO_MEM) dst_addr += period_len; @@ -1402,6 +1399,10 @@ static struct dma_async_tx_descriptor *edma_prep_dma_cyclic( edma_assign_channel_eventq(echan, EVENTQ_0); return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags); + +free_desc: + kfree(edesc); + return NULL; } static void edma_completion_handler(struct edma_chan *echan)