Convert the op argument of blk_op_str() to a local unsigned int variable using (__force unsigned int) before comparing it against ARRAY_SIZE(blk_op_name) and indexing blk_op_name[]. Because the enumerators of enum req_op are defined with (__force blk_opf_t) and blk_opf_t is a __bitwise type, sparse treats enum req_op as a restricted bitwise type. Hence, an enum req_op value must neither be compared directly against ARRAY_SIZE(blk_op_name) nor be used directly as an array subscript. Sparse does not yet report this because blk_op_str() is an inline function that is exported but that is not called from block/blk-core.c, and because sparse skips the body of inline functions that have no caller. A sparse change is pending that makes sparse check the body of exported inline functions that have no caller in their translation unit. With that change applied, sparse reports the following warnings: block/blk-core.c:130:13: warning: restricted blk_opf_t degrades to integer block/blk-core.c:130:57: warning: restricted blk_opf_t degrades to integer block/blk-core.c:131:38: warning: restricted blk_opf_t degrades to integer Signed-off-by: Bart Van Assche --- block/blk-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 2ee079c1ce15..6802f4d88ec8 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -126,9 +126,10 @@ static const char *const blk_op_name[] = { inline const char *blk_op_str(enum req_op op) { const char *op_str = "UNKNOWN"; + unsigned int uint_op = (__force unsigned int)op; - if (op < ARRAY_SIZE(blk_op_name) && blk_op_name[op]) - op_str = blk_op_name[op]; + if (uint_op < ARRAY_SIZE(blk_op_name) && blk_op_name[uint_op]) + op_str = blk_op_name[uint_op]; return op_str; }