From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f68.google.com (mail-oa1-f68.google.com [209.85.160.68]) (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 31452632 for ; Wed, 31 Dec 2025 20:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.68 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767213086; cv=none; b=p3Ppzxqpf/yL5BSZ7qQtyEdTZuIONo45vDEylia3lC/IAXIYUcHCNq17D35HSCfX4dD2W/gXTEV3h47IvWBRUEtoIXTfhBfOiGR/+IGrK/aMqYszSakxnq9NbB4Lbn6psIqK0Kn9nKFebzVfXW3eNXGoEO7+qbaA16jK2p+mqVw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767213086; c=relaxed/simple; bh=rpAyc043Ax5VQr8+dHc0LhLszXtoHwy4eiOIzYipxz4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kNKBo3EpEPvc6BQ7oaK0JOR7Fv/PWZTaYtazNDWtiqJFr2ktZYBVf5U7Jli1YNBjNLRublhJ1ryeSV43ge6y3tPfltBuY0+6FuS//qEeWC2wPRT4v2lmfWdPLaG3DTMqHki8vxCw8pHatf5WOvDt+9ZytN8uyVrQuc80oY2FhAE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=RUVkNPRf; arc=none smtp.client-ip=209.85.160.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="RUVkNPRf" Received: by mail-oa1-f68.google.com with SMTP id 586e51a60fabf-3f13043e2fdso3681448fac.1 for ; Wed, 31 Dec 2025 12:31:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1767213082; x=1767817882; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=CkgP3P/JOmmU4SQIzQRxbAxKStjjkyO+o9UMdLOwKAc=; b=RUVkNPRfWqbhfLO854COIcA8bXTFtX6KXcjMzI4zy8s2QmINan+FBFrjzmqtsfosxu QKMhMcKmbUKprwQNtYvH0VOUHpkGTGkfUDoyc9Z8AMhrT+Gh7KJC6qcizbkByyMpKZio rVQggbpBUDPQdtDiVuJr9lZh/fd2HyYAgeMlY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767213082; x=1767817882; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CkgP3P/JOmmU4SQIzQRxbAxKStjjkyO+o9UMdLOwKAc=; b=eIYc9ukeVe/L2SJLvampmDCoQJtjiSL/4u0hCfk00sBaQ8JK3wDgWEsEaMn9J9AUxY X8KCUKGx1mbc0f/8ahtvyFdFU2Q7D9tPY2qEMJQdN7Dc3DrnsAKPDB8tE7/oX+I+V5P8 m3gXbmGJiggVaJKd/Gd1daUqdkLOoKw977iGzfe/VdNTIvkREUyrFvZgpko18PcuDimL FUkZMD2ykeN/bhjmxu4mATIiloUOpupHl+KUxRO80VXKwDkPqpgxEsXhirKfFgHBJNCe /YHxfWq5+qrS2WWi3Rx56YF4Yt3aDuSTnCN3A5htVpw5NMpUIOpHMi5xpVvYGgju5o0B 0p9A== X-Forwarded-Encrypted: i=1; AJvYcCXDjrYhnKPdX4v5h9U5Bjg3QMFgtslqF4DCBDIiaIKOT+X83y38kxRDOmyBxiGM7qtcs3Cl6mdVWVypt3A=@vger.kernel.org X-Gm-Message-State: AOJu0YxuSN7tLDiddRbfjYNbSSQ/lWxneznECLHpP/BaOiMafvbVWWh7 2JU5Yfjwh1uQobkaeRz52XCisIYpMCMHVdKdtX2KewxDGkevcLymW216IbABf8NIOBA= X-Gm-Gg: AY/fxX48lGV4SvLX9l3BhfANjJ5Yo7ZsnBLAfpadzTO/SHIn35/CpR4CP1NlJYa4Eun i3wByD92dlbgaqhgaeXmFvjnVNlxKtEeSZPZCzAd4uQZF+8fo0ShnmKkqY20JT+MN4mPRSyszP1 2I7MVwbwnHJmavYb+74ezUrqyuFnaEkPkOB4Ygglp2dS8EJz9RvAR+lxIut6b1NIuCfimOywcxG VObZzUvu0kmyv9RF44Cds5JjEo508sL/EtcIu3rFFr0Ztk3RdU+AAoxYOsvAyr+1+Ttj+kHRPsY ohO+AsEn0xQm9Hz5pqvlH3X2zm0UoDOALYBP8vUtIn85okg/JmkQVHAgp8gCZPqspauhmdNBkjL X+GDALwYrra4SK2J/Rum1GRXkrvYIHc1A4MbCtsX3Ccp6zpA1HJhM4PmgSrtnDCMZkwykBvUvOI RMrLm/DFbRns60TfRN1OCkBqYb4X0TgaWQEA== X-Google-Smtp-Source: AGHT+IFZAkPcKJ2uTeFxS+roZ678AbK78d+9mfwo6bn/TTYmxsIJ+R5E5wssgjSFb8Ze3mX//4DEXQ== X-Received: by 2002:a05:6870:d691:b0:3f5:d9b0:567e with SMTP id 586e51a60fabf-3fda5666a5cmr18296581fac.14.1767213082037; Wed, 31 Dec 2025 12:31:22 -0800 (PST) Received: from [192.168.1.14] ([38.175.187.108]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-3fdaabbadacsm22960637fac.15.2025.12.31.12.31.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Dec 2025 12:31:21 -0800 (PST) Message-ID: <3ee8406b-1789-4a18-8637-120fc0c62a99@linuxfoundation.org> Date: Wed, 31 Dec 2025 13:31:20 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] kselftest/harness: Use helper to avoid zero-size memset warning To: Wake Liu , 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, Shuah Khan References: <871plslxsw.ffs@tglx> <20251224084120.249417-1-wakel@google.com> Content-Language: en-US From: Shuah Khan In-Reply-To: <20251224084120.249417-1-wakel@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/24/25 01:41, Wake Liu wrote: > When building kselftests with a toolchain that enables source > fortification (e.g., Android's build environment, which uses > -D_FORTIFY_SOURCE=3), 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) clang version 22.0.0 (https://android.googlesource.com/toolchain/llvm-project 2d65e4108033380e6fe8e08b1f1826cd2bfb0c99) > Relevant Options: -O2 -Wall -Werror -D_FORTIFY_SOURCE=3 -target i686-linux-android10000 > > Test: m kselftest_futex_futex_requeue_pi > > Change-Id: If4fdfe6ffcbe9736fbd8f66b2453e8cbbb95e25e I removed this before applying. In the future remove these before sending the patch - running checkpatch.pl prompts you to remove it. > 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/selftests/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 @@ > > #include "kselftest.h" > > +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 > > /* Utilities exposed to the test definitions */ > @@ -416,7 +422,7 @@ > self = 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 = &self_private; \ > } \ > } \ Applied to linux-kselftest fixes branch for next rc. thanks, -- Shuah