Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp37080676rwd; Tue, 11 Jul 2023 09:10:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlFBe5qmZdxH2rP7usa7Cpha48DJdo1pwyaisF1po6SW1ytkn8Bhz27s7/KhzL7vtSa1IuER X-Received: by 2002:a17:903:1c5:b0:1b6:8863:8c9f with SMTP id e5-20020a17090301c500b001b688638c9fmr13726807plh.6.1689091855987; Tue, 11 Jul 2023 09:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689091855; cv=none; d=google.com; s=arc-20160816; b=g3/TDsjrqhvbmODFKywSZB0XmE7V0nLdDXaYvNfmchWd975O++Wj/wp14ELh+5ePOG hKuIx3e2BxOaH/haQP9fGOYB3pdjcSzxCk2MH98CKhWWOp2U7pf9iJ+La8bXsA9Xe/PJ vbAWyD2Q7AybMyWXw6FOmyODZNak5v1Iz0yfaW42ooVbafbw3F1WtkEbOJC8b020qjG4 YqaZKTCBfSxL4NHCO5q3CyO9GdLH7XxmK/5CrjXOfCtG3XZ9osLsdimxwnKGGgEXNFky LIoDjJt5k3o9tNXBMt6otJDyQK1gUjE968ie8Fbl3FvAPo6MKrKIrKs2Ws+j0s683esJ IsLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=50T3d3UAYbmunWbjYU70AIU+IAzFPQ5T7lPgOd1ys6g=; fh=WH96hErZs3rLqSRIs5BU28TgbpVSxbccCV06cHhl3Ik=; b=LvO0YZl/e/HSogILqkPs1Rn+7owvPV/7IwOEdCjpGd8LmhL9W1JEaL3BcfunFAIzBt ZEZmHnstBllwBj3+3AwAaIfCFbYxWlJ/SRUf5SA4uv0fW3SXcg1VD84tIXS059WLNa+j ism/awudG+lcc466RARu6iWb/abRPIBqRg7lGRSx/xFjkOGfWainGjbczL2wnq0eVfA7 cIG01QBbsdq0Wsq5SwytPFq+/lhH/yfdtEp7UVfx9A++/Aid0wW9DOWTx4QqEf/4mCMP pGpTAngdbJZLD0FKHDdJBO9g7LBaiKZPO9zV/1MruexQoshdttrbEdlW8LsnA22grkX5 FPpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=BoKijjfv; 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 z16-20020a170903019000b001b864e277e1si1842281plg.494.2023.07.11.09.10.19; Tue, 11 Jul 2023 09:10: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=@linux-foundation.org header.s=korg header.b=BoKijjfv; 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 S231755AbjGKPuC (ORCPT + 99 others); Tue, 11 Jul 2023 11:50:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229987AbjGKPuB (ORCPT ); Tue, 11 Jul 2023 11:50:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D14BF0; Tue, 11 Jul 2023 08:50:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3103D61515; Tue, 11 Jul 2023 15:50:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63951C433C7; Tue, 11 Jul 2023 15:49:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1689090599; bh=1M8nmB54EZY/+b8my3a6BRvNuquZWY4tkJH0mqxJC+w=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BoKijjfvqvv6NbUyE/VuntEq0ELyssdgeVkybVbYFPfbtEz1VefthvwapIjaumpVB +PbmD9siI2vBoZVtSyejupQbkm7KVC1DthD2GDhKgPSjvUiPxtwYJQ5vZS62Luf/l9 4Pq5qrGeuQ6KnzuOpBqfi3YC2uJTfLDukkZrp3zo= Date: Tue, 11 Jul 2023 08:49:58 -0700 From: Andrew Morton To: Matthew Wilcox 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: <20230711084958.8fdbb0fc4f80c6d9bbaf0ca3@linux-foundation.org> In-Reply-To: References: <20230710204339.3554919-1-willy@infradead.org> <20230710204339.3554919-2-willy@infradead.org> <20230710161341.c8d6a8b2cbf57013bf6e0140@linux-foundation.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,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 Tue, 11 Jul 2023 03:14:44 +0100 Matthew Wilcox wrote: > 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) It saves some typing ;) sizeof(val+start+len)?