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

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: xdp_hw_metadata correct status value in error(3)

The glibc error reporting function error():

void error(int status, int errnum, const char *format, ...);

The status argument should be a positive value between 0-255 as it
is passed over to the exit(3) function as the value as the shell exit
status. The least significant byte of status (i.e., status & 0xFF) is
returned to the shell parent.

Fix this by using 1 instead of -1. As 1 corresponds to C standard
constant EXIT_FAILURE.

Fixes: 297a3f124155 ("selftests/bpf: Simple program to dump XDP RX metadata")
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/167527272038.937063.9137108142012298120.stgit@firesoul

authored by

Jesper Dangaard Brouer and committed by
Daniel Borkmann
7bd4224d a19a62e5

+14 -14
+14 -14
tools/testing/selftests/bpf/xdp_hw_metadata.c
··· 165 165 hdr.msg_controllen = sizeof(cmsg_buf); 166 166 167 167 if (recvmsg(fd, &hdr, 0) < 0) 168 - error(-1, errno, "recvmsg"); 168 + error(1, errno, "recvmsg"); 169 169 170 170 for (cmsg = CMSG_FIRSTHDR(&hdr); cmsg != NULL; 171 171 cmsg = CMSG_NXTHDR(&hdr, cmsg)) { ··· 275 275 276 276 fd = socket(AF_UNIX, SOCK_DGRAM, 0); 277 277 if (fd < 0) 278 - error(-1, errno, "socket"); 278 + error(1, errno, "socket"); 279 279 280 280 ret = ioctl(fd, SIOCETHTOOL, &ifr); 281 281 if (ret < 0) 282 - error(-1, errno, "ioctl(SIOCETHTOOL)"); 282 + error(1, errno, "ioctl(SIOCETHTOOL)"); 283 283 284 284 close(fd); 285 285 ··· 296 296 297 297 fd = socket(AF_UNIX, SOCK_DGRAM, 0); 298 298 if (fd < 0) 299 - error(-1, errno, "socket"); 299 + error(1, errno, "socket"); 300 300 301 301 ret = ioctl(fd, op, &ifr); 302 302 if (ret < 0) 303 - error(-1, errno, "ioctl(%d)", op); 303 + error(1, errno, "ioctl(%d)", op); 304 304 305 305 close(fd); 306 306 } ··· 360 360 361 361 ret = setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, &val, sizeof(val)); 362 362 if (ret < 0) 363 - error(-1, errno, "setsockopt(SO_TIMESTAMPING)"); 363 + error(1, errno, "setsockopt(SO_TIMESTAMPING)"); 364 364 } 365 365 366 366 int main(int argc, char *argv[]) ··· 386 386 387 387 rx_xsk = malloc(sizeof(struct xsk) * rxq); 388 388 if (!rx_xsk) 389 - error(-1, ENOMEM, "malloc"); 389 + error(1, ENOMEM, "malloc"); 390 390 391 391 for (i = 0; i < rxq; i++) { 392 392 printf("open_xsk(%s, %p, %d)\n", ifname, &rx_xsk[i], i); 393 393 ret = open_xsk(ifindex, &rx_xsk[i], i); 394 394 if (ret) 395 - error(-1, -ret, "open_xsk"); 395 + error(1, -ret, "open_xsk"); 396 396 397 397 printf("xsk_socket__fd() -> %d\n", xsk_socket__fd(rx_xsk[i].socket)); 398 398 } ··· 400 400 printf("open bpf program...\n"); 401 401 bpf_obj = xdp_hw_metadata__open(); 402 402 if (libbpf_get_error(bpf_obj)) 403 - error(-1, libbpf_get_error(bpf_obj), "xdp_hw_metadata__open"); 403 + error(1, libbpf_get_error(bpf_obj), "xdp_hw_metadata__open"); 404 404 405 405 prog = bpf_object__find_program_by_name(bpf_obj->obj, "rx"); 406 406 bpf_program__set_ifindex(prog, ifindex); ··· 409 409 printf("load bpf program...\n"); 410 410 ret = xdp_hw_metadata__load(bpf_obj); 411 411 if (ret) 412 - error(-1, -ret, "xdp_hw_metadata__load"); 412 + error(1, -ret, "xdp_hw_metadata__load"); 413 413 414 414 printf("prepare skb endpoint...\n"); 415 415 server_fd = start_server(AF_INET6, SOCK_DGRAM, NULL, 9092, 1000); 416 416 if (server_fd < 0) 417 - error(-1, errno, "start_server"); 417 + error(1, errno, "start_server"); 418 418 timestamping_enable(server_fd, 419 419 SOF_TIMESTAMPING_SOFTWARE | 420 420 SOF_TIMESTAMPING_RAW_HARDWARE); ··· 427 427 printf("map[%d] = %d\n", queue_id, sock_fd); 428 428 ret = bpf_map_update_elem(bpf_map__fd(bpf_obj->maps.xsk), &queue_id, &sock_fd, 0); 429 429 if (ret) 430 - error(-1, -ret, "bpf_map_update_elem"); 430 + error(1, -ret, "bpf_map_update_elem"); 431 431 } 432 432 433 433 printf("attach bpf program...\n"); ··· 435 435 bpf_program__fd(bpf_obj->progs.rx), 436 436 XDP_FLAGS, NULL); 437 437 if (ret) 438 - error(-1, -ret, "bpf_xdp_attach"); 438 + error(1, -ret, "bpf_xdp_attach"); 439 439 440 440 signal(SIGINT, handle_signal); 441 441 ret = verify_metadata(rx_xsk, rxq, server_fd); 442 442 close(server_fd); 443 443 cleanup(); 444 444 if (ret) 445 - error(-1, -ret, "verify_metadata"); 445 + error(1, -ret, "verify_metadata"); 446 446 }