Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5056447pxj; Wed, 26 May 2021 01:32:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGcY9HxLDNoodGGyai9MGmFgjLMTzkzCw78EF5cuMXJKoFbFsg8iQ+e67NI9kMmoZGo2sy X-Received: by 2002:a17:906:c448:: with SMTP id ck8mr32745794ejb.497.1622017948424; Wed, 26 May 2021 01:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622017948; cv=none; d=google.com; s=arc-20160816; b=GTdWPzaRhTpMjeQ5MEtMTUzAw+q5xLqRhFgSJ0Na4IXfNclZXwRM8kTuJl5F237Srp ooGd8omPKr8vBCnVZc1LSNH7OXLFMP8IB/KsV8NIBy4WltQhjkozE1E3xUGBwXtmJ9Ux bR/N7cWub4c3IQXgn8hYo33e9DziD8yPZsGRob8JB8abp4aL5NHgwykn+XJbSZfg+1o2 JqejC2Suz3i19k9pSyeBlenbzcBX7+AEGmhTpjyORpINrpUTIa38jhqfSZj5EeTWX77V wln9EPXyXSVePclo9tYurt+6N9/dROAlGiokYSJKHjkt0Y4FSDJ3IvaLFfAjHWbIXCOO JeAQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=VD4DdgkLEwMBLxi8WhssAYJk4yFTL82j5cYeHw+xrZg=; b=dimNt3XocSBoBmLnUmkWQeBsmglEgITozAqvC+v/ssAPSrElTiyv0JZtSHp4NlDRRv KWkltYYbzRImJtsCjvg+nBnWV/bCCL0JnHYTAVYUTY9FLMxK49ikDff2oqu++jEbzdZd AJsoSlOPuRncJpVUwMqU88YTxvIyeGcaX4Bx7ebaJw++ea+bFgmKuHBf+zNL7yX/5+LP 6cjzM6c4DzjwLElmSL6OQDJ8naswouhe9YBaESuoiztvOHs8BCHPA97jJTolAIQdRUqc PPmZNF2Gjtx1G7dhO1SYnqAvLC/VbSYm6zvwbziJq4NClWPHMRJ/HPA1Hc/IsPcFwWsV L7Wg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si16467713edw.467.2021.05.26.01.31.54; Wed, 26 May 2021 01:32:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232659AbhEZIdO (ORCPT + 99 others); Wed, 26 May 2021 04:33:14 -0400 Received: from mail105.syd.optusnet.com.au ([211.29.132.249]:39008 "EHLO mail105.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231410AbhEZIdO (ORCPT ); Wed, 26 May 2021 04:33:14 -0400 Received: from dread.disaster.area (pa49-180-230-185.pa.nsw.optusnet.com.au [49.180.230.185]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id CD4E1104350A; Wed, 26 May 2021 18:31:38 +1000 (AEST) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1llowz-005N7h-2k; Wed, 26 May 2021 18:31:37 +1000 Date: Wed, 26 May 2021 18:31:37 +1000 From: Dave Chinner To: Christophe Leroy Cc: Wu Bo , linfeilong@huawei.com, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, linux-fsdevel@vger.kernel.org, davem@davemloft.net, herbert@gondor.apana.org.au, viro@zeniv.linux.org.uk Subject: Re: [PATCH 1/2] crypto: af_alg - use DIV_ROUND_UP helper macro for calculations Message-ID: <20210526083137.GK2817@dread.disaster.area> References: <1621930520-515336-1-git-send-email-wubo40@huawei.com> <1621930520-515336-2-git-send-email-wubo40@huawei.com> <20210525103744.Horde.nmFFeC3J2_-Qdu7udOYa8g1@messagerie.c-s.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210525103744.Horde.nmFFeC3J2_-Qdu7udOYa8g1@messagerie.c-s.fr> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=YKPhNiOx c=1 sm=1 tr=0 a=dUIOjvib2kB+GiIc1vUx8g==:117 a=dUIOjvib2kB+GiIc1vUx8g==:17 a=8nJEP1OIZ-IA:10 a=5FLXtPjwQuUA:10 a=i0EeH86SAAAA:8 a=7-415B0cAAAA:8 a=PjDj1IsLZaY1bt5ZHPIA:9 a=wPNLvfGTeEIA:10 a=biEYGPWJfzWAr4FL6Ov7:22 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, May 25, 2021 at 10:37:44AM +0200, Christophe Leroy wrote: > Wu Bo a ?crit?: > > > From: Wu Bo > > > > Replace open coded divisor calculations with the DIV_ROUND_UP kernel > > macro for better readability. > > > > Signed-off-by: Wu Bo > > --- > > crypto/af_alg.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/crypto/af_alg.c b/crypto/af_alg.c > > index 18cc82d..8bd288d 100644 > > --- a/crypto/af_alg.c > > +++ b/crypto/af_alg.c > > @@ -411,7 +411,7 @@ int af_alg_make_sg(struct af_alg_sgl *sgl, struct > > iov_iter *iter, int len) > > if (n < 0) > > return n; > > > > - npages = (off + n + PAGE_SIZE - 1) >> PAGE_SHIFT; > > + npages = DIV_ROUND_UP(off + n, PAGE_SIZE); > > You should use PFN_UP() No. We are not using pfns here - we're converting a byte count to a page count. Besides, "PFN_UP" is a horrible, awful api. It does not decribe what it does and anyone who is not a mm developer will look at it and ask "what does this do?" and have to go looking for it's definition to determine what it does. Yes, that's exactyl what I've just done, and I really wish I didn't because, well, it just reinforces how much we suck at APIs... OTOH, what DIV_ROUND_UP() does is obvious, widely understood, self documenting and easy to determine if the usage is correct, which indeed this is. The lesson: do not use whacky obscure, out of context macros when a simple, obvious, widely known macro will give the same result and make the code easier to understand. Cheers, Dave. -- Dave Chinner david@fromorbit.com