You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qemu/hw/net/rocker
Peter Maydell 33eff5c84d hw/net/rocker: Don't overflow in of_dpa_mask2prefix()
In of_dpa_mask2prefix() we do "(2 << i)" for a loop where i can go up
to 31.  At i == 31 we shift off the top end of an integer.  This
doesn't actually calculate the wrong value in practice, because we
calculate 0 - 1 which is the 0xffffffff mask we wanted (and for QEMU
shifting off the top of a signed integer is not UB); but it makes
Coverity complain.

We could fix this simply by using "2ULL" (where the "(2ULL << i) - 1"
expression also evaluates to 0xffffffff for i == 31), but in fact
this function is a slow looping implementation of counting the number
of trailing zeroes in the (network-order) input mask:

 0bxxxxxxxxx1 => 32
 0bxxxxxxxx10 => 31
 0bxxxxxxx100 => 30
 ...
 0bx100000000 => 2
 0b1000000000 => 1
 0b0000000000 => 0

Replace the implementation with 32 - ctz32().

Coverity: CID 1547602
Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20251016145407.781978-1-peter.maydell@linaro.org
3 weeks ago
..
qmp-norocker.c rocker: Tweak stubbed out monitor commands' error messages 3 years ago
rocker-hmp-cmds.c qapi: Move include/qapi/qmp/ to include/qobject/ 9 months ago
rocker.c qom: Make InterfaceInfo[] uses const 7 months ago
rocker.h rocker: do not pollute the namespace 6 months ago
rocker_desc.c bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 3 years ago
rocker_desc.h
rocker_fp.c net: Provide MemReentrancyGuard * to qemu_new_nic() 2 years ago
rocker_fp.h rocker: Revamp fp_port_get_info 5 years ago
rocker_hw.h rocker: do not pollute the namespace 6 months ago
rocker_of_dpa.c hw/net/rocker: Don't overflow in of_dpa_mask2prefix() 3 weeks ago
rocker_of_dpa.h
rocker_tlv.h
rocker_world.c net/rocker: Remove the dead error handling 8 years ago
rocker_world.h