linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Avoid compiler warning by storing the result of rq_data_dir() in an int variable
@ 2015-08-02 10:36 Tomer Barletz
  2015-08-02 13:48 ` Hagen Paul Pfeifer
  0 siblings, 1 reply; 5+ messages in thread
From: Tomer Barletz @ 2015-08-02 10:36 UTC (permalink / raw)
  To: dwmw2, computersforpeace; +Cc: linux-mtd, linux-kernel, Tomer Barletz

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) {
 	case READ:
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->readsect(dev, block, buf))
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid compiler warning by storing the result of rq_data_dir() in an int variable
  2015-08-02 10:36 [PATCH] Avoid compiler warning by storing the result of rq_data_dir() in an int variable Tomer Barletz
@ 2015-08-02 13:48 ` Hagen Paul Pfeifer
  2015-08-03  5:49   ` Tomer Barletz
  2015-08-05  4:00   ` [PATCH] mtd: Fix switch-bool compilation warning Tomer Barletz
  0 siblings, 2 replies; 5+ messages in thread
From: Hagen Paul Pfeifer @ 2015-08-02 13:48 UTC (permalink / raw)
  To: Tomer Barletz; +Cc: dwmw2, computersforpeace, linux-mtd, linux-kernel

* 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Avoid compiler warning by storing the result of rq_data_dir() in an int variable
  2015-08-02 13:48 ` Hagen Paul Pfeifer
@ 2015-08-03  5:49   ` Tomer Barletz
  2015-08-05  4:00   ` [PATCH] mtd: Fix switch-bool compilation warning Tomer Barletz
  1 sibling, 0 replies; 5+ messages in thread
From: Tomer Barletz @ 2015-08-03  5:49 UTC (permalink / raw)
  To: dwmw2, computersforpeace; +Cc: linux-mtd, linux-kernel, Tomer Barletz

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 | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 41acc50..8830475 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -97,14 +97,13 @@ 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)) {
-	case READ:
+	if (rq_data_dir(req) == READ) {
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->readsect(dev, block, buf))
 				return -EIO;
 		rq_flush_dcache_pages(req);
 		return 0;
-	case WRITE:
+	} else {
 		if (!tr->writesect)
 			return -EIO;
 
@@ -113,9 +112,6 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 			if (tr->writesect(dev, block, buf))
 				return -EIO;
 		return 0;
-	default:
-		printk(KERN_NOTICE "Unknown request %u\n", rq_data_dir(req));
-		return -EIO;
 	}
 }
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] mtd: Fix switch-bool compilation warning
  2015-08-02 13:48 ` Hagen Paul Pfeifer
  2015-08-03  5:49   ` Tomer Barletz
@ 2015-08-05  4:00   ` Tomer Barletz
  2015-08-25 20:59     ` Brian Norris
  1 sibling, 1 reply; 5+ messages in thread
From: Tomer Barletz @ 2015-08-05  4:00 UTC (permalink / raw)
  To: dwmw2, computersforpeace; +Cc: linux-mtd, linux-kernel, Tomer Barletz

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 | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 41acc50..8830475 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -97,14 +97,13 @@ 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)) {
-	case READ:
+	if (rq_data_dir(req) == READ) {
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->readsect(dev, block, buf))
 				return -EIO;
 		rq_flush_dcache_pages(req);
 		return 0;
-	case WRITE:
+	} else {
 		if (!tr->writesect)
 			return -EIO;
 
@@ -113,9 +112,6 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 			if (tr->writesect(dev, block, buf))
 				return -EIO;
 		return 0;
-	default:
-		printk(KERN_NOTICE "Unknown request %u\n", rq_data_dir(req));
-		return -EIO;
 	}
 }
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: Fix switch-bool compilation warning
  2015-08-05  4:00   ` [PATCH] mtd: Fix switch-bool compilation warning Tomer Barletz
@ 2015-08-25 20:59     ` Brian Norris
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Norris @ 2015-08-25 20:59 UTC (permalink / raw)
  To: Tomer Barletz; +Cc: dwmw2, linux-mtd, linux-kernel

On Tue, Aug 04, 2015 at 09:00:24PM -0700, Tomer Barletz wrote:
> With gcc 5.1 I get:
> warning: switch condition has boolean value [-Wswitch-bool]
> 
> Signed-off-by: Tomer Barletz <barletz@gmail.com>

Applied to l2-mtd.git

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-25 20:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-02 10:36 [PATCH] Avoid compiler warning by storing the result of rq_data_dir() in an int variable Tomer Barletz
2015-08-02 13:48 ` Hagen Paul Pfeifer
2015-08-03  5:49   ` Tomer Barletz
2015-08-05  4:00   ` [PATCH] mtd: Fix switch-bool compilation warning Tomer Barletz
2015-08-25 20:59     ` Brian Norris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).