All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tobin C. Harding" <me@tobin.cc>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linux Driver Project Developer List
	<driverdev-devel@linuxdriverproject.org>,
	Wolfram Sang <wsa@the-dreams.de>
Subject: [PATCH 1/3] staging: ks7010: invert conditional, reduce indentation
Date: Tue, 28 Mar 2017 17:45:13 +1100	[thread overview]
Message-ID: <1490683515-16432-2-git-send-email-me@tobin.cc> (raw)
In-Reply-To: <1490683515-16432-1-git-send-email-me@tobin.cc>

Function contains a large block of code that is guarded by an if
statement. There is some remaining code after block that does final
clean up of driver. If we add a goto label labeling the final cleanup
code we can invert the if statement and jump to goto label. This
allows the subsequent code to be indented one level less while not
changing the program logic.

Add goto label. Invert if statement conditional, jump to label if new
conditional evaluates to true. Reduce indentation of subsequent code
by one level. Do not change the program logic.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
 drivers/staging/ks7010/ks7010_sdio.c | 91 +++++++++++++++++++-----------------
 1 file changed, 47 insertions(+), 44 deletions(-)

diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c
index b16618b..0f5ff68 100644
--- a/drivers/staging/ks7010/ks7010_sdio.c
+++ b/drivers/staging/ks7010/ks7010_sdio.c
@@ -1067,6 +1067,7 @@ static void ks7010_sdio_remove(struct sdio_func *func)
 	int ret;
 	struct ks_sdio_card *card;
 	struct ks_wlan_private *priv;
+	struct net_device *netdev;
 
 	DPRINTK(1, "ks7010_sdio_remove()\n");
 
@@ -1077,60 +1078,62 @@ static void ks7010_sdio_remove(struct sdio_func *func)
 
 	DPRINTK(1, "priv = card->priv\n");
 	priv = card->priv;
-	if (priv) {
-		struct net_device *netdev = priv->net_dev;
+	if (!priv)
+		goto out;
 
-		ks_wlan_net_stop(netdev);
-		DPRINTK(1, "ks_wlan_net_stop\n");
+	netdev = priv->net_dev;
 
-		/* interrupt disable */
-		sdio_claim_host(func);
-		sdio_writeb(func, 0, INT_ENABLE, &ret);
-		sdio_writeb(func, 0xff, INT_PENDING, &ret);
-		sdio_release_host(func);
-		DPRINTK(1, "interrupt disable\n");
+	ks_wlan_net_stop(netdev);
+	DPRINTK(1, "ks_wlan_net_stop\n");
 
-		/* send stop request to MAC */
-		{
-			struct hostif_stop_request_t *pp;
+	/* interrupt disable */
+	sdio_claim_host(func);
+	sdio_writeb(func, 0, INT_ENABLE, &ret);
+	sdio_writeb(func, 0xff, INT_PENDING, &ret);
+	sdio_release_host(func);
+	DPRINTK(1, "interrupt disable\n");
 
-			pp = kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL);
-			if (!pp) {
-				DPRINTK(3, "allocate memory failed..\n");
-				return;	/* to do goto ni suru */
-			}
-			pp->header.size =
-			    cpu_to_le16((uint16_t)
-					(sizeof(*pp) -
-					 sizeof(pp->header.size)));
-			pp->header.event = cpu_to_le16((uint16_t)HIF_STOP_REQ);
-
-			sdio_claim_host(func);
-			write_to_device(priv, (unsigned char *)pp,
-					hif_align_size(sizeof(*pp)));
-			sdio_release_host(func);
-			kfree(pp);
-		}
-		DPRINTK(1, "STOP Req\n");
+	/* send stop request to MAC */
+	{
+		struct hostif_stop_request_t *pp;
 
-		if (priv->ks_wlan_hw.ks7010sdio_wq) {
-			flush_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
-			destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
+		pp = kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL);
+		if (!pp) {
+			DPRINTK(3, "allocate memory failed..\n");
+			return;	/* to do goto ni suru */
 		}
-		DPRINTK(1,
-			"destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);\n");
+		pp->header.size =
+			cpu_to_le16((uint16_t)
+				(sizeof(*pp) -
+					sizeof(pp->header.size)));
+		pp->header.event = cpu_to_le16((uint16_t)HIF_STOP_REQ);
 
-		hostif_exit(priv);
-		DPRINTK(1, "hostif_exit\n");
-
-		unregister_netdev(netdev);
+		sdio_claim_host(func);
+		write_to_device(priv, (unsigned char *)pp,
+				hif_align_size(sizeof(*pp)));
+		sdio_release_host(func);
+		kfree(pp);
+	}
+	DPRINTK(1, "STOP Req\n");
 
-		trx_device_exit(priv);
-		kfree(priv->ks_wlan_hw.read_buf);
-		free_netdev(priv->net_dev);
-		card->priv = NULL;
+	if (priv->ks_wlan_hw.ks7010sdio_wq) {
+		flush_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
+		destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
 	}
+	DPRINTK(1,
+		"destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);\n");
+
+	hostif_exit(priv);
+	DPRINTK(1, "hostif_exit\n");
+
+	unregister_netdev(netdev);
+
+	trx_device_exit(priv);
+	kfree(priv->ks_wlan_hw.read_buf);
+	free_netdev(priv->net_dev);
+	card->priv = NULL;
 
+out:
 	sdio_claim_host(func);
 	sdio_release_irq(func);
 	DPRINTK(1, "sdio_release_irq()\n");
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply	other threads:[~2017-03-28  6:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-28  6:45 [PATCH 0/4] staging: ks7010: refactor ks7010_sdio_remove() Tobin C. Harding
2017-03-28  6:45 ` Tobin C. Harding [this message]
2017-03-28  6:45 ` [PATCH 2/3] staging: ks7010: factor out send stop request Tobin C. Harding
2017-03-28  6:45 ` [PATCH 3/3] staging: ks7010: remove extraneous newlines Tobin C. Harding

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=1490683515-16432-2-git-send-email-me@tobin.cc \
    --to=me@tobin.cc \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=wsa@the-dreams.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.