Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3721828rwd; Sat, 10 Jun 2023 13:22:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4mICNFB8dvZYMwpRYzauIFzujXE82zwPecpze6Y1hs+JYHvI1e8VuxeOL10AIq6t8fNVYZ X-Received: by 2002:a05:6a00:188c:b0:64c:ecf7:f49a with SMTP id x12-20020a056a00188c00b0064cecf7f49amr6491161pfh.21.1686428534794; Sat, 10 Jun 2023 13:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686428534; cv=none; d=google.com; s=arc-20160816; b=lSSQfdShEcTz4INnB+Zftlm8mlH5dg4xg1YZ2uUxnrq5LrGrAhPVCY7Aih34BzMdqa 8+kcs9nRH1+8jfAjCk966tZz0s5COI9OGWzpSWfKWz/hhGWe1P1GThKApRuLZtmiFEf+ ydOBID5xm1ehD+P20aldUl71LK35/nnvDMvtcTFDkN/ODG5iAS5QW29EF7eDV5dlnhrw lCQNxPYejFtrjuFV5+1TnD90yWusaVBeeWkSalTofoCRqtjeW0xPftH/eP/7IOBC9mfQ M5R1k1YfjGvaOvnGctQX9P6UX9ARCECpRy4Mw5yK1SmKo91FN8wMLcOxAJ+53RsBlUUG ABZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=wPt3icLjnPmYanY+1VhF8dGxIIqDaxQvuMQvfe+DYMA=; b=EH7PD2+xvSPMUycPD6hDlGjisZJn6m5SFJHMUNbbU9WBpAUlcnNtwxFu49vzqu2UEw J3cE1sJtQAnSVCKHZeFt6SYD91svthQpZTNkw7v/DJu3hBnhSFRxgDu8y4SmqgZh8uRn Ve1YZY903Kk7MOSMXAZPDoiPHCki7Q1M1IbSMYWgoJY4NLoZmKg55zmshz6wI6YjTqxs dF6Hz3QPnaj+091kEs4HORkWJzRo3uzbmGHIYjPJvIuDniekTlTp+XKIxV88voMLAE4e m0jz41G4/ahwu4kpUk0OWPkHcVw6wggn+a4zSTHtmQgNQaLwPVZFky51/3Ie/HNj3FFx sCxg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020aa796c2000000b00662186eb4eesi4499545pfq.273.2023.06.10.13.22.03; Sat, 10 Jun 2023 13:22:14 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231552AbjFJUJi convert rfc822-to-8bit (ORCPT + 99 others); Sat, 10 Jun 2023 16:09:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231128AbjFJUJh (ORCPT ); Sat, 10 Jun 2023 16:09:37 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5483358E for ; Sat, 10 Jun 2023 13:09:35 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-310-2DLACrxANTCZx5d8sgYTVQ-1; Sat, 10 Jun 2023 21:09:32 +0100 X-MC-Unique: 2DLACrxANTCZx5d8sgYTVQ-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 10 Jun 2023 21:09:28 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sat, 10 Jun 2023 21:09:28 +0100 From: David Laight To: 'Lorenzo Stoakes' , Lu Hongfei CC: Andrew Morton , Uladzislau Rezki , Christoph Hellwig , "open list:VMALLOC" , open list , "opensource.kernel@vivo.com" Subject: RE: [PATCH] mm/vmalloc: Replace the ternary conditional operator with min() Thread-Topic: [PATCH] mm/vmalloc: Replace the ternary conditional operator with min() Thread-Index: AQHZmq9RsZ2mMErDwEmVNd3QmnYBSK+Ed3Zw Date: Sat, 10 Jun 2023 20:09:28 +0000 Message-ID: References: <20230609061309.42453-1-luhongfei@vivo.com> <832d7c69-ffd5-4764-8ffe-3a02bef0efb0@lucifer.local> <3fc87d60-4e81-4f49-95f0-0503ad5cdf35@lucifer.local> In-Reply-To: <3fc87d60-4e81-4f49-95f0-0503ad5cdf35@lucifer.local> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, 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 From: Lorenzo Stoakes > Sent: 09 June 2023 09:49 > On Fri, Jun 09, 2023 at 08:09:45AM +0100, Lorenzo Stoakes wrote: > > On Fri, Jun 09, 2023 at 02:13:09PM +0800, Lu Hongfei wrote: > > > It would be better to replace the traditional ternary conditional > > > operator with min() in zero_iter > > > > > > Signed-off-by: Lu Hongfei > > > --- > > > mm/vmalloc.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > index 29077d61ff81..42df032e6c27 > > > --- a/mm/vmalloc.c > > > +++ b/mm/vmalloc.c > > > @@ -3571,7 +3571,7 @@ static size_t zero_iter(struct iov_iter *iter, size_t count) > > > while (remains > 0) { > > > size_t num, copied; > > > > > > - num = remains < PAGE_SIZE ? remains : PAGE_SIZE; > > > + num = min(remains, PAGE_SIZE); > > OK, as per the pedantic test bot, you'll need to change this to:- > > num = min_t(size_t, remains, PAGE_SIZE); There has to be a valid reason why min/max have strong type checks. Using min_t() all the time is just subverting them and means that bugs are more likely than if the extra tests in min() were absent. The problem here is that size_t is 'unsigned int' but PAGE_SIZE 'unsigned long'. A 'safe' change is min(remains + 0ULL, PAGE_SIZE). But, in reality, min/max should always be valid when one value is a constant between 0 and MAX_INT. The constant just needs forcing to 'signed int' (eg assigning to a temporary on that type) before the comparison (etc). David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)