linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: elfring@users.sourceforge.net (SF Markus Elfring)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 08/24] ste_dma40: Less checks in d40_hw_detect_init() after error detection
Date: Sat, 17 Sep 2016 17:16:11 +0200	[thread overview]
Message-ID: <e1895f0f-187a-976d-5064-e3022a2c9ea4@users.sourceforge.net> (raw)
In-Reply-To: <92810066-69b6-94e7-dcec-a28594b1328f@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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

  parent reply	other threads:[~2016-09-17 15:16 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <566ABCD9.1060404@users.sourceforge.net>
2015-12-31 21:47 ` [PATCH] net-thunder: One check less in nicvf_register_interrupts() after error detection SF Markus Elfring
2016-01-07 11:07   ` Robert Richter
2016-01-07 19:30     ` SF Markus Elfring
2016-01-07 19:44       ` Joe Perches
2016-01-07 19:56         ` SF Markus Elfring
2016-01-07 19:59           ` Joe Perches
2016-01-07 20:07             ` SF Markus Elfring
2016-01-07 20:28               ` Joe Perches
2016-01-07 20:38                 ` SF Markus Elfring
2016-01-07 20:42                   ` Joe Perches
2016-09-17 15:05 ` [PATCH 00/24] ste_dma40: Fine-tuning for several function implementations SF Markus Elfring
2016-09-17 15:07   ` [PATCH 01/24] ste_dma40: Use kmalloc_array() in d40_lcla_allocate() SF Markus Elfring
2016-09-17 15:08   ` [PATCH 02/24] ste_dma40: Return directly after a failed kmalloc_array() SF Markus Elfring
2016-09-17 15:09   ` [PATCH 03/24] ste_dma40: Rename a jump label in d40_lcla_allocate() SF Markus Elfring
2016-09-17 15:10   ` [PATCH 04/24] ste_dma40: Move an assignment " SF Markus Elfring
2016-09-17 15:11   ` [PATCH 05/24] ste_dma40: Improve a size determination in d40_of_probe() SF Markus Elfring
2016-09-17 15:12   ` [PATCH 06/24] ste_dma40: Replace four kzalloc() calls by kcalloc() in d40_hw_detect_init() SF Markus Elfring
2016-09-17 15:15   ` [PATCH 07/24] ste_dma40: Use kmalloc_array() " SF Markus Elfring
2016-09-17 15:16   ` SF Markus Elfring [this message]
2016-09-17 15:17   ` [PATCH 09/24] ste_dma40: Delete unnecessary variable initialisations " SF Markus Elfring
2016-09-17 15:18   ` [PATCH 10/24] ste_dma40: Adjust the position of a jump label in d40_probe() SF Markus Elfring
2016-09-17 15:19   ` [PATCH 11/24] ste_dma40: Rename " SF Markus Elfring
2016-09-17 15:20   ` [PATCH 12/24] ste_dma40: Rename jump labels in d40_dmaengine_init() SF Markus Elfring
2016-09-17 15:22   ` [PATCH 13/24] ste_dma40: Rename a jump label in d40_alloc_chan_resources() SF Markus Elfring
2016-09-17 15:23   ` [PATCH 14/24] ste_dma40: One check less in d40_prep_sg() after error detection SF Markus Elfring
2016-09-17 15:25   ` [PATCH 15/24] ste_dma40: Move two assignments in d40_prep_sg() SF Markus Elfring
2016-09-17 15:26   ` [PATCH 16/24] ste_dma40: Rename a jump label in d40_prep_desc() SF Markus Elfring
2016-09-17 15:27   ` [PATCH 17/24] ste_dma40: Move an assignment " SF Markus Elfring
2016-09-17 15:30   ` [PATCH 18/24] ste_dma40: Rename a jump label in d40_is_paused() SF Markus Elfring
2016-09-17 15:31   ` [PATCH 19/24] ste_dma40: Rename a jump label in d40_free_dma() SF Markus Elfring
2016-09-17 15:32   ` [PATCH 20/24] ste_dma40: Rename a jump label in d40_alloc_mask_free() SF Markus Elfring
2016-09-17 15:33   ` [PATCH 21/24] ste_dma40: Rename jump labels in d40_alloc_mask_set() SF Markus Elfring
2016-09-17 15:34   ` [PATCH 22/24] ste_dma40: Rename a jump label in dma_tasklet() SF Markus Elfring
2016-09-17 15:35   ` [PATCH 23/24] ste_dma40: Rename a jump label in __d40_execute_command_phy() SF Markus Elfring
2016-09-17 15:36   ` [PATCH 24/24] ste_dma40: Rename a jump label in d40_log_lli_to_lcxa() SF Markus Elfring
2016-09-23  9:41   ` [PATCH 00/24] ste_dma40: Fine-tuning for several function implementations Linus Walleij
2016-09-26 17:39   ` Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e1895f0f-187a-976d-5064-e3022a2c9ea4@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).