diff mbox

selftests/powerpc: context_switch: Fix pthread errors

Message ID 20170704012115.30870-1-cyrilbur@gmail.com (mailing list archive)
State Accepted
Commit 89aca4753eb451a48f65a12b02640365dba3d4ea
Headers show

Commit Message

Cyril Bur July 4, 2017, 1:21 a.m. UTC
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>
---
 .../selftests/powerpc/benchmarks/context_switch.c        | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Comments

Michael Ellerman Oct. 19, 2017, 4:48 a.m. UTC | #1
On Tue, 2017-07-04 at 01:21:15 UTC, Cyril Bur wrote:
> 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>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/89aca4753eb451a48f65a12b026403

cheers
diff mbox

Patch

diff --git a/tools/testing/selftests/powerpc/benchmarks/context_switch.c b/tools/testing/selftests/powerpc/benchmarks/context_switch.c
index 778f5fbfd784..7486e532d3e2 100644
--- a/tools/testing/selftests/powerpc/benchmarks/context_switch.c
+++ b/tools/testing/selftests/powerpc/benchmarks/context_switch.c
@@ -75,6 +75,7 @@  static void touch(void)
 
 static void start_thread_on(void *(*fn)(void *), void *arg, unsigned long cpu)
 {
+	int rc;
 	pthread_t tid;
 	cpu_set_t cpuset;
 	pthread_attr_t attr;
@@ -82,14 +83,23 @@  static void start_thread_on(void *(*fn)(void *), void *arg, unsigned long cpu)
 	CPU_ZERO(&cpuset);
 	CPU_SET(cpu, &cpuset);
 
-	pthread_attr_init(&attr);
+	rc = pthread_attr_init(&attr);
+	if (rc) {
+		errno = rc;
+		perror("pthread_attr_init");
+		exit(1);
+	}
 
-	if (pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset)) {
+	rc = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset);
+	if (rc)	{
+		errno = rc;
 		perror("pthread_attr_setaffinity_np");
 		exit(1);
 	}
 
-	if (pthread_create(&tid, &attr, fn, arg)) {
+	rc = pthread_create(&tid, &attr, fn, arg);
+	if (rc) {
+		errno = rc;
 		perror("pthread_create");
 		exit(1);
 	}