Skip to contentSkip to conversation

block: use enumerate instead of integer in op_is_write()

PATCH In review brookxu 2 participants 2 messages Aug 20, 2021 Block layer

lore
Share & tools
lore

brookxu

author
#0 lore raw

PATCH 1/1 block: use enumerate instead of integer in op_is_write()

From: Chunguang Xu <[email protected]>

For mask operation, using enumerate may be safer than integer.

---
 include/linux/blk_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/blk_types.h +1 -1
index fd3860d1..b0411dc 100644
@@ -447,7 +447,7 @@ static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
 
 static inline bool op_is_write(unsigned int op)
 {
-	return (op & 1);
+	return (op & REQ_OP_WRITE);
 }
 
 /*
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 3 lines · brookxu

From: Chunguang Xu <[email protected]>

For mask operation, using enumerate may be safer than integer.

Except that we are explicitly checking for least significant bit as that is part of the encoding, not a specific enum value.