Skip to contentSkip to conversation

mmc: Use switch() instead of if/else if in mmc_blk_issue_rq.

PATCH In review Namjae Jeon 2 participants 2 messages Aug 20, 2011 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: Use switch() instead of if/else if in mmc_blk_issue_rq.

This uses a switch statement instead of if/else if statements.
It will make to improve clarity and scalability, and offer faster execution through compiler optimization than if/else if statements.

---
 drivers/mmc/card/block.c |   38 +++++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 15 deletions(-)
drivers/mmc/card/block.c +23 -15
index 1ff5486..fe9dd89 100644
@@ -1191,23 +1191,31 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
 		goto out;
 	}
 
-	if (req && req->cmd_flags & REQ_DISCARD) {
-		/* complete ongoing async transfer before issuing discard */
-		if (card->host->areq)
-			mmc_blk_issue_rw_rq(mq, NULL);
-		if (req->cmd_flags & REQ_SECURE)
-			ret = mmc_blk_issue_secdiscard_rq(mq, req);
-		else
+	if (req) {
+		switch(req->cmd_flags) {
+		case REQ_DISCARD:
+			/* complete ongoing async transfer before issuing discard */
+			if (card->host->areq)
+				mmc_blk_issue_rw_rq(mq, NULL);
 			ret = mmc_blk_issue_discard_rq(mq, req);
-	} else if (req && req->cmd_flags & REQ_FLUSH) {
-		/* complete ongoing async transfer before issuing flush */
-		if (card->host->areq)
-			mmc_blk_issue_rw_rq(mq, NULL);
-		ret = mmc_blk_issue_flush(mq, req);
-	} else {
+			break;
+		case REQ_DISCARD | REQ_SECURE:
+			/* complete ongoing async transfer before issuing discard */
+			if (card->host->areq)
+				mmc_blk_issue_rw_rq(mq, NULL);
+			ret = mmc_blk_issue_secdiscard_rq(mq, req);
+			break;
+		case REQ_FLUSH:
+			/* complete ongoing async transfer before issuing discard */
+			if (card->host->areq)
+				mmc_blk_issue_rw_rq(mq, NULL);
+			ret = mmc_blk_issue_flush(mq, req);
+			break;
+		}
+	}		
+	else
 		ret = mmc_blk_issue_rw_rq(mq, req);
-	}
-
+			
 out:
 	if (!req)
 		/* release host only when there are no more requests */
Signature · 1 line
1.7.4.4
#1 lore raw

Hi,

Quoted 19 lines · Namjae Jeon

This uses a switch statement instead of if/else if statements.
It will make to improve clarity and scalability, and offer faster execution through compiler optimization than if/else if statements.

---
 drivers/mmc/card/block.c |   38 +++++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 15 deletions(-)
drivers/mmc/card/block.c +0 -3
index 1ff5486..fe9dd89 100644
@@ -1191,23 +1191,31 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
 		goto out;
 	}
 
-	if (req && req->cmd_flags & REQ_DISCARD) {
-		/* complete ongoing async transfer before issuing discard */
-		if (card->host->areq)

drivers/mmc/card/block.c static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) · line 1199

Quoted 10 lines
drivers/mmc/card/block.c +6 -4
-			mmc_blk_issue_rw_rq(mq, NULL);
-		if (req->cmd_flags & REQ_SECURE)
-			ret = mmc_blk_issue_secdiscard_rq(mq, req);
-		else
+	if (req) {
+		switch(req->cmd_flags) {
+		case REQ_DISCARD:
+			/* complete ongoing async transfer before issuing discard */
+			if (card->host->areq)
+				mmc_blk_issue_rw_rq(mq, NULL);

But it doesn't work, because you've changed the test for "req->cmd_flags & REQ_DISCARD" into a test for "req->cmd_flags == REQ_DISCARD".

- Chris.

Signature · 2 lines
Chris Ball   <[email protected]>   <http://printf.net/>
One Laptop Per Child