Skip to content

Commit 94bf6aa

Browse files
Linkui Xiaoanakryiko
authored andcommitted
selftests/bpf: Return true/false (not 1/0) from bool functions
Return boolean values ("true" or "false") instead of 1 or 0 from bool functions. This fixes the following warnings from coccicheck: tools/testing/selftests/bpf/progs/test_xdp_noinline.c:407:9-10: WARNING: return of 0/1 in function 'decap_v4' with return type bool tools/testing/selftests/bpf/progs/test_xdp_noinline.c:389:9-10: WARNING: return of 0/1 in function 'decap_v6' with return type bool tools/testing/selftests/bpf/progs/test_xdp_noinline.c:290:9-10: WARNING: return of 0/1 in function 'encap_v6' with return type bool tools/testing/selftests/bpf/progs/test_xdp_noinline.c:264:9-10: WARNING: return of 0/1 in function 'parse_tcp' with return type bool tools/testing/selftests/bpf/progs/test_xdp_noinline.c:242:9-10: WARNING: return of 0/1 in function 'parse_udp' with return type bool Generated by: scripts/coccinelle/misc/boolreturn.cocci Suggested-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Stanislav Fomichev <sdf@google.com> Link: https://lore.kernel.org/bpf/20220714015647.25074-1-xiaolinkui@kylinos.cn
1 parent bf3f003 commit 94bf6aa

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

tools/testing/selftests/bpf/progs/test_xdp_noinline.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@ bool parse_udp(void *data, void *data_end,
239239
udp = data + off;
240240

241241
if (udp + 1 > data_end)
242-
return 0;
242+
return false;
243243
if (!is_icmp) {
244244
pckt->flow.port16[0] = udp->source;
245245
pckt->flow.port16[1] = udp->dest;
246246
} else {
247247
pckt->flow.port16[0] = udp->dest;
248248
pckt->flow.port16[1] = udp->source;
249249
}
250-
return 1;
250+
return true;
251251
}
252252

253253
static __attribute__ ((noinline))
@@ -261,7 +261,7 @@ bool parse_tcp(void *data, void *data_end,
261261

262262
tcp = data + off;
263263
if (tcp + 1 > data_end)
264-
return 0;
264+
return false;
265265
if (tcp->syn)
266266
pckt->flags |= (1 << 1);
267267
if (!is_icmp) {
@@ -271,7 +271,7 @@ bool parse_tcp(void *data, void *data_end,
271271
pckt->flow.port16[0] = tcp->dest;
272272
pckt->flow.port16[1] = tcp->source;
273273
}
274-
return 1;
274+
return true;
275275
}
276276

277277
static __attribute__ ((noinline))
@@ -287,15 +287,15 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
287287
void *data;
288288

289289
if (bpf_xdp_adjust_head(xdp, 0 - (int)sizeof(struct ipv6hdr)))
290-
return 0;
290+
return false;
291291
data = (void *)(long)xdp->data;
292292
data_end = (void *)(long)xdp->data_end;
293293
new_eth = data;
294294
ip6h = data + sizeof(struct eth_hdr);
295295
old_eth = data + sizeof(struct ipv6hdr);
296296
if (new_eth + 1 > data_end ||
297297
old_eth + 1 > data_end || ip6h + 1 > data_end)
298-
return 0;
298+
return false;
299299
memcpy(new_eth->eth_dest, cval->mac, 6);
300300
memcpy(new_eth->eth_source, old_eth->eth_dest, 6);
301301
new_eth->eth_proto = 56710;
@@ -314,7 +314,7 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
314314
ip6h->saddr.in6_u.u6_addr32[2] = 3;
315315
ip6h->saddr.in6_u.u6_addr32[3] = ip_suffix;
316316
memcpy(ip6h->daddr.in6_u.u6_addr32, dst->dstv6, 16);
317-
return 1;
317+
return true;
318318
}
319319

320320
static __attribute__ ((noinline))
@@ -335,15 +335,15 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
335335
ip_suffix <<= 15;
336336
ip_suffix ^= pckt->flow.src;
337337
if (bpf_xdp_adjust_head(xdp, 0 - (int)sizeof(struct iphdr)))
338-
return 0;
338+
return false;
339339
data = (void *)(long)xdp->data;
340340
data_end = (void *)(long)xdp->data_end;
341341
new_eth = data;
342342
iph = data + sizeof(struct eth_hdr);
343343
old_eth = data + sizeof(struct iphdr);
344344
if (new_eth + 1 > data_end ||
345345
old_eth + 1 > data_end || iph + 1 > data_end)
346-
return 0;
346+
return false;
347347
memcpy(new_eth->eth_dest, cval->mac, 6);
348348
memcpy(new_eth->eth_source, old_eth->eth_dest, 6);
349349
new_eth->eth_proto = 8;
@@ -367,8 +367,8 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
367367
csum += *next_iph_u16++;
368368
iph->check = ~((csum & 0xffff) + (csum >> 16));
369369
if (bpf_xdp_adjust_head(xdp, (int)sizeof(struct iphdr)))
370-
return 0;
371-
return 1;
370+
return false;
371+
return true;
372372
}
373373

374374
static __attribute__ ((noinline))
@@ -386,10 +386,10 @@ bool decap_v6(struct xdp_md *xdp, void **data, void **data_end, bool inner_v4)
386386
else
387387
new_eth->eth_proto = 56710;
388388
if (bpf_xdp_adjust_head(xdp, (int)sizeof(struct ipv6hdr)))
389-
return 0;
389+
return false;
390390
*data = (void *)(long)xdp->data;
391391
*data_end = (void *)(long)xdp->data_end;
392-
return 1;
392+
return true;
393393
}
394394

395395
static __attribute__ ((noinline))
@@ -404,10 +404,10 @@ bool decap_v4(struct xdp_md *xdp, void **data, void **data_end)
404404
memcpy(new_eth->eth_dest, old_eth->eth_dest, 6);
405405
new_eth->eth_proto = 8;
406406
if (bpf_xdp_adjust_head(xdp, (int)sizeof(struct iphdr)))
407-
return 0;
407+
return false;
408408
*data = (void *)(long)xdp->data;
409409
*data_end = (void *)(long)xdp->data_end;
410-
return 1;
410+
return true;
411411
}
412412

413413
static __attribute__ ((noinline))

0 commit comments

Comments
 (0)