Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2442665rwo; Thu, 3 Aug 2023 09:23:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlFU/RRMLVNZftaD5FtfM/U8G7su1uKDcjeEJWlIkoTH+YDF5A46ddKPv6JZTxjMfpY6Vfht X-Received: by 2002:a9d:61d5:0:b0:6bc:8cb4:f1fc with SMTP id h21-20020a9d61d5000000b006bc8cb4f1fcmr17693252otk.27.1691079823530; Thu, 03 Aug 2023 09:23:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691079823; cv=none; d=google.com; s=arc-20160816; b=nHJDplCl5wsHT3tBLt+08SRtn49HNZ9cVYkITU+M3WuaRyaE49abCD6guFGSsee8hC mjnM8MHL4cZSrddW019PGav846F4TChaelexl4HK9EFV5K+j7hAZJC5DMNxbL2XI+7Pw 8MhApIzDIPfugFsHvWK6p9FL6n50fQiHFMJm9HQE/mORk78dU6q6Z+br1QMYW4qovRTS TAfJo1Y0PduoQa0Eik8BFQ6qqgk9+yKJTLxk0E2/WFj+HUZcLomDgnZhNc7+m2dzorwv fa2o8H48e61tufv5zfipY/1XtQ1jwK/Qzh9yqAMqQZhb7+B+/GUHnnAxKKLfXE7zJb6I m95w== 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=LnL/w0gerl2bmZjXzcUrorqUHH4MeidXJZnUY3FnBf8=; fh=JPd/I49fHpe6Kfw18DNjk3nOg0e1CVtPe3+PmsZcIvQ=; b=DwNO11bNmGzzcE+59NNjSUSRa9mP02Rv9i1Eo4HM+LXbVZiNsXvl2ocgmo5YNsibaa vJeGYhLVnclhtfmF2dadK6cGHRc6LYqNlKlbqA3wJYPLdCvb1RFbgUdTgKUd7LGnYha3 l1v0IqzB5izCGqbW3ypLk/RN+LYsPQz9IPKOrgPl/+1r4QJnTUwZJ1WsPD8xz/c61hMf fXOnjLW/c4y5LZr4cFrLWX8eO5TDEYY00wv9k8rdNklSFmLBJR9zQihJyMW/djfXzhqk TW1Q8tvamgTFF2XEDtPxjz10RiAhnGUzGjKBp2U0B4SYoGoKnyfUdlPT+4caMfk6F2pQ kIWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=tl66j6LV; 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 t189-20020a6381c6000000b00553b783ad97si142038pgd.228.2023.08.03.09.23.30; Thu, 03 Aug 2023 09:23:43 -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=tl66j6LV; 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 S235666AbjHCNXJ (ORCPT + 99 others); Thu, 3 Aug 2023 09:23:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235722AbjHCNW5 (ORCPT ); Thu, 3 Aug 2023 09:22:57 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC369134; Thu, 3 Aug 2023 06:22:56 -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=LnL/w0gerl2bmZjXzcUrorqUHH4MeidXJZnUY3FnBf8=; b=tl66j6LVXL/8xk7brEEbkOjnTb qWzPdVREn0HUGqy0AbZR/JqX2T8Bb0c6IIHM2Pgw7Q9Z4ji8BTbs7cYVdRDvNLu5as/rQFfnoxXsD ubsP2nHqvmnJFWHkOsNvw9xLGwiu3TtHORltseCtB4yU4AOe+PFUQDZjzwwEATH5U+UJirW8lA4h2 nJGxcrFeisAuW9vNDS4lbP1raFOXJZe4RGGW6gRjjXsvKwCK29CnM2IIzSsTwDsVtK2Mn7cvA9eok DVxdCD/umCFRYUt37bXhFWjC7xsJGMS776PK1R+VMDAsHIvyqndWJdFJPxgzZOKCFo4ZoP4hw0Lbl 9juj41AA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qRYI2-003td9-EV; Thu, 03 Aug 2023 13:22:54 +0000 Date: Thu, 3 Aug 2023 14:22:54 +0100 From: Matthew Wilcox To: Phi Nguyen Cc: Andrew Morton , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 01/38] minmax: Add in_range() macro Message-ID: References: <20230802151406.3735276-1-willy@infradead.org> <20230802151406.3735276-2-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Thu, Aug 03, 2023 at 09:00:35PM +0800, Phi Nguyen wrote: > On 8/2/2023 11:13 PM, Matthew Wilcox (Oracle) wrote: > > +static inline bool in_range64(u64 val, u64 start, u64 len) > > +{ > > + return (val - start) < len; > > +} > > + > > +static inline bool in_range32(u32 val, u32 start, u32 len) > > +{ > > + return (val - start) < len; > > +} > > + > > I think these two functions return wrong result if val is smaller than start > and len is big enough. How is it that you stopped reading at exactly the point where I explained that this is intentional? +/** + * 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. + */