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

selftests/bpf: Output the correct error code for pthread APIs

The return value of pthread API is the error code when the called
API fails, so output the return value instead of errno.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20230613080921.1623219-3-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Hou Tao and committed by
Alexei Starovoitov
ea400d13 8ad663d3

+6 -4
+6 -4
tools/testing/selftests/bpf/bench.c
··· 441 441 static void set_thread_affinity(pthread_t thread, int cpu) 442 442 { 443 443 cpu_set_t cpuset; 444 + int err; 444 445 445 446 CPU_ZERO(&cpuset); 446 447 CPU_SET(cpu, &cpuset); 447 - if (pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset)) { 448 + err = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset); 449 + if (err) { 448 450 fprintf(stderr, "setting affinity to CPU #%d failed: %d\n", 449 - cpu, errno); 451 + cpu, -err); 450 452 exit(1); 451 453 } 452 454 } ··· 607 605 bench->consumer_thread, (void *)(long)i); 608 606 if (err) { 609 607 fprintf(stderr, "failed to create consumer thread #%d: %d\n", 610 - i, -errno); 608 + i, -err); 611 609 exit(1); 612 610 } 613 611 if (env.affinity) ··· 626 624 bench->producer_thread, (void *)(long)i); 627 625 if (err) { 628 626 fprintf(stderr, "failed to create producer thread #%d: %d\n", 629 - i, -errno); 627 + i, -err); 630 628 exit(1); 631 629 } 632 630 if (env.affinity)