mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] selftests/bpf: Fix unsigned expression compared with zero
@ 2022-11-05 10:25 Kang Minchul
  2022-11-05 16:16 ` Randy Dunlap
  0 siblings, 1 reply; 3+ messages in thread
From: Kang Minchul @ 2022-11-05 10:25 UTC (permalink / raw)
  To: Björn Töpel, Magnus Karlsson, Maciej Fijalkowski,
	Jonathan Lemon
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, netdev, linux-kernel,
	Kang Minchul

Variable ret is compared with zero even though it was set as u32.
So u32 to int conversion is needed.

Signed-off-by: Kang Minchul <tegongkang@gmail.com>
---
 tools/testing/selftests/bpf/xskxceiver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
index 681a5db80dae..162d3a516f2c 100644
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@ -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) {
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] selftests/bpf: Fix unsigned expression compared with zero
  2022-11-05 10:25 [PATCH v2] selftests/bpf: Fix unsigned expression compared with zero Kang Minchul
@ 2022-11-05 16:16 ` Randy Dunlap
  2022-11-05 16:21   ` Kang Minchul
  0 siblings, 1 reply; 3+ messages in thread
From: Randy Dunlap @ 2022-11-05 16:16 UTC (permalink / raw)
  To: Kang Minchul, Björn Töpel, Magnus Karlsson,
	Maciej Fijalkowski, Jonathan Lemon
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, netdev, linux-kernel

Hi--

On 11/5/22 03:25, Kang Minchul wrote:
> 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.

> So u32 to int conversion is needed.
> 
> Signed-off-by: Kang Minchul <tegongkang@gmail.com>
> ---
>  tools/testing/selftests/bpf/xskxceiver.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> index 681a5db80dae..162d3a516f2c 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.c
> +++ b/tools/testing/selftests/bpf/xskxceiver.c
> @@ -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) {

-- 
~Randy

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] selftests/bpf: Fix unsigned expression compared with zero
  2022-11-05 16:16 ` Randy Dunlap
@ 2022-11-05 16:21   ` Kang Minchul
  0 siblings, 0 replies; 3+ messages in thread
From: Kang Minchul @ 2022-11-05 16:21 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Björn Töpel, Magnus Karlsson, Maciej Fijalkowski,
	Jonathan Lemon, Martin KaFai Lau, Song Liu, Yonghong Song,
	netdev, linux-kernel

2022년 11월 6일 (일) 오전 1:16, Randy Dunlap <rdunlap@infradead.org>님이 작성:
>
> Hi--
>
> On 11/5/22 03:25, Kang Minchul wrote:
> > 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-05 16:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-05 10:25 [PATCH v2] selftests/bpf: Fix unsigned expression compared with zero Kang Minchul
2022-11-05 16:16 ` Randy Dunlap
2022-11-05 16:21   ` Kang Minchul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®