From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 C687E20459A for ; Sat, 20 Dec 2025 10:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766224927; cv=none; b=ldWBC+pUhDJSpqQ8Jt6mVpW280u/REUuhC9+jZAU7UfZ1DT+udyml3Z+QTgFrQoLj/vjM9OixzCVO0Xq3/dGkhr+GI7LUr3bHuUxyZoQHT8MsibPUQ0jKWQlPvESsxGCf6lhu+WyC7viFUxXZr8wOT9qcSWTjr/roMyj3tCIYPQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766224927; c=relaxed/simple; bh=bxFgAEY81SjNvUJ+kxxs2m1wYC/4BSvGlgWSuaRMhJw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kEDEoACPtW4snbvB0Wt2F9k/DF2cnwjI3WtfzXlkpZB+Eyom+2iqApRzmlRwYMVZONe4QTt1BY5m8anbwPD11sLuqhridqmfmdqWrFVaQyGmHkT+jrizymaGKeim+FvvH2n9eg62EgltXUcO1tWJ3SBop6594cSMvlVpQEYLYag= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=em41QCIU; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="em41QCIU" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-47d1d8a49f5so8062325e9.3 for ; Sat, 20 Dec 2025 02:02:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766224924; x=1766829724; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=6b6TgfZ4l4yfYsx0rUlhXwOOOgK1ZGgIr0RlxGtU3To=; b=em41QCIUfIpTaePp09bYqEG9fP0XivMmMT6qoKVHG8dQQ5lz21fOYZsasKdptPCM5S C0jbJFdWopKnJLWEt0Xz4910XxoiVB7j/Umhjo5OsvhOU6pKrqwKIL4cc6eGAlTflWd2 0DRk13PDiDaGMLe/ZXkfR9FKmt2i5HRG+1/CRPqGUAJvsARDmg789ogFSMD8ts8XZ5Vf rVkguRxaKEB/ktO+1kZqll9fYw3sN7ZBU8Ibt957O1pQgp+nsBjP+RM3cuIxApD2eXle OcW8T6SYggyCZ2hJwQ4YDsgUygxCv7vm+SOiL0LYpqiG/SAD+Lx2qvJCxL10Hqxmkj8I h0xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766224924; x=1766829724; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6b6TgfZ4l4yfYsx0rUlhXwOOOgK1ZGgIr0RlxGtU3To=; b=Mp2VBQ+iVo0uzcHvl90SWMUtGZnXInzWMPCsUt5DIzKXUTuGEuU2TW1iGQWzd2pNvy LUPGFTGPhZWhUUGf6++/VKpuCzn+tgO0jqAq+gSk85aK1+RcGVVFVs8GMG6CqKZBMPrI ARl3PqArxfEx3wmxqrz7rY8KMMMHR617JgriRH7kff4/XZcd4TceDmJoX/9Em4NWhZFn vU48KKxSCy2n3KvxUTrcgaOi+xD0DnaNPQkPZVqdYNunx24oL/Lm2I7SIJXCgXWFm90T Ab6OBhB+uOIu3CQO2R7oZ4E2JSq0H7EoFtuVcaxzVVR3NQN8wInjk6HPEZdlthBmSGKY LJ5A== X-Forwarded-Encrypted: i=1; AJvYcCUs5qvbpYE8/mGsDwRWX5oW1T5Ww5G86PuXM6qPbXL5L6nXv+mvd8sDpAaVm0zbZCz29X8rMq2bPDlvuV4=@vger.kernel.org X-Gm-Message-State: AOJu0Yxiob2EjCKYkW0pqqB/MwYOfnUYUspCbiGl0UlYvCm4tAHWH3qS qenich1jIWx2vqF7UXNg3Mvj4kc9fziOAV1XG56XIuIL6Ggpjg2jq4vk X-Gm-Gg: AY/fxX4JvToQgpZB5mK+PwW9vXepCuxZ2sVZeaO3A4wwywaVV0UhVlXrvqmUBKVQA5R xEblpyRQwMK+3sW5y5p6bftxuQ2NjVmERmRRLu8R74jklCtzNY3TLH6fNNS7yawMXOlpdxguQhq N/En4mT5ncNFsMoiqyjH9B5B6IS/p3NWTcO+KQhJW+TJLg5LV43Ajdo4w/f44KTeQ1YjL0XWm7m IbvFjo4WnCeM+QnlULYQiM/nCPoqQaxsUuoi//v6sa/vRtu3M9uuGP9fYfWv06K1Ylo47TuEog7 /vHsoNSnmNx2FgLV1Rnljh/RCGkWAafb/8UxmrDGH0RrG84CQoomXBV124jrqa72QEzbFRGbI+Z 1IAJgLhL/glJc8v6EUtolxrezPEVbZ1imHGG1J3IAsItFbAAabgCTtJGTzpofMTV/NMQ+37tp1s M3HM80z9rOdFkqcBM3CcFy1RokJqrYlJAtUy+WO9VIQb/bcIeYxolJ X-Google-Smtp-Source: AGHT+IHQOJ0Ua+zWZlb0QPcZUUI/HtzVKK9z+yFIQMbNJiEgWc0RnGqXX7qQpeO5IWGkqcyJJpZw3A== X-Received: by 2002:a05:600c:1d1d:b0:471:d2f:7987 with SMTP id 5b1f17b1804b1-47d1958f9c5mr48722805e9.26.1766224923818; Sat, 20 Dec 2025 02:02:03 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4324eab257asm9840402f8f.38.2025.12.20.02.02.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Dec 2025 02:02:03 -0800 (PST) Date: Sat, 20 Dec 2025 10:02:01 +0000 From: David Laight To: Vincent Mailhol Cc: Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Chris Mason , David Sterba , Kees Cook , "Gustavo A. R. Silva" , Linus Torvalds , linux-kbuild@vger.kernel.org, linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-btrfs@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2 4/4] minmax: remove useless cast in __is_nonneg() Message-ID: <20251220100201.26d9b0db@pumpkin> In-Reply-To: <20251219-remove_wtype-limits-v2-4-2e92b3f566c5@kernel.org> References: <20251219-remove_wtype-limits-v2-0-2e92b3f566c5@kernel.org> <20251219-remove_wtype-limits-v2-4-2e92b3f566c5@kernel.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 19 Dec 2025 23:39:48 +0100 Vincent Mailhol wrote: > The function like macro __is_nonneg() casts its argument to (long long) > in an attempt to silence -Wtype-limits warnings on unsigned values. nak. The cast is needed for pointer types, not for -Wtype-limits. which is why the '#if __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__' test is there. David > > But this workaround is incomplete as proven here: > > $ cat foo.c > #include > > int foo(unsigned int a) > { > return __is_nonneg(a); > } > $ make CFLAGS_KERNEL="-Wtype-limits" foo.o > CALL scripts/checksyscalls.sh > DESCEND objtool > INSTALL libsubcmd_headers > CC foo.o > foo.c: In function 'foo': > ./include/linux/minmax.h:68:57: warning: comparison is always true due to limited range of data type [-Wtype-limits] > 68 | #define __is_nonneg(ux) statically_true((long long)(ux) >= 0) > | ^~ > ./include/linux/compiler.h:350:50: note: in definition of macro 'statically_true' > 350 | #define statically_true(x) (__builtin_constant_p(x) && (x)) > | ^ > foo.c:5:16: note: in expansion of macro '__is_nonneg' > 5 | return __is_nonneg(a); > | ^~~~~~~~~~~ > ./include/linux/minmax.h:68:57: warning: comparison is always true due to limited range of data type [-Wtype-limits] > 68 | #define __is_nonneg(ux) statically_true((long long)(ux) >= 0) > | ^~ > ./include/linux/compiler.h:350:57: note: in definition of macro 'statically_true' > 350 | #define statically_true(x) (__builtin_constant_p(x) && (x)) > | ^ > foo.c:5:16: note: in expansion of macro '__is_nonneg' > 5 | return __is_nonneg(a); > | ^~~~~~~~~~~ > > And because -Wtype-limits is now globally disabled, such a workaround > now becomes useless. Remove the __is_nonneg()'s cast and its related > comment. > > Signed-off-by: Vincent Mailhol > --- > Changelog: > > v1 -> v2: new patch > --- > include/linux/minmax.h | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/include/linux/minmax.h b/include/linux/minmax.h > index a0158db54a04..3e2e3e539ba1 100644 > --- a/include/linux/minmax.h > +++ b/include/linux/minmax.h > @@ -52,9 +52,6 @@ > /* > * Check whether a signed value is always non-negative. > * > - * A cast is needed to avoid any warnings from values that aren't signed > - * integer types (in which case the result doesn't matter). > - * > * On 64-bit any integer or pointer type can safely be cast to 'long long'. > * But on 32-bit we need to avoid warnings about casting pointers to integers > * of different sizes without truncating 64-bit values so 'long' or 'long long' > @@ -65,7 +62,7 @@ > * but they are handled by the !is_signed_type() case). > */ > #if __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__ > -#define __is_nonneg(ux) statically_true((long long)(ux) >= 0) > +#define __is_nonneg(ux) statically_true((ux) >= 0) > #else > #define __is_nonneg(ux) statically_true( \ > (typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)))(ux) >= 0) >