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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BD7FC4167D for ; Fri, 3 Nov 2023 07:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344219AbjKCHfS (ORCPT ); Fri, 3 Nov 2023 03:35:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233216AbjKCHfP (ORCPT ); Fri, 3 Nov 2023 03:35:15 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36413CE for ; Fri, 3 Nov 2023 00:35:12 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0629CC433C8; Fri, 3 Nov 2023 07:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698996911; bh=OwYraiWkRGh713mFuBYUkMG66+APMALaM2UA9/OPM4Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MpQvfuD64rLyAZYkNj6bZGqNDUHXaBufxMYO7HTTllrrdXkiY5fSmEKrzDlJtpMJ+ TG1it3u/4YTXqyVqHba3o/03rXvIiokvctVSUrIGRSf96MBWBvF+msAvFoznrhdkGF E4mIRx3hAru3EaujSHaWm+Fk3A+OuzouKtd3TBn2vKqQ/9h0fZlBrYPNA4Kj97kpyT 0tLQlqje7tlZCTHJPaGtgN4CC0KJo6W8FncdU0Hwea2w1zGXrZdMOgpmx75YvKeUDD +EF+jkYlw+t0BI+zLRgcsjk+O3CmBcbwkWnShoG108n0UQ8VY+bgX71sYj61uTS737 lh1CSEprMLS2A== Date: Fri, 3 Nov 2023 09:34:59 +0200 From: Mike Rapoport To: =?utf-8?B?6buE5Lqu5Lqu?= Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, Liangliang Huang Subject: Re: [PATCH] mm/memblock.c: using judgment statement can reduce loop and enhance readability. Message-ID: <20231103073459.GN2824@kernel.org> References: <20231102023710.13023-1-huanglllzu@gmail.com> <20231102085418.GM2824@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 03, 2023 at 01:30:21PM +0800, 黄亮亮 wrote: > Hi,this patch can less loop once in this situation: > base more than rbase and end less than rend. >                 base           end >     rbase-----|--------------|-------rend >       |            |                 |           | > --------------------------------------------------------> The loop won't be executed anyway because there's similar condition in the beginning of the loop. Next time when you reply to the kernel mailing lists, please don't top post and make sure your reply is text-only. And there is no need to send 4 badly formatted replies. > Mike Rapoport 于2023年11月2日周四 16:54写道: > > Hi, > > > Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop > and enhance readability. > > I disagree. > > On Thu, Nov 02, 2023 at 10:37:10AM +0800, huanglllzu@gmail.com wrote: > > From: Liangliang Huang > > > > Signed-off-by: Liangliang Huang > > --- > >  mm/memblock.c | 6 +++++- > >  1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/mm/memblock.c b/mm/memblock.c > > index 913b2520a9a0..e48dea7144bb 100644 > > --- a/mm/memblock.c > > +++ b/mm/memblock.c > > @@ -655,7 +655,11 @@ static int __init_memblock memblock_add_range(struct > memblock_type *type, > >                       } > >               } > >               /* area below @rend is dealt with, forget about it */ > > -             base = min(rend, end); > > +             if (end < rend) { > > +                     base = end; > > +                     break; > > +             } else > > +                     base = rend; > > min() is perfectly clear and there no change in number of iterations of the > loop. > > >       } > >  > >       /* insert the remaining portion */ > > -- > > 2.25.1 > > > > -- > Sincerely yours, > Mike. > -- Sincerely yours, Mike.