Skip to contentSkip to conversation

drivers/firewire/core-card.c:479 bm_work() warn: always true condition '(root_node->max_hops < (16 / 1 + (0))) => (0-15 < 16)'

PATCH Nick Desaulniers 1 participant 1 message Sep 19, 2018 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 201809190938.CXi0coge%[email protected]

#1 lore raw
Quoted 8 lines · kbuild test robot
tree:   git://github.com/ojeda/linux compiler-attributes-v4
head:   7c70bc9e399c67f5d1a84b845d2656f8808e0032
commit: 431781b83c5e7ae3719498bf1e52ca99bcf6d20b [7/13] Compiler Attributes: remove unneeded sparse (__CHECKER__) tests

smatch warnings:
drivers/firewire/core-card.c:479 bm_work() warn: always true condition '(root_node->max_hops < (16 / 1 + (0))) => (0-15 < 16)' drivers/ide/ide-cd_verbose.c:271 ide_cd_log_error() warn: always true condition '(sense->sense_key < (64 / 4 + (0))) => (0-15 < 16)'

If I understand this correctly, it seems that the condition:

479 root_node->max_hops < ARRAY_SIZE(gap_count_table))

is always true. root_node->max_hops is declared as:

187 u8 max_hops:4; /* Max hops in this sub tree */

in drivers/firewire/core.h, while gap_count_table is declared as:

289 static const char gap_count_table[] = {
290 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37,
40
291 };

Since max_hops is a 4b bit vector, its maximal unsigned representable value is (2^4) - 1 == 15, and 15 is always less that 16, so indeed this condition is always true.

One issue is that should gap_count_table grow, then this condition may become always false. Removing the condition might break the then clause should gap_count_table grow.

Maybe this can be converted to a BUILD_BUG_ON?

Signature · 2 lines
Thanks,
~Nick Desaulniers