Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1198349

Re: [PATCH] Avoid compiler warning by storing the result of rq_data_dir() in an int variable

From Hagen Paul Pfeifer <hagen@jauu.net>
Newsgroups linux.kernel
Subject Re: [PATCH] Avoid compiler warning by storing the result of rq_data_dir() in an int variable
Date 2015-08-02 16:00 +0200
Message-ID <pT1XY-5NL-13@gated-at.bofh.it> (permalink)
References <pSYQq-1h9-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


* Tomer Barletz | 2015-08-02 03:36:52 [-0700]:

>With gcc 5.1 I get:
>warning: switch condition has boolean value [-Wswitch-bool]
>
>Signed-off-by: Tomer Barletz <barletz@gmail.com>
>---
> drivers/mtd/mtd_blkdevs.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
>index 41acc50..8c3715c 100644
>--- a/drivers/mtd/mtd_blkdevs.c
>+++ b/drivers/mtd/mtd_blkdevs.c
>@@ -79,6 +79,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
> {
> 	unsigned long block, nsect;
> 	char *buf;
>+	int rq;
> 
> 	block = blk_rq_pos(req) << 9 >> tr->blkshift;
> 	nsect = blk_rq_cur_bytes(req) >> tr->blkshift;
>@@ -97,7 +98,8 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
> 	if (req->cmd_flags & REQ_DISCARD)
> 		return tr->discard(dev, block, nsect);
> 
>-	switch(rq_data_dir(req)) {
>+	rq = rq_data_dir(req);
>+	switch(rq) {

Gcc warning seems over the top here, but when then the coding guideline should
be meet:

switch (rw) {
[..]

On the other hand, rq_data_dir() *could* be simplified to:

#define rq_data_dir(rq)         (((rq)->cmd_flags & 1)

Or just re-code the construct into a if else construct.

if (rw == READ) {
[...]
} else {
[...]
}

The default branch is superfluous anyway here.

Hagen
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] Avoid compiler warning by storing the result of rq_data_dir() in an int variable Tomer Barletz <barletz@gmail.com> - 2015-08-02 12:40 +0200
  Re: [PATCH] Avoid compiler warning by storing the result of  rq_data_dir() in an int variable Hagen Paul Pfeifer <hagen@jauu.net> - 2015-08-02 16:00 +0200
    [PATCH] Avoid compiler warning by storing the result of rq_data_dir() in an int variable Tomer Barletz <barletz@gmail.com> - 2015-08-03 08:00 +0200

csiph-web