From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752864AbcIQPQw (ORCPT ); Sat, 17 Sep 2016 11:16:52 -0400 Received: from mout.web.de ([217.72.192.78]:64725 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751970AbcIQPQn (ORCPT ); Sat, 17 Sep 2016 11:16:43 -0400 Subject: [PATCH 08/24] ste_dma40: Less checks in d40_hw_detect_init() after error detection To: dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Dan Williams , Linus Walleij , Vinod Koul References: <566ABCD9.1060404@users.sourceforge.net> <92810066-69b6-94e7-dcec-a28594b1328f@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: Date: Sat, 17 Sep 2016 17:16:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <92810066-69b6-94e7-dcec-a28594b1328f@users.sourceforge.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:USlpsoF6s+4Y5uMcg6E5qx90MaJ547vuJ7jLcg8FX/PKuga1hET Fe60/R6Ta4qGeOV6vsH+jRK2zJ5lwX8Y7fASqADX+egqtQO0rqNjrpeZWJ9p234YCcrhE3R /y0SNp7JLDWBPFcN9z661qrTGbz4CpvEkmqF239CJW7oPIYJTDznzRkZHDovBD0AWtYuQOK MkNoXSVai88duwabY9KpA== X-UI-Out-Filterresults: notjunk:1;V01:K0:YjjEvCrMdDA=:9ht13Z0s4BHK+19upwuIfl fNbqOYHC7WxrPCo+NmF4YjCGds+B6ni3IlH+WW6UNx59HPDdETihx2b6LXSRq0OJhVtDv04M+ T4D/ZZHvvXr06V2ow6y/YrEvCXxfDWSToBc9Mvt46QyMQ3Xk8LWjrRZAso7JrIt8vwuEpn13C HmpHqDH0aP3VbNmZi670kPKNmLgZMZhK413ZH40m829Gcv1gRsutXSjFrpIklPZQMb/eSJyai ETeP4QkKCZkXPBoX//+hBnFr+DwC39q+9zY4hFyKdnXezk4fs0Z8YIYlkP3LkeAgMNazCfUKw II/lOR+QKs2u9uuTIfqujfWkQ4lfW6gOiZTRanTl1iA8Im00Sh77eRg1GzKky9ma/Dp57Wka3 zMx2Lf9347Z1q2Vel+MXutqZV9+bW7LJfugmulW3RijhWZPnu9T6NLoH0qZmxl3Qoon4p418p +KLxdhjhqLXmtox+xqDpyysnAo83zjMFT/EHxckB2Ft/2IOK0R7RoYIXGXPm52vMnOdR5js/O 6mlkrXusqJkAqgMUcnBwRlExlf4s5uFfkM3e2QrpPurQLqWdh3PhzsLqr+ocUhyq6N34Axtmf tExCwpvDpey4ygQhOpMA/wQ75mCS8BfI8qoVMkew3Cf2GnQdsr89c8P7R/qpyodoMxPfWtYTB SZhBaIMXa5/cQ90Fw2Im9UOtyi5gKHbTV/OJGCHPeWWKlAaDV2zNVYkBiOSk7PV1NxtP0TPP8 HGvJ66NpLlBNS5gVNB3mBzs3gamJORx6FeTtYvkfvpgyOlpsI/PanOAkQm3JFD8S/MUwJCDU0 0NA/6FR Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Markus Elfring Date: Sat, 17 Sep 2016 14:10:47 +0200 Four checks could be repeated by the d40_hw_detect_init() function during error handling even if the passed variables contained a null pointer. * Adjust jump targets according to the Linux coding style convention. * Call the interface "iounmap" only once at the end. * Delete the repeated checks which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- drivers/dma/ste_dma40.c | 67 ++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c index f813056..c680dd3 100644 --- a/drivers/dma/ste_dma40.c +++ b/drivers/dma/ste_dma40.c @@ -3158,27 +3158,27 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) clk = clk_get(&pdev->dev, NULL); if (IS_ERR(clk)) { d40_err(&pdev->dev, "No matching clock found\n"); - goto failure; + goto check_prepare_enabled; } clk_ret = clk_prepare_enable(clk); if (clk_ret) { d40_err(&pdev->dev, "Failed to prepare/enable clock\n"); - goto failure; + goto disable_unprepare; } /* Get IO for DMAC base address */ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "base"); if (!res) - goto failure; + goto disable_unprepare; if (request_mem_region(res->start, resource_size(res), D40_NAME " I/O base") == NULL) - goto failure; + goto release_region; virtbase = ioremap(res->start, resource_size(res)); if (!virtbase) - goto failure; + goto release_region; /* This is just a regular AMBA PrimeCell ID actually */ for (pid = 0, i = 0; i < 4; i++) @@ -3190,13 +3190,13 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) if (cid != AMBA_CID) { d40_err(&pdev->dev, "Unknown hardware! No PrimeCell ID\n"); - goto failure; + goto unmap_io; } if (AMBA_MANF_BITS(pid) != AMBA_VENDOR_ST) { d40_err(&pdev->dev, "Unknown designer! Got %x wanted %x\n", AMBA_MANF_BITS(pid), AMBA_VENDOR_ST); - goto failure; + goto unmap_io; } /* * HW revision: @@ -3210,7 +3210,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) rev = AMBA_REV_BITS(pid); if (rev < 2) { d40_err(&pdev->dev, "hardware revision: %d is not supported", rev); - goto failure; + goto unmap_io; } /* The number of physical channels on this HW */ @@ -3236,7 +3236,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) sizeof(struct d40_chan), GFP_KERNEL); if (base == NULL) - goto failure; + goto unmap_io; base->rev = rev; base->clk = clk; @@ -3285,63 +3285,62 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) sizeof(*base->phy_res), GFP_KERNEL); if (!base->phy_res) - goto failure; + goto free_base; base->lookup_phy_chans = kcalloc(num_phy_chans, sizeof(*base->lookup_phy_chans), GFP_KERNEL); if (!base->lookup_phy_chans) - goto failure; + goto free_phy_res; base->lookup_log_chans = kcalloc(num_log_chans, sizeof(*base->lookup_log_chans), GFP_KERNEL); if (!base->lookup_log_chans) - goto failure; + goto free_phy_chans; base->reg_val_backup_chan = kmalloc_array(base->num_phy_chans, sizeof(d40_backup_regs_chan), GFP_KERNEL); if (!base->reg_val_backup_chan) - goto failure; + goto free_log_chans; base->lcla_pool.alloc_map = kcalloc(num_phy_chans * D40_LCLA_LINK_PER_EVENT_GRP, sizeof(*base->lcla_pool.alloc_map), GFP_KERNEL); if (!base->lcla_pool.alloc_map) - goto failure; + goto free_backup_chan; base->desc_slab = kmem_cache_create(D40_NAME, sizeof(struct d40_desc), 0, SLAB_HWCACHE_ALIGN, NULL); if (base->desc_slab == NULL) - goto failure; + goto free_map; return base; - -failure: + free_map: + kfree(base->lcla_pool.alloc_map); + free_backup_chan: + kfree(base->reg_val_backup_chan); + free_log_chans: + kfree(base->lookup_log_chans); + free_phy_chans: + kfree(base->lookup_phy_chans); + free_phy_res: + kfree(base->phy_res); + free_base: + kfree(base); + unmap_io: + iounmap(virtbase); + release_region: + release_mem_region(res->start, resource_size(res)); + check_prepare_enabled: if (!clk_ret) + disable_unprepare: clk_disable_unprepare(clk); if (!IS_ERR(clk)) clk_put(clk); - if (virtbase) - iounmap(virtbase); - if (res) - release_mem_region(res->start, - resource_size(res)); - if (virtbase) - iounmap(virtbase); - - if (base) { - kfree(base->lcla_pool.alloc_map); - kfree(base->reg_val_backup_chan); - kfree(base->lookup_log_chans); - kfree(base->lookup_phy_chans); - kfree(base->phy_res); - kfree(base); - } - return NULL; } -- 2.10.0