From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E161EB64DC for ; Tue, 11 Jul 2023 02:14:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 997B78E0001; Mon, 10 Jul 2023 22:14:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 947B68D0001; Mon, 10 Jul 2023 22:14:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8365E8E0001; Mon, 10 Jul 2023 22:14:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 71D378D0001 for ; Mon, 10 Jul 2023 22:14:52 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 39DB8A0170 for ; Tue, 11 Jul 2023 02:14:52 +0000 (UTC) X-FDA: 80997712824.04.CF62985 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id 0F15820005 for ; Tue, 11 Jul 2023 02:14:47 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=AbT6dlqB; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689041689; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BZDZ6r5wpkW+gDFlK/U7jgzzYLwpzB2atLlaIKBEiEc=; b=vE9pklaXiHGfl1RoPIIP0SpvDO2sbB6h7jq9e2mklU/TYZ6i6BTY0ZzoHOnsMvyLbzIeFt r9isUWPyhalf7pqluHf3MpKs3C/BN/G6RifR7SJc7OFZBbXzvTMMtMPzzd2xPDDNL00HRo 2ogKTJou9vuI3HvApjq0riqBw9lumiI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689041689; a=rsa-sha256; cv=none; b=6L6aQ87KG8CaCOS9f4mV872SD6rlJOzVDqRrw1gTuDU834KgMr+Z6lxJwX6PJHnqDxdjg2 zNavyeVylfND0p/1JiDNOtD2nOQ69pQWyxJO9auY5SXtVTXwqkbubA8RxE555pEn218tFJ JgmbCBnsEPDssMbhhmkV3FlcRoP39UE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=AbT6dlqB; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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-Stat-Signature: mtbdpbxxypy9wdo5dsnaid7fd6ac4py5 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0F15820005 X-Rspam-User: X-HE-Tag: 1689041687-203488 X-HE-Meta: U2FsdGVkX18gVO0uh1N8SykLNK4I1gsLF/k4Q7/o/Zm0lercNOIoPrkMPbt8MzdcGbmDYCHOuBbTvijLIHfLp0eFeqnKzdKQagNoIiUJYVu19eyFuJYdqiM3L1Qe3N5FUB2SGnBNjOc1uL2TlrkiGoLFtHtrwiCJ8Ur+/wzCN7OVnqQ6pncnaEIFYSOof9Y6KYVvab5xWtMoFM4KIWXS34NHe1xmJkJeGvBONGdnlvvXTsoKJgvDURAUvLh1EZgNFQ7aYJI3MnhwNnu7goeJBMBQyO5TJ41+9NCzwBL08toXKFU+d75AAYizRDidvRxBDYVwyUOhySkAW09vxGx++8nMHcYGk+DsPztzLkfNC4zt8olBqZdomHtZVoUsFSgFC4DTA+0dOsEt8JuouAQ3T1omlws4jE21+B5c/ZBPtZTJh1tk2v3PT7IRH3laBppL5+6xZAU5oVOcRsMKkuB/AKKpIckE+0e53PJZWGUwZWZZf10fYSYnL8Y3k24Y2FQfz4rqsabZfR80780FEo0qYE8n9eNvGEfYKz0Jl87MZSogq2x6a8CaFvd4iOZrBaFbp5VMVDljK1S43+zdzWrMeRgyiJeuMV8dhD2316E92nsx+MUwEO72aVdTg4v/6DffvAgPGlQ4DrnyF4d/FsUw2WspUJyVO7H5qVk4RIN6hNSf7xeK4RFGZMIPvr2nSQqYYl+w70Auy2oo9G+/FR/MlIJYM/onKFUi8YG0YqQ2L0qGEa+KwpqkX33di6sNYgPv6EXtsWOdOACytYb56XR1DjYs55X1JT+QXdVVq2u+U6IKXw9v8s+twQK6pfLi6UP9zdK75dpi2BKXnkCF+yWBiCrAOZKv9MpKwPRFC9nuV0dps3OSEFTbnpaS0j0sF0VZnq0J2LehIlxX6QdyyRpLtSPBOBZsGGpFMC/bkXL4PTU4zC6FoiqjFv+ZyOBzivYd9RBGMaxCB9OPcPVjMh3 ophnED6e 6nFgDU6Vxf30vhyCD8LyZNmzLJWqoxL2kQv94N0ZbuLB6F8xka9VLqqQruJynISUfvabs5pRnqgsCPHxxIKOnCDzehKwTfh5tZ2o31Mfox6kquuhVUkde61OM6cMzArrmNta9FpBIhPMjCql8rKeYv9F9T73kzLAJYkNFMTWdYL6+qxuKHXVKGijmmQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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)