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

selftests/powerpc: context_switch: Fix pthread errors

Turns out pthreads returns an errno and doesn't set errno. This doesn't
play well with perror().

Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Cyril Bur and committed by
Michael Ellerman
89aca475 8f6a9042

+14 -3
+14 -3
tools/testing/selftests/powerpc/benchmarks/context_switch.c
··· 10 10 */ 11 11 12 12 #define _GNU_SOURCE 13 + #include <errno.h> 13 14 #include <sched.h> 14 15 #include <string.h> 15 16 #include <stdio.h> ··· 76 75 77 76 static void start_thread_on(void *(*fn)(void *), void *arg, unsigned long cpu) 78 77 { 78 + int rc; 79 79 pthread_t tid; 80 80 cpu_set_t cpuset; 81 81 pthread_attr_t attr; ··· 84 82 CPU_ZERO(&cpuset); 85 83 CPU_SET(cpu, &cpuset); 86 84 87 - pthread_attr_init(&attr); 85 + rc = pthread_attr_init(&attr); 86 + if (rc) { 87 + errno = rc; 88 + perror("pthread_attr_init"); 89 + exit(1); 90 + } 88 91 89 - if (pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset)) { 92 + rc = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset); 93 + if (rc) { 94 + errno = rc; 90 95 perror("pthread_attr_setaffinity_np"); 91 96 exit(1); 92 97 } 93 98 94 - if (pthread_create(&tid, &attr, fn, arg)) { 99 + rc = pthread_create(&tid, &attr, fn, arg); 100 + if (rc) { 101 + errno = rc; 95 102 perror("pthread_create"); 96 103 exit(1); 97 104 }