Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4593506ybi; Sat, 20 Jul 2019 02:14:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqyipkYASuIkfFX4Bqy/QPPFuBnsoqQRueUDMD1da3yJ6dIHTdSXAOX/M+Lpo1zVoammSkup X-Received: by 2002:a63:d944:: with SMTP id e4mr58445003pgj.261.1563614064704; Sat, 20 Jul 2019 02:14:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563614064; cv=none; d=google.com; s=arc-20160816; b=D6WRVApsp99o7giFX09PmnzAVPV6QxRWRb7eJs96Tq59tUfQSQWF+hG8lrKc/fiAh5 bTJaaxuJXyFxfvjkExhDy0KKRIWr0cfeW57BYfcazlcv8RzLzR928QKzziRzTWhs1pUq DfjIhE5dlQgnsFHTue8OoPgHXzWp7YF5ph+qs56vAwG9tpyZ0ruKKzYVMHiGOMG0m2xK V/nnCEy8mmQvRr/vODY0lrANOr8J5WdXouS8zlzgA+WTKTh/JsDCuPS/wkOyQaOTEx+M coLEmPgJHpIUqQ3nlPxtE9z3+yD3JBMU+JNtWHy7DG/mC3LdC0bdRIE2M9VzJRrWUbni hD6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=85mweGnqRiGyYtWotmXR3l+iqV5TgHZDyHALtUExFY8=; b=n9NbS+3bYLaJDFaSoas2o3yfUR6O3yYcYvK9lNnt4sMBEChRKdZbGJpVbAu6zc8Fy/ qL6emAsJHLJ7Msq4YXfQminO6UOj8VjU3wL3AIPMm2b39Swya47yJtdvgEvsxYTTxX24 9xgX/resROmjo2VPnkG40Gj5oXQOvHa4mGHIPKuFKrQwcpgUxWnsR5tIP16vYasoBgRX RSpt2zkjH9iq/SWq+zNJjjZPE+s3R+/TN9Tl8Gt40XLPRWWV93fJqZqVnA7MgtuFFvZO XXtmTZa2KHrOUV93RF1xxkccBcN7IMom1GN1oFHvRDAVHGJvQyJzBgNcNjMbsQ6DCYTb gxsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2d21roDp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v62si6511655pgv.126.2019.07.20.02.13.28; Sat, 20 Jul 2019 02:14:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2d21roDp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730341AbfGSWZz (ORCPT + 99 others); Fri, 19 Jul 2019 18:25:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:34372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727344AbfGSWZx (ORCPT ); Fri, 19 Jul 2019 18:25:53 -0400 Received: from [172.20.8.67] (fs96f9c61d.tkyc509.ap.nuro.jp [150.249.198.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 22F662089C; Fri, 19 Jul 2019 22:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563575151; bh=8BWoO3DvmgmHko8VDYdzETwa/D8Uvwa79H4eUTG3YyA=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=2d21roDptAiEMN+/t1Tn1VqLwtXAzfhagrwnPWLFbYgAsIvJrwHrLthScReql/x37 AR35y/eDLcde0w6tvfWPiYxJdZI5Xmb/Wqr3rItqjuiTHCL3Wa/X60g/Pf/v1glDZV /OWIM04HKP6cE2E1wkO2gqhjsIBpm7gFFRxIlREI= Subject: Re: [PATCH v10 8/9] kselftest: save-and-restore errno to allow for %m formatting To: Aleksa Sarai , Al Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan Cc: Eric Biederman , Andy Lutomirski , Andrew Morton , Alexei Starovoitov , Kees Cook , Jann Horn , Christian Brauner , Tycho Andersen , David Drysdale , Chanho Min , Oleg Nesterov , Aleksa Sarai , Linus Torvalds , containers@lists.linux-foundation.org, linux-alpha@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, sparclinux@vger.kernel.org, shuah References: <20190719164225.27083-1-cyphar@cyphar.com> <20190719164225.27083-9-cyphar@cyphar.com> From: shuah Message-ID: Date: Fri, 19 Jul 2019 16:25:46 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190719164225.27083-9-cyphar@cyphar.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/19/19 10:42 AM, Aleksa Sarai wrote: > Previously, using "%m" in a ksft_* format string can result in strange > output because the errno value wasn't saved before calling other libc > functions. The solution is to simply save and restore the errno before > we format the user-supplied format string. > > Signed-off-by: Aleksa Sarai > --- > tools/testing/selftests/kselftest.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h > index ec15c4f6af55..0ac49d91a260 100644 > --- a/tools/testing/selftests/kselftest.h > +++ b/tools/testing/selftests/kselftest.h > @@ -10,6 +10,7 @@ > #ifndef __KSELFTEST_H > #define __KSELFTEST_H > > +#include > #include > #include > #include > @@ -81,58 +82,68 @@ static inline void ksft_print_cnts(void) > > static inline void ksft_print_msg(const char *msg, ...) > { > + int saved_errno = errno; > va_list args; > > va_start(args, msg); > printf("# "); > + errno = saved_errno; > vprintf(msg, args); > va_end(args); > } > > static inline void ksft_test_result_pass(const char *msg, ...) > { > + int saved_errno = errno; > va_list args; > > ksft_cnt.ksft_pass++; > > va_start(args, msg); > printf("ok %d ", ksft_test_num()); > + errno = saved_errno; > vprintf(msg, args); > va_end(args); > } > > static inline void ksft_test_result_fail(const char *msg, ...) > { > + int saved_errno = errno; > va_list args; > > ksft_cnt.ksft_fail++; > > va_start(args, msg); > printf("not ok %d ", ksft_test_num()); > + errno = saved_errno; > vprintf(msg, args); > va_end(args); > } > > static inline void ksft_test_result_skip(const char *msg, ...) > { > + int saved_errno = errno; > va_list args; > > ksft_cnt.ksft_xskip++; > > va_start(args, msg); > printf("not ok %d # SKIP ", ksft_test_num()); > + errno = saved_errno; > vprintf(msg, args); > va_end(args); > } > > static inline void ksft_test_result_error(const char *msg, ...) > { > + int saved_errno = errno; > va_list args; > > ksft_cnt.ksft_error++; > > va_start(args, msg); > printf("not ok %d # error ", ksft_test_num()); > + errno = saved_errno; > vprintf(msg, args); > va_end(args); > } > @@ -152,10 +163,12 @@ static inline int ksft_exit_fail(void) > > static inline int ksft_exit_fail_msg(const char *msg, ...) > { > + int saved_errno = errno; > va_list args; > > va_start(args, msg); > printf("Bail out! "); > + errno = saved_errno; > vprintf(msg, args); > va_end(args); > > @@ -178,10 +191,12 @@ static inline int ksft_exit_xpass(void) > static inline int ksft_exit_skip(const char *msg, ...) > { > if (msg) { > + int saved_errno = errno; > va_list args; > > va_start(args, msg); > printf("not ok %d # SKIP ", 1 + ksft_test_num()); > + errno = saved_errno; > vprintf(msg, args); > va_end(args); > } else { > Hi Aleksa, Can you send this patch separate from the patch series. I will apply this as bug fix to 5.3-rc2 or rc3. This isn't part of this series anyway and I would like to get this in right away. thanks, -- Shuah