Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36175550rwd; Mon, 10 Jul 2023 19:35:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlHvxallqjkE5PRce1fnk29zAHhz8lv2OeZuBO7z9M95nUj4lL0+3jRgf8lZGm7lUqi8FLWl X-Received: by 2002:a05:6358:3386:b0:135:515c:38ee with SMTP id i6-20020a056358338600b00135515c38eemr7131844rwd.25.1689042955078; Mon, 10 Jul 2023 19:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689042955; cv=none; d=google.com; s=arc-20160816; b=DbHVACRZ1KAzHgDHNt9L8GV0N1X6Y876/jq44qUKNi/tHIWaEDGN6BryTzheG8ImHM q2kR3mNw8bGlzhhVisqRVUpX9/fOQvNdnqCwlfYZHTwv4W44MBtCyv7FIlJwKND2g1/M 0NU9zzNRXybAjKB2Mk8x6chAHc/jpkUXrLAwyjRHgO084Dco0gySx9u+R7WtKKRI7Jaq r57sqQm9G015neL/dcGZJeIgrDmjUIK51T8KC4lAPqyCRNAB7XtgJFRcav+SD3qCDRmq 7EDl2OZFrZ2LgHW7xlvGccS9Qd8QnpnzA/VWXNYap0xLO+OBLeJNcS23+t+qpi6zWwDc +UQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BZDZ6r5wpkW+gDFlK/U7jgzzYLwpzB2atLlaIKBEiEc=; fh=9FWpU0ARbeyLOjuDiX6QIixCSlCf7t+BLdlO+WeAVz0=; b=SVLJTa0DT+1wwKVcHKcH/iuynFwCpRJpxzwmHwF3kiuHzibCCdRNPG1QrU2YhHq923 qiF6aukV044pgRaST9hqun4Mzwl6eUf7Uu2+JIjYpnlYmfQ1zKpD/lK14ogfMyj7fAy3 YalKEgWEKuqNEpI3blzRFQhPppOdN1AsqEeq/d0RzqNZx+JA9OBVU2OfOsxQy9bFrW7B zq0yTZ/6R/noSTtbrjAiUcFyvLDDM6qJGCTlbDhAZM5ijc4RBCMYgIhDJQernUS//+x+ J6ViptUBkNKzO9Y8dhpCjv9//iX+JUuSBaAo5si0nApIQjjdv6w9S0dAmvMly+9k+lVb KoZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=AbT6dlqB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13-20020a63f04d000000b0055b4ef605easi589504pgj.886.2023.07.10.19.35.42; Mon, 10 Jul 2023 19:35:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=AbT6dlqB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231494AbjGKCOt (ORCPT + 99 others); Mon, 10 Jul 2023 22:14:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229911AbjGKCOs (ORCPT ); Mon, 10 Jul 2023 22:14:48 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 800FAE1; Mon, 10 Jul 2023 19:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=BZDZ6r5wpkW+gDFlK/U7jgzzYLwpzB2atLlaIKBEiEc=; b=AbT6dlqBzLhxoNuN17BMaOZQP2 aiJzb+0XU5zblE1Gy8s85PfoWZuy+PQzTrG6OdX97x5S4W3zLgr2Y8LYWWNH1kPvHPAdZljIRUN1p MK/YNjFJ1a3Md9zICwfNW04jvb2D//EvniyaKnUeD8Cj80VFqfulmV86LQP3QYgMxvgeFzxIzxeLA gSI6uR+GMMiuxTCOZKy3lRkoqMVKvkvL3vjBc6jGf7pbtNVSRmxpspl46kzh4wB2PNlCh4FvGiQJf 7f6trkMKFzWutLX+vz0eWf6/xf+/VraJ5Zn+/De8kDbEvirw03uCdaXbevL9rgHMoTg/EI0M6PcIz 1XTL/U5g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qJ2to-00FCaw-53; Tue, 11 Jul 2023 02:14:44 +0000 Date: Tue, 11 Jul 2023 03:14:44 +0100 From: Matthew Wilcox To: Andrew Morton Cc: linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 01/38] minmax: Add in_range() macro Message-ID: References: <20230710204339.3554919-1-willy@infradead.org> <20230710204339.3554919-2-willy@infradead.org> <20230710161341.c8d6a8b2cbf57013bf6e0140@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230710161341.c8d6a8b2cbf57013bf6e0140@linux-foundation.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 10, 2023 at 04:13:41PM -0700, Andrew Morton wrote: > > +/** > > + * in_range - Determine if a value lies within a range. > > + * @val: Value to test. > > + * @start: First value in range. > > + * @len: Number of values in range. > > + * > > + * This is more efficient than "if (start <= val && val < (start + len))". > > + * It also gives a different answer if @start + @len overflows the size of > > + * the type by a sufficient amount to encompass @val. Decide for yourself > > + * which behaviour you want, or prove that start + len never overflow. > > + * Do not blindly replace one form with the other. > > + */ > > +#define in_range(val, start, len) \ > > + sizeof(start) <= sizeof(u32) ? in_range32(val, start, len) : \ > > + in_range64(val, start, len) > > There's nothing here to prevent callers from passing a mixture of > 32-bit and 64-bit values, possibly resulting in truncation of `val' or > `len'. > > Obviously caller is being dumb, but I think it's cost-free to check all > three of the arguments for 64-bitness? > > Or do a min()/max()-style check for consistently typed arguments? How about #define in_range(val, start, len) \ (sizeof(val) | sizeof(start) | size(len)) <= sizeof(u32) ? \ in_range32(val, start, len) : in_range64(val, start, len)