From nobody Sat Feb 7 17:55:51 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2278122B8CB for ; Wed, 24 Dec 2025 08:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766565694; cv=none; b=J20B7STGyiFjkvMe5G60G8kWXWB2HLfjjZiz+cx2g/pGDw75fKlEx38SZO/u8N4JLeg+5IcsMqo35rCJNTMpTXd/ionf/5NNuEObD+kXLmvjChWkwDhzhMGkAoy74F56RtUxozMmFk4wu6J4lqj4ewtXK657XedlE5MLVbrNpxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766565694; c=relaxed/simple; bh=b9azLrvng1W+owOZrrSCG2h1ZMWVw5Gr5XMFi74WAM0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JXirUKUzqWE+XDiG4jxna06/gQshfHDn9FvV2U0F2XqqObxINBlw0kxJvqMgexnejXI6NpUA8c42g/0KdNNSPctQbwoSo7zpfQp4EDSGgW1Ao7eqfE7B21ZTIntmRI+35D5UbeIWH9uy9SPezcSDRD2hpVJ9YoA8qBUleo1qTm8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wakel.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pQ5ep3wV; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wakel.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pQ5ep3wV" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-29f8e6a5de4so79451275ad.2 for ; Wed, 24 Dec 2025 00:41:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766565691; x=1767170491; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/8kS3dI32T4iLMQTgoo/uaduNvix6IC7/fsObmlhneA=; b=pQ5ep3wVfk1TrgXMj9F7XkgQcm9Up/0Xqf90pGo3X6YK7oW99zLO1qaxolzxnAViRE 8g5shygaZJF1EcsddL85GCLOMPqap8uPd1U21D8xf5VK/KPMzfBUQf+CO8ZXmuMvY7u+ fdBBepH2Syl8Y8RbT9EU7slEOLibIEgWCYuZLoEgoBZXn3EOO51rqw6bmWbFPBDI4J5J S93tZ3AhXKSOgzaFvGpNs/9cLZTzkc6HRfp0w0LF8YrHUonWkR0KN0+GJVyPhYuVM+8R q8mE75Dr/Kn2hpgp2XnAvLmXY7n2R6K+ohvtYy7ujGnzcvAKMMwozuPOwq+pQxWxAyqA w9ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766565691; x=1767170491; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/8kS3dI32T4iLMQTgoo/uaduNvix6IC7/fsObmlhneA=; b=VIjZnsmZrRa39yMxlpuwb4JuckZOUATZUgRhPIjcDRHe6P0n9UlUMBaCm8uls4PhRv YJxIQ830Q1q0UrJU+K7yqYPA6fEqOanlYbrSwS91PQlB7fga4iiK0gvcRLbh/F/xwNYi K5jN/iNd00lOjjgfyxJOmdsXoXDGTgpRQ/D+jceCGUYO1CUGL95BUYhwgSmG4uZ0SIJO i8MU745GlK/9GFVwZ2MC6chQI4cLmgB5vU2KqhYygYtUnA3YK3wxjE7hP2LqQqsOQ8bJ t4yVBP84ZAiohqU1IIir7K1IopgBJJA7IneMRly7Bse41Ai0GaSMIbVYfQu4Sp2Pv/BC x37A== X-Forwarded-Encrypted: i=1; AJvYcCXVYx0yNqI55o2lfANm4NYJqjWCt+RDyn1Un5gpnneY0aCpO6OVA01MujFlQ2ZjkWCr2FnMdqj584kitFA=@vger.kernel.org X-Gm-Message-State: AOJu0YzTVf+90k1jHSKp9KhKD/zAgladkDVs9/wCyLJfbD5c7X3Bbk09 MvKNMAnozr4rV7yrWjKRwtzpfhYxRhfFlkLnvnWeeS+9QQNbilaYbrhaGNZ4r+vostZcWgGrDgN ODQ== X-Google-Smtp-Source: AGHT+IEyqeTMoaShXNRUvtHOhlYNvGlKrvndvLDnIj+Cloeh6LxSFejF5eSTr8OUrR3lJf2+Y5Rv2yfKdg== X-Received: from pjbei18.prod.google.com ([2002:a17:90a:e552:b0:343:af64:f654]) (user=wakel job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d54b:b0:2a2:d2e8:9f25 with SMTP id d9443c01a7336-2a2f28368eamr173738215ad.33.1766565691337; Wed, 24 Dec 2025 00:41:31 -0800 (PST) Date: Wed, 24 Dec 2025 16:41:20 +0800 In-Reply-To: <871plslxsw.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <871plslxsw.ffs@tglx> X-Mailer: git-send-email 2.52.0.351.gbe84eed79e-goog Message-ID: <20251224084120.249417-1-wakel@google.com> Subject: [PATCH] kselftest/harness: Use helper to avoid zero-size memset warning From: Wake Liu To: tglx@linutronix.de, kees@kernel.org, shuah@kernel.org, nathan@kernel.org Cc: luto@amacapital.net, wad@chromium.org, nick.desaulniers+lkml@gmail.com, morbo@google.com, justinstitt@google.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Wake Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When building kselftests with a toolchain that enables source fortification (e.g., Android's build environment, which uses -D_FORTIFY_SOURCE=3D3), a build failure occurs in tests that use an empty FIXTURE(). The root cause is that an empty fixture struct results in `sizeof(self_private)` evaluating to 0. The compiler's fortification checks then detect the `memset()` call with a compile-time constant size of 0, issuing a `-Wuser-defined-warnings` which is promoted to an error by `-Werror`. An initial attempt to guard the call with `if (sizeof(self_private) > 0)` was insufficient. The compiler's static analysis is aggressive enough to flag the `memset(..., 0)` pattern before evaluating the conditional, thus still triggering the error. To resolve this robustly, this change introduces a `static inline` helper function, `__kselftest_memset_safe()`. This function wraps the size check and the `memset()` call. By replacing the direct `memset()` in the `__TEST_F_IMPL` macro with a call to this helper, we create an abstraction boundary. This prevents the compiler's static analyzer from "seeing" the problematic pattern at the macro expansion site, resolving the build failure. Build Context: Compiler: Android (14488419, +pgo, +bolt, +lto, +mlgo, based on r584948) cl= ang version 22.0.0 (https://android.googlesource.com/toolchain/llvm-project= 2d65e4108033380e6fe8e08b1f1826cd2bfb0c99) Relevant Options: -O2 -Wall -Werror -D_FORTIFY_SOURCE=3D3 -target i686-linu= x-android10000 Test: m kselftest_futex_futex_requeue_pi Change-Id: If4fdfe6ffcbe9736fbd8f66b2453e8cbbb95e25e Signed-off-by: Wake Liu --- tools/testing/selftests/kselftest_harness.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/se= lftests/kselftest_harness.h index 3f66e862e83eb..159cd6729af33 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -70,6 +70,12 @@ =20 #include "kselftest.h" =20 +static inline void __kselftest_memset_safe(void *s, int c, size_t n) +{ + if (n > 0) + memset(s, c, n); +} + #define TEST_TIMEOUT_DEFAULT 30 =20 /* Utilities exposed to the test definitions */ @@ -416,7 +422,7 @@ self =3D mmap(NULL, sizeof(*self), PROT_READ | PROT_WRITE, \ MAP_SHARED | MAP_ANONYMOUS, -1, 0); \ } else { \ - memset(&self_private, 0, sizeof(self_private)); \ + __kselftest_memset_safe(&self_private, 0, sizeof(self_private)); \ self =3D &self_private; \ } \ } \ --=20 2.52.0.351.gbe84eed79e-goog