From nobody Thu Dec 18 04:50:50 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01A4AC88CB2 for ; Thu, 24 Aug 2023 12:42:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239358AbjHXMmB (ORCPT ); Thu, 24 Aug 2023 08:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239107AbjHXMlo (ORCPT ); Thu, 24 Aug 2023 08:41:44 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 611C0170C for ; Thu, 24 Aug 2023 05:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692880902; x=1724416902; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e8TDYWiMwooDPLL+j1EknxHChiy/ycRSty3NIGB478Y=; b=bgJv3B2OkSn33xq7/PBIyYv1ZDKGemXuTM9Qcb+6eycfiJK5oh85ax6t 0lqlQ/Vn9yDDGiINAcy1qEy7VIDu0xxYyhaCR+1qjHkiIpf+ZN7+wDzef 5Ol1bPjqonZ2QqJVhlqT9ImqDAec15WzL+Mb2Cw4Zb4fgN8qCxVPfA/aR FHV9crKL2z1E5fkW6MzbLNGhSH6QV1BMBvmkjxDIJ+hc38ciSzImrdPQp poPGZk/BCIuatV+FXq3VlOA6KTZF+C19343DUjmAqjOMdRnFtxHNSiA67 3W9OuFg2htm4ast+/5I6/436WJiRhI+McR54mtThf8BHI9eWaMVei+Awx w==; X-IronPort-AV: E=McAfee;i="6600,9927,10811"; a="460783951" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="460783951" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 05:41:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10811"; a="740161426" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="740161426" Received: from mdziurdx-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.11.127]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 05:41:40 -0700 From: "Wieczor-Retman, Maciej" To: linux-kernel@vger.kernel.org, reinette.chatre@intel.com, fenghua.yu@intel.com Cc: ilpo.jarvinen@linux.intel.com Subject: [PATCH 3/3] selftests: Add printf attribute to ksefltest prints Date: Thu, 24 Aug 2023 14:41:26 +0200 Message-ID: <9adfc58deb5c7df43f6a8701d4e15821f4c42dc7.1692880423.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Kselftest header defines multiple variadic function that use printf along with other logic There is no format checking for the variadic functions that use printing inside kselftest.h. Because of this the compiler won't be able to catch instances of mismatched print formats and debugging tests might be more difficult Add the common __printf attribute macro to kselftest.h Add __printf attribute to every function using formatted printing with variadic arguments Signed-off-by: Wieczor-Retman, Maciej Reviewed-by: Ilpo J=C3=A4rvinen --- tools/testing/selftests/kselftest.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/= kselftest.h index 829be379545a..ff47ed711879 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -77,6 +77,8 @@ #define KSFT_XPASS 3 #define KSFT_SKIP 4 =20 +#define __printf(a, b) __attribute__((format(printf, a, b))) + /* counters */ struct ksft_count { unsigned int ksft_pass; @@ -134,7 +136,7 @@ static inline void ksft_print_cnts(void) ksft_cnt.ksft_xskip, ksft_cnt.ksft_error); } =20 -static inline void ksft_print_msg(const char *msg, ...) +static inline __printf(1, 2) void ksft_print_msg(const char *msg, ...) { int saved_errno =3D errno; va_list args; @@ -146,7 +148,7 @@ static inline void ksft_print_msg(const char *msg, ...) va_end(args); } =20 -static inline void ksft_test_result_pass(const char *msg, ...) +static inline __printf(1, 2) void ksft_test_result_pass(const char *msg, .= ..) { int saved_errno =3D errno; va_list args; @@ -160,7 +162,7 @@ static inline void ksft_test_result_pass(const char *ms= g, ...) va_end(args); } =20 -static inline void ksft_test_result_fail(const char *msg, ...) +static inline __printf(1, 2) void ksft_test_result_fail(const char *msg, .= ..) { int saved_errno =3D errno; va_list args; @@ -186,7 +188,7 @@ static inline void ksft_test_result_fail(const char *ms= g, ...) ksft_test_result_fail(fmt, ##__VA_ARGS__);\ } while (0) =20 -static inline void ksft_test_result_xfail(const char *msg, ...) +static inline __printf(1, 2) void ksft_test_result_xfail(const char *msg, = ...) { int saved_errno =3D errno; va_list args; @@ -200,7 +202,7 @@ static inline void ksft_test_result_xfail(const char *m= sg, ...) va_end(args); } =20 -static inline void ksft_test_result_skip(const char *msg, ...) +static inline __printf(1, 2) void ksft_test_result_skip(const char *msg, .= ..) { int saved_errno =3D errno; va_list args; @@ -215,7 +217,7 @@ static inline void ksft_test_result_skip(const char *ms= g, ...) } =20 /* TODO: how does "error" differ from "fail" or "skip"? */ -static inline void ksft_test_result_error(const char *msg, ...) +static inline __printf(1, 2) void ksft_test_result_error(const char *msg, = ...) { int saved_errno =3D errno; va_list args; @@ -262,7 +264,7 @@ static inline int ksft_exit_fail(void) ksft_cnt.ksft_xfail + \ ksft_cnt.ksft_xskip) =20 -static inline int ksft_exit_fail_msg(const char *msg, ...) +static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...) { int saved_errno =3D errno; va_list args; @@ -289,7 +291,7 @@ static inline int ksft_exit_xpass(void) exit(KSFT_XPASS); } =20 -static inline int ksft_exit_skip(const char *msg, ...) +static inline __printf(1, 2) int ksft_exit_skip(const char *msg, ...) { int saved_errno =3D errno; va_list args; --=20 2.42.0