Skip to contentSkip to conversation

block: precedence bug in bio_set_op_attrs() macro

PATCH In review Dan Carpenter 2 participants 2 messages Nov 10, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: precedence bug in bio_set_op_attrs() macro

This code causes a problem for flush_epd_write_bio() because | has higher precedence than ?: so it basically turns into:

	((bio)->bi_opf |= REQ_SYNC;

Which is wrong.

Fixes ef295ecf090d ("block: better op and flags encoding")
include/linux/blk_types.h +1 -1
index 562ac46..67fae32 100644
@@ -208,7 +208,7 @@ enum req_flag_bits {
 
 /* obsolete, don't use in new code */
 #define bio_set_op_attrs(bio, op, op_flags) \
-	((bio)->bi_opf |= (op | op_flags))
+	((bio)->bi_opf |= ((op) | (op_flags)))
 
 static inline bool op_is_write(unsigned int op)
 {
#1 lore raw
Quoted 6 lines · Dan Carpenter

This code causes a problem for flush_epd_write_bio() because | has higher precedence than ?: so it basically turns into:

	((bio)->bi_opf |= REQ_SYNC;

Which is wrong.

Its is. And while we're at it the macro should really be doing a = instead of |=.

And we really should stop using it, at least in the block core even ASAP.