[PATCH 2/3] staging: ks7010: factor out send stop request

Tobin C. Harding me at tobin.cc
Tue Mar 28 06:45:14 UTC 2017


Function contains a block of code combined as a compound
statement. This would be better factored out into a separate function.

Factor compound statement out into a separate function.

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 drivers/staging/ks7010/ks7010_sdio.c | 46 ++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c
index 0f5ff68..a820371 100644
--- a/drivers/staging/ks7010/ks7010_sdio.c
+++ b/drivers/staging/ks7010/ks7010_sdio.c
@@ -1062,6 +1062,29 @@ static int ks7010_sdio_probe(struct sdio_func *func,
 	return -ENODEV;
 }
 
+/* send stop request to MAC */
+static int send_stop_request(struct ks_sdio_card *card)
+{
+	struct hostif_stop_request_t *pp;
+	size_t size;
+
+	pp = kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL);
+	if (!pp)
+		return -ENOMEM;
+
+	size = sizeof(*pp) - sizeof(pp->header.size);
+	pp->header.size = cpu_to_le16((uint16_t)size);
+	pp->header.event = cpu_to_le16((uint16_t)HIF_STOP_REQ);
+
+	sdio_claim_host(card->func);
+	write_to_device(card->priv, (unsigned char *)pp,
+			hif_align_size(sizeof(*pp)));
+	sdio_release_host(card->func);
+
+	kfree(pp);
+	return 0;
+}
+
 static void ks7010_sdio_remove(struct sdio_func *func)
 {
 	int ret;
@@ -1093,27 +1116,10 @@ static void ks7010_sdio_remove(struct sdio_func *func)
 	sdio_release_host(func);
 	DPRINTK(1, "interrupt disable\n");
 
-	/* send stop request to MAC */
-	{
-		struct hostif_stop_request_t *pp;
+	ret = send_stop_request(card);
+	if (ret)
+		return;
 
-		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");
 
 	if (priv->ks_wlan_hw.ks7010sdio_wq) {
-- 
2.7.4



More information about the devel mailing list