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 EEDCBCDB482 for ; Wed, 18 Oct 2023 21:44:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231886AbjJRVoB (ORCPT ); Wed, 18 Oct 2023 17:44:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344486AbjJRVnz (ORCPT ); Wed, 18 Oct 2023 17:43:55 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE79114 for ; Wed, 18 Oct 2023 14:43:53 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AFC1C433C9; Wed, 18 Oct 2023 21:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1697665433; bh=4SXwsuXnZ1xDM5ixonFXac/+3zHzm/aBUChghLSq6f4=; h=Date:To:From:Subject:From; b=hoeXL/VJHDJv2EynTKBFLsY9xjeLB/ALlsrasZedeSUBVNiLlI5N0lp418+cumIF/ 5tANR4x76ezeX2xTvk7kFg+FJSZ2fnkucIxAT00Vy56f7hwA8DhkHD7o0ruEaqd+KD uK5UKi4t7BcRGOPpLiYJISS+SvVbDI8cyz2Tl4EU= Date: Wed, 18 Oct 2023 14:43:52 -0700 To: mm-commits@vger.kernel.org, willy@infradead.org, torvalds@linux-foundation.org, Jason@zx2c4.com, hch@infradead.org, david.laight@aculab.com, andriy.shevchenko@linux.intel.com, David.Laight@ACULAB.COM, akpm@linux-foundation.org From: Andrew Morton Subject: [merged mm-nonmm-stable] minmax-relax-check-to-allow-comparison-between-unsigned-arguments-and-signed-constants.patch removed from -mm tree Message-Id: <20231018214353.0AFC1C433C9@smtp.kernel.org> Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The quilt patch titled Subject: minmax: relax check to allow comparison between unsigned arguments and signed constants has been removed from the -mm tree. Its filename was minmax-relax-check-to-allow-comparison-between-unsigned-arguments-and-signed-constants.patch This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm ------------------------------------------------------ From: David Laight Subject: minmax: relax check to allow comparison between unsigned arguments and signed constants Date: Mon, 18 Sep 2023 08:19:25 +0000 Allow (for example) min(unsigned_var, 20). The opposite min(signed_var, 20u) is still errored. Since a comparison between signed and unsigned never makes the unsigned value negative it is only necessary to adjust the __types_ok() test. Link: https://lkml.kernel.org/r/633b64e2f39e46bb8234809c5595b8c7@AcuMS.aculab.com Signed-off-by: David Laight Cc: Andy Shevchenko Cc: Christoph Hellwig Cc: Jason A. Donenfeld Cc: Linus Torvalds Cc: Matthew Wilcox (Oracle) Signed-off-by: Andrew Morton --- include/linux/minmax.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) --- a/include/linux/minmax.h~minmax-relax-check-to-allow-comparison-between-unsigned-arguments-and-signed-constants +++ a/include/linux/minmax.h @@ -10,13 +10,18 @@ /* * min()/max()/clamp() macros must accomplish three things: * - * - avoid multiple evaluations of the arguments (so side-effects like + * - Avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. - * - perform signed v unsigned type-checking (to generate compile - * errors instead of nasty runtime surprises). - * - retain result as a constant expressions when called with only + * - Retain result as a constant expressions when called with only * constant expressions (to avoid tripping VLA warnings in stack * allocation usage). + * - Perform signed v unsigned type-checking (to generate compile + * errors instead of nasty runtime surprises). + * - Unsigned char/short are always promoted to signed int and can be + * compared against signed or unsigned arguments. + * - Unsigned arguments can be compared against non-negative signed constants. + * - Comparison of a signed argument against an unsigned constant fails + * even if the constant is below __INT_MAX__ and could be cast to int. */ #define __typecheck(x, y) \ (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) @@ -26,9 +31,14 @@ __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))), \ is_signed_type(typeof(x)), 0) -#define __types_ok(x, y) \ - (__is_signed(x) == __is_signed(y) || \ - __is_signed((x) + 0) == __is_signed((y) + 0)) +/* True for a non-negative signed int constant */ +#define __is_noneg_int(x) \ + (__builtin_choose_expr(__is_constexpr(x) && __is_signed(x), x, -1) >= 0) + +#define __types_ok(x, y) \ + (__is_signed(x) == __is_signed(y) || \ + __is_signed((x) + 0) == __is_signed((y) + 0) || \ + __is_noneg_int(x) || __is_noneg_int(y)) #define __cmp_op_min < #define __cmp_op_max > _ Patches currently in -mm which might be from David.Laight@ACULAB.COM are