Re: [PATCH v2] BLOCK: fix bio.bi_rw handling

Previous thread: [PATCH v2] SCSI: fix bio.bi_rw handling by Jiri Slaby on Thursday, August 12, 2010 - 5:31 am. (3 messages)

Next thread: [PATCH v2] MD: raid, fix BUG caused by flags handling by Jiri Slaby on Thursday, August 12, 2010 - 5:31 am. (3 messages)
From: Jiri Slaby
Date: Thursday, August 12, 2010 - 5:31 am

Return of the bi_rw tests is no longer bool after commit 74450be1. But
results of such tests are stored in bools. This doesn't fit in there
for some compilers (gcc 4.5 here), so either use !! magic to get real
bools or use ulong where the result is assigned somewhere.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>
---
 block/blk-core.c     |    6 +++---
 drivers/block/loop.c |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 207af0d..29fd2cc 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1198,9 +1198,9 @@ static int __make_request(struct request_queue *q, struct bio *bio)
 	int el_ret;
 	unsigned int bytes = bio->bi_size;
 	const unsigned short prio = bio_prio(bio);
-	const bool sync = (bio->bi_rw & REQ_SYNC);
-	const bool unplug = (bio->bi_rw & REQ_UNPLUG);
-	const unsigned int ff = bio->bi_rw & REQ_FAILFAST_MASK;
+	const bool sync = !!(bio->bi_rw & REQ_SYNC);
+	const bool unplug = !!(bio->bi_rw & REQ_UNPLUG);
+	const unsigned long ff = bio->bi_rw & REQ_FAILFAST_MASK;
 	int rw_flags;
 
 	if ((bio->bi_rw & REQ_HARDBARRIER) &&
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index e647537..0ba2899 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -476,7 +476,7 @@ static int do_bio_filebacked(struct loop_device *lo, struct bio *bio)
 	pos = ((loff_t) bio->bi_sector << 9) + lo->lo_offset;
 
 	if (bio_rw(bio) == WRITE) {
-		bool barrier = (bio->bi_rw & REQ_HARDBARRIER);
+		bool barrier = !!(bio->bi_rw & REQ_HARDBARRIER);
 		struct file *file = lo->lo_backing_file;
 
 		if (barrier) {
-- 
1.7.2.1


--

From: Jeff Moyer
Date: Thursday, August 12, 2010 - 6:35 am

Reviewed-by: Jeff Moyer <jmoyer@redhat.com>

Cheers,
Jeff
--

From: Christoph Hellwig
Date: Thursday, August 12, 2010 - 9:08 am

I'd have to look at my copy of the C standard if it's guaranteed, but
at least currently the values just get truncated down and bool still
is set to true.  I'd much prefer just making these flags unsigned longs
instead of adding syntactic surage to make them true bools.

--

From: Jiri Slaby
Date: Thursday, August 12, 2010 - 9:24 am

§6.5.3.3 of ANSI C99, par 5:
The result of the logical negation operator ! is 0 if the value of its
operand compares unequal to 0, 1 if the value of its operand compares
equal to 0. The result has type int. The expression !E is equivalent to
(0==E).

On == (§6.5.9 par 3):
The == (equal to) and != (not equal to) operators are analogous to the
relational operators except for their lower precedence. Each of the
operators yields 1 if the specified relation is true and 0 if it is
false. The result has type int. For any pair of operands, exactly one of
the relations is true.

On bool => _Bool (§6.2.5 par 2)
An object declared as type _Bool is large enough to store the values 0
and 1.

So it should be safe :).

BTW just of curiosity, sizeof(bool) is 1 here (8 bits).

regards,
-- 
js
--

From: Jens Axboe
Date: Monday, August 23, 2010 - 3:33 am

Added, sorry for the delay!

-- 
Jens Axboe

--

Previous thread: [PATCH v2] SCSI: fix bio.bi_rw handling by Jiri Slaby on Thursday, August 12, 2010 - 5:31 am. (3 messages)

Next thread: [PATCH v2] MD: raid, fix BUG caused by flags handling by Jiri Slaby on Thursday, August 12, 2010 - 5:31 am. (3 messages)