selftests/bpf: Fix unsigned expression compared with zero
Subsystems (6)
PATCH v2 1/1 selftests/bpf: Fix unsigned expression compared with zero
Variable ret is compared with zero even though it was set as u32. So u32 to int conversion is needed.
--- tools/testing/selftests/bpf/xskxceiver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/xskxceiver.c +2 -1
@@ -1006,7 +1006,8 @@ static int __send_pkts(struct ifobject *ifobject, u32 *pkt_nb, struct pollfd *fd {struct xsk_socket_info *xsk = ifobject->xsk;bool use_poll = ifobject->use_poll; -u32 i, idx =0 , ret, valid_pkts =0 ; +u32 i, idx =0 , valid_pkts =0 ; +int ret;while (xsk_ring_prod__reserve (&xsk->tx,BATCH_SIZE , &idx) <BATCH_SIZE ) {if (use_poll) {
Signature · 1 line
2.34.1
Hi--
Quoted 1 line · Kang Minchul
Variable ret is compared with zero even though it was set as u32.
It's OK to compare a u32 == to zero, but 'ret' is compared to < 0, which it cannot be. Better explanation here would be good. Thanks.
Quoted 21 lines
So u32 to int conversion is needed.
Signed-off-by Kang Minchul <[email protected]>--- tools/testing/selftests/bpf/xskxceiver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/xskxceiver.c +2
-1@@ -1006,7 +1006,8 @@ static int __send_pkts(struct ifobject *ifobject, u32 *pkt_nb, struct pollfd *fd {struct xsk_socket_info *xsk = ifobject->xsk;bool use_poll = ifobject->use_poll; -u32 i, idx =0 , ret, valid_pkts =0 ; +u32 i, idx =0 , valid_pkts =0 ; +int ret;while (xsk_ring_prod__reserve (&xsk->tx,BATCH_SIZE , &idx) <BATCH_SIZE ) {if (use_poll) {
Signature · 1 line
~Randy
2022년 11월 6일 (일) 오전 1:16, Randy Dunlap <[email protected]>님이 작성:
Quoted 10 lines
Hi--
Quoted 1 line · Kang Minchul
Variable ret is compared with zero even though it was set as u32.
It's OK to compare a u32 == to zero, but 'ret' is compared to < 0, which it cannot be. Better explanation here would be good. Thanks.
~Randy
Thanks for your kind feedback!
I guess I have to change the message more precisely. I'll send the amended patch (PATCH v3) as you mentioned.
Regards,
Kang Minchul