linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: Kalle Valo <kvalo@codeaurora.org>,
	Solomon Peachy <pizza@shaftnet.org>,
	netdev@vger.kernel.org, linux-wireless@vger.kernel.org
Cc: LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Julia Lawall <julia.lawall@lip6.fr>
Subject: [PATCH 2/2] CW1200: Less function calls in cw1200_load_firmware_cw1200() after error detection
Date: Wed, 04 Feb 2015 17:48:42 +0100	[thread overview]
Message-ID: <54D24D6A.2020404@users.sourceforge.net> (raw)
In-Reply-To: <54D24CC3.9010006@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 4 Feb 2015 17:28:41 +0100

The functions kfree() and release_firmware() were called in a few cases
by the cw1200_load_firmware_cw1200() function during error handling even if
the passed variables contained still a null pointer.

Corresponding implementation details could be improved by adjustments for
jump targets.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/wireless/cw1200/fwio.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wireless/cw1200/fwio.c b/drivers/net/wireless/cw1200/fwio.c
index 581dfde..30e7646 100644
--- a/drivers/net/wireless/cw1200/fwio.c
+++ b/drivers/net/wireless/cw1200/fwio.c
@@ -66,25 +66,31 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	do { \
 		ret = cw1200_apb_write_32(priv, CW1200_APB(reg), (val)); \
 		if (ret < 0) \
-			goto error; \
+			goto exit; \
+	} while (0)
+#define APB_WRITE2(reg, val) \
+	do { \
+		ret = cw1200_apb_write_32(priv, CW1200_APB(reg), (val)); \
+		if (ret < 0) \
+			goto free_buffer; \
 	} while (0)
 #define APB_READ(reg, val) \
 	do { \
 		ret = cw1200_apb_read_32(priv, CW1200_APB(reg), &(val)); \
 		if (ret < 0) \
-			goto error; \
+			goto free_buffer; \
 	} while (0)
 #define REG_WRITE(reg, val) \
 	do { \
 		ret = cw1200_reg_write_32(priv, (reg), (val)); \
 		if (ret < 0) \
-			goto error; \
+			goto exit; \
 	} while (0)
 #define REG_READ(reg, val) \
 	do { \
 		ret = cw1200_reg_read_32(priv, (reg), &(val)); \
 		if (ret < 0) \
-			goto error; \
+			goto exit; \
 	} while (0)
 
 	switch (priv->hw_revision) {
@@ -142,14 +148,14 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	ret = request_firmware(&firmware, fw_path, priv->pdev);
 	if (ret) {
 		pr_err("Can't load firmware file %s.\n", fw_path);
-		goto error;
+		goto exit;
 	}
 
 	buf = kmalloc(DOWNLOAD_BLOCK_SIZE, GFP_KERNEL | GFP_DMA);
 	if (!buf) {
 		pr_err("Can't allocate firmware load buffer.\n");
 		ret = -ENOMEM;
-		goto error;
+		goto firmware_release;
 	}
 
 	/* Check if the bootloader is ready */
@@ -163,7 +169,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	if (val32 != DOWNLOAD_I_AM_HERE) {
 		pr_err("Bootloader is not ready.\n");
 		ret = -ETIMEDOUT;
-		goto error;
+		goto free_buffer;
 	}
 
 	/* Calculcate number of download blocks */
@@ -171,7 +177,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 
 	/* Updating the length in Download Ctrl Area */
 	val32 = firmware->size; /* Explicit cast from size_t to u32 */
-	APB_WRITE(DOWNLOAD_IMAGE_SIZE_REG, val32);
+	APB_WRITE2(DOWNLOAD_IMAGE_SIZE_REG, val32);
 
 	/* Firmware downloading loop */
 	for (block = 0; block < num_blocks; block++) {
@@ -183,7 +189,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 		if (val32 != DOWNLOAD_PENDING) {
 			pr_err("Bootloader reported error %d.\n", val32);
 			ret = -EIO;
-			goto error;
+			goto free_buffer;
 		}
 
 		/* loop until put - get <= 24K */
@@ -198,7 +204,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 		if ((put - get) > (DOWNLOAD_FIFO_SIZE - DOWNLOAD_BLOCK_SIZE)) {
 			pr_err("Timeout waiting for FIFO.\n");
 			ret = -ETIMEDOUT;
-			goto error;
+			goto free_buffer;
 		}
 
 		/* calculate the block size */
@@ -220,12 +226,12 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 		if (ret < 0) {
 			pr_err("Can't write firmware block @ %d!\n",
 			       put & (DOWNLOAD_FIFO_SIZE - 1));
-			goto error;
+			goto free_buffer;
 		}
 
 		/* update the put register */
 		put += block_size;
-		APB_WRITE(DOWNLOAD_PUT_REG, put);
+		APB_WRITE2(DOWNLOAD_PUT_REG, put);
 	} /* End of firmware download loop */
 
 	/* Wait for the download completion */
@@ -238,18 +244,21 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	if (val32 != DOWNLOAD_SUCCESS) {
 		pr_err("Wait for download completion failed: 0x%.8X\n", val32);
 		ret = -ETIMEDOUT;
-		goto error;
+		goto free_buffer;
 	} else {
 		pr_info("Firmware download completed.\n");
 		ret = 0;
 	}
 
-error:
+free_buffer:
 	kfree(buf);
+firmware_release:
 	release_firmware(firmware);
+exit:
 	return ret;
 
 #undef APB_WRITE
+#undef APB_WRITE2
 #undef APB_READ
 #undef REG_WRITE
 #undef REG_READ
-- 
2.2.2


  parent reply	other threads:[~2015-02-04 16:48 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5307CAA2.8060406@users.sourceforge.net>
     [not found] ` <alpine.DEB.2.02.1402212321410.2043@localhost6.localdomain6>
     [not found]   ` <530A086E.8010901@users.sourceforge.net>
     [not found]     ` <alpine.DEB.2.02.1402231635510.1985@localhost6.localdomain6>
     [not found]       ` <530A72AA.3000601@users.sourceforge.net>
     [not found]         ` <alpine.DEB.2.02.1402240658210.2090@localhost6.localdomain6>
     [not found]           ` <530B5FB6.6010207@users.sourceforge.net>
     [not found]             ` <alpine.DEB.2.10.1402241710370.2074@hadrien>
     [not found]               ` <530C5E18.1020800@users.sourceforge.net>
     [not found]                 ` <alpine.DEB.2.10.1402251014170.2080@hadrien>
     [not found]                   ` <530CD2C4.4050903@users.sourceforge.net>
     [not found]                     ` <alpine.DEB.2.10.1402251840450.7035@hadrien>
     [not found]                       ` <530CF8FF.8080600@users.sourceforge.net>
     [not found]                         ` <alpine.DEB.2.02.1402252117150.2047@localhost6.localdomain6>
     [not found]                           ` <530DD06F.4090703@users.sourceforge.net>
     [not found]                             ` <alpine.DEB.2.02.1402262129250.2221@localhost6.localdomain6>
     [not found]                               ` <5317A59D.4@users.sourceforge.net>
2014-11-20 15:50                                 ` [PATCH 1/1] net: brcm80211: Deletion of unnecessary checks before two function calls SF Markus Elfring
2014-11-20 18:04                                   ` Arend van Spriel
2015-11-06  7:58                                     ` [PATCH] net: brcm80211: Delete an unnecessary check before the function call "release_firmware" SF Markus Elfring
2015-11-11  9:18                                       ` Arend van Spriel
2015-11-26 12:04                                       ` brcm80211: Delete an unnecessary check before the function call"release_firmware" Kalle Valo
2015-02-04 16:45                                 ` [PATCH 0/2] CW1200: Deletion of an unnecessary check SF Markus Elfring
2015-02-04 16:47                                   ` [PATCH 1/2] CW1200: Delete an unnecessary check before the function call "release_firmware" SF Markus Elfring
2015-02-06  6:49                                     ` [1/2] cw1200: " Kalle Valo
2015-02-04 16:48                                   ` SF Markus Elfring [this message]
2015-02-04 17:54                                 ` [PATCH] ath9k: Delete an unnecessary check before the function call "relay_close" SF Markus Elfring
2015-02-06  6:50                                   ` ath9k: Delete an unnecessary check before the function call"relay_close" Kalle Valo
2015-02-04 18:33                                 ` [PATCH] ath10k: Delete unnecessary checks before the function call "release_firmware" SF Markus Elfring
2015-03-04 12:06                                   ` Kalle Valo
2015-02-04 18:56                                 ` [PATCH] orinoco: Delete an unnecessary check before the function call "kfree" SF Markus Elfring
2015-02-06  6:51                                   ` Kalle Valo
2015-02-04 19:10                                 ` [PATCH] HostAP: " SF Markus Elfring
2015-02-06  6:52                                   ` hostap: " Kalle Valo
2015-02-04 19:40                                 ` [PATCH] net: brcm80211: Delete unnecessary checks before two function calls SF Markus Elfring
2015-02-06  6:53                                   ` Kalle Valo
2015-06-27 14:29                                 ` [PATCH 0/2] staging: wilc1000: Deletion of two unnecessary checks SF Markus Elfring
2015-06-27 14:36                                   ` [PATCH 1/2] staging: wilc1000: Delete unnecessary checks before two function calls SF Markus Elfring
2015-07-07  2:31                                     ` Greg Kroah-Hartman
2015-07-07  6:21                                       ` Clarification for the use of additional fields in the message body SF Markus Elfring
2015-07-07  6:40                                         ` Frans Klaver
2015-07-07  7:54                                           ` SF Markus Elfring
2015-07-07  8:23                                             ` Frans Klaver
2015-07-07 11:53                                               ` SF Markus Elfring
2015-07-07 14:13                                                 ` Frans Klaver
2015-07-07 16:15                                                   ` SF Markus Elfring
2015-07-07 23:43                                                     ` Julian Calaby
2015-07-08  7:09                                                       ` SF Markus Elfring
2015-07-08  7:36                                                         ` Julian Calaby
2015-07-08  9:28                                                           ` SF Markus Elfring
2015-07-08 11:05                                                             ` Julian Calaby
2015-07-08 13:46                                                               ` SF Markus Elfring
2015-07-08 23:47                                                                 ` Julian Calaby
2015-07-08 15:03                                                               ` Theodore Ts'o
2015-07-08 15:27                                                                 ` SF Markus Elfring
2015-07-09 16:51                                                                   ` Theodore Ts'o
2015-06-27 14:37                                   ` [PATCH 2/2] staging: wilc1000: One function call less in mac_ioctl() after error detection SF Markus Elfring
2015-06-27 16:21                                     ` Julia Lawall
2015-07-07  2:31                                     ` Greg Kroah-Hartman
2015-07-08  8:40                                       ` SF Markus Elfring
2016-07-24 20:15                                   ` [PATCH 0/3] staging: wilc1000: Fine-tuning for two function implementations SF Markus Elfring
2016-07-24 20:20                                     ` [PATCH 1/3] staging: wilc1000: Delete an unnecessary check before the function call "release_firmware" SF Markus Elfring
2016-07-24 20:22                                     ` [PATCH 2/3] staging: wilc1000: One function call less in mac_ioctl() after error detection SF Markus Elfring
2016-07-28 12:02                                       ` Julian Calaby
2016-07-24 20:23                                     ` [PATCH 3/3] staging: wilc1000: Reduce scope for a few variables in mac_ioctl() SF Markus Elfring
2015-11-14 21:50                                 ` [PATCH] NFC-nci: Delete unnecessary checks before the function call "kfree_skb" SF Markus Elfring
2015-11-16 12:18                                 ` [PATCH] rtlwifi: " SF Markus Elfring
2015-11-26 13:01                                   ` rtlwifi: Delete unnecessary checks before the function call"kfree_skb" Kalle Valo

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=54D24D6A.2020404@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=julia.lawall@lip6.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pizza@shaftnet.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).