* [PATCH] mmc: Use switch() instead of if/else if in mmc_blk_issue_rq.
@ 2011-08-20 14:50 Namjae Jeon
2011-08-20 15:12 ` Chris Ball
0 siblings, 1 reply; 2+ messages in thread
From: Namjae Jeon @ 2011-08-20 14:50 UTC (permalink / raw)
To: linux-mmc; +Cc: cjb, linus.walleij, linux-kernel, 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.
Signed-off-by: Namjae Jeon <linkinjeon@gmail.com>
---
drivers/mmc/card/block.c | 38 +++++++++++++++++++++++---------------
1 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 1ff5486..fe9dd89 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -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 */
--
1.7.4.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mmc: Use switch() instead of if/else if in mmc_blk_issue_rq.
2011-08-20 14:50 [PATCH] mmc: Use switch() instead of if/else if in mmc_blk_issue_rq Namjae Jeon
@ 2011-08-20 15:12 ` Chris Ball
0 siblings, 0 replies; 2+ messages in thread
From: Chris Ball @ 2011-08-20 15:12 UTC (permalink / raw)
To: Namjae Jeon; +Cc: linux-mmc, linus.walleij, linux-kernel
Hi,
On Sat, Aug 20 2011, Namjae Jeon wrote:
> 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.
>
> Signed-off-by: Namjae Jeon <linkinjeon@gmail.com>
> ---
> drivers/mmc/card/block.c | 38 +++++++++++++++++++++++---------------
> 1 files changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
> index 1ff5486..fe9dd89 100644
> --- a/drivers/mmc/card/block.c
> +++ b/drivers/mmc/card/block.c
> @@ -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);
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.
--
Chris Ball <cjb@laptop.org> <http://printf.net/>
One Laptop Per Child
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-08-20 15:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-20 14:50 [PATCH] mmc: Use switch() instead of if/else if in mmc_blk_issue_rq Namjae Jeon
2011-08-20 15:12 ` Chris Ball
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox