Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: ksz: Make reg_mib_cnt a u8 as it never exceeds 255

Currently the for-loop in ksz8_port_init_cnt is causing a static
analysis infinite loop warning with the comparison of
mib->cnt_ptr < dev->reg_mib_cnt. This occurs because mib->cnt_ptr
is a u8 and dev->reg_mib_cnt is an int and the analyzer determines
that mib->cnt_ptr potentially can wrap around to zero if the value
in dev->reg_mib_cnt is > 255. However, this value is never this
large, it is always less than 256 so make reg_mib_cnt a u8.

Addresses-Coverity: ("Infinite loop")
Fixes: e66f840c08a2 ("net: dsa: ksz: Add Microchip KSZ8795 DSA driver")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Link: https://lore.kernel.org/r/20210428120010.337959-1-colin.king@canonical.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Colin Ian King and committed by
Jakub Kicinski
12c2bb96 9be02dd3

+1 -1
+1 -1
drivers/net/dsa/microchip/ksz_common.h
··· 69 69 int cpu_ports; /* port bitmap can be cpu port */ 70 70 int phy_port_cnt; 71 71 int port_cnt; 72 - int reg_mib_cnt; 72 + u8 reg_mib_cnt; 73 73 int mib_cnt; 74 74 const struct mib_names *mib_names; 75 75 phy_interface_t compat_interface;