Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2061642pxb; Fri, 25 Mar 2022 10:24:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtQUIpit1dfATSQjRiNANU3e27xxKm3bGlppPoYqQNAXy2xIIzUJ/5nq0jilbgVmsiXUe+ X-Received: by 2002:a05:6870:a78f:b0:dd:d5a3:767f with SMTP id x15-20020a056870a78f00b000ddd5a3767fmr5390171oao.283.1648229058273; Fri, 25 Mar 2022 10:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648229058; cv=none; d=google.com; s=arc-20160816; b=jfXyUjTEusKXc04R+hjfkPsMepnSw+SK04o50HV6lUh4zWWP6ufW8C5VBeLO+pf68L Hg8EvxRY/JtlNzCh4DGbBB6QZg40YCvl52Ru1tzsUoOgVFEzzG/xq6XjUlL021QrA9UX xv7kIEPivtF7hPsFtsXdR4H5Xj2zGlxCU9SUKeTS4CFADS3IiK6mms6NnvM6ou9T8X5H hxQwojUjvk3SpdWY9D4PNGEWSl6Vr515khrWj6j91EshTb7hRRDs2fZOuzSv2VVxSrUG guQimydyDvX9R7KlqxAoZCfmU7CcsYSv1OWEb3RHGITE2aXunJPn9JALNrPcjCtMw7qk UOiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=w3f7X8ZQmsfdaAV82p2Xj2PMJbOkJGo8fN/N0A6gsV4=; b=q1tAvoiULhtZ46h5J52ZuiOr3BKUX5AqgUFDUw1/RSH/OHE5zZEvj7x7fRwnJ8SlxC CxHMeb2/YomNlNCNvVegO4oH2Igrdfsrz7doLbaxJDAu0G3SFFMlRGqqCJone/OVRQBf w00/AnjmuebMIAax2/EgkMtgN+bZwcDrwrPt4I83LOkg9b0pLQWR7UBnRTeaI7C/ZJ18 b5pKu5xfKy/wyzEuBCwrMVmYnJrfxANB6+sOjpVSivuTnlpMykxY7rBuk6junm8WygxP TTZRI9lkBBxbWWDGT/l/gROqZ2tusDkBMWS/o2OOK/M7cLxvutFNMPcOWhiDejFhZ1Aa FSXw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m11-20020a9d73cb000000b005cb2fc138d4si2330869otk.336.2022.03.25.10.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 10:24:18 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3397DF4628; Fri, 25 Mar 2022 10:19:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358181AbiCYDRE (ORCPT + 99 others); Thu, 24 Mar 2022 23:17:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234794AbiCYDRC (ORCPT ); Thu, 24 Mar 2022 23:17:02 -0400 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCDC2A1458 for ; Thu, 24 Mar 2022 20:15:28 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0V87tFIC_1648178124; Received: from 30.225.24.51(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0V87tFIC_1648178124) by smtp.aliyun-inc.com(127.0.0.1); Fri, 25 Mar 2022 11:15:25 +0800 Message-ID: <9de48770-7dfa-1dd8-5eab-5fc0ac0499d5@linux.alibaba.com> Date: Fri, 25 Mar 2022 11:15:24 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH] ocfs2: replace usage of found with dedicated list iterator variable Content-Language: en-US To: Jakob Koschel , Mark Fasheh , Andrew Morton Cc: Joel Becker , Geert Uytterhoeven , Miguel Ojeda , Masahiro Yamada , ocfs2-devel@oss.oracle.com, linux-kernel@vger.kernel.org, Mike Rapoport , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." References: <20220324071650.61168-1-jakobkoschel@gmail.com> From: Joseph Qi In-Reply-To: <20220324071650.61168-1-jakobkoschel@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no 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 3/24/22 3:16 PM, Jakob Koschel wrote: > To move the list iterator variable into the list_for_each_entry_*() > macro in the future it should be avoided to use the list iterator > variable after the loop body. > > To *never* use the list iterator variable after the loop it was > concluded to use a separate iterator variable instead of a > found boolean [1]. > > This removes the need to use a found variable and simply checking if > the variable was set, can determine if the break/goto was hit. > > Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ > Signed-off-by: Jakob Koschel Looks good. Reviewed-by: Joseph Qi > --- > fs/ocfs2/dlm/dlmunlock.c | 21 ++++++++++----------- > fs/ocfs2/quota_local.c | 10 +++++----- > 2 files changed, 15 insertions(+), 16 deletions(-) > > diff --git a/fs/ocfs2/dlm/dlmunlock.c b/fs/ocfs2/dlm/dlmunlock.c > index 61103b2d69fb..7318e4794ef9 100644 > --- a/fs/ocfs2/dlm/dlmunlock.c > +++ b/fs/ocfs2/dlm/dlmunlock.c > @@ -392,9 +392,9 @@ int dlm_unlock_lock_handler(struct o2net_msg *msg, u32 len, void *data, > struct dlm_ctxt *dlm = data; > struct dlm_unlock_lock *unlock = (struct dlm_unlock_lock *)msg->buf; > struct dlm_lock_resource *res = NULL; > - struct dlm_lock *lock = NULL; > + struct dlm_lock *lock = NULL, *iter; > enum dlm_status status = DLM_NORMAL; > - int found = 0, i; > + int i; > struct dlm_lockstatus *lksb = NULL; > int ignore; > u32 flags; > @@ -437,7 +437,6 @@ int dlm_unlock_lock_handler(struct o2net_msg *msg, u32 len, void *data, > } > > queue=&res->granted; > - found = 0; > spin_lock(&res->spinlock); > if (res->state & DLM_LOCK_RES_RECOVERING) { > spin_unlock(&res->spinlock); > @@ -461,21 +460,21 @@ int dlm_unlock_lock_handler(struct o2net_msg *msg, u32 len, void *data, > } > > for (i=0; i<3; i++) { > - list_for_each_entry(lock, queue, list) { > - if (lock->ml.cookie == unlock->cookie && > - lock->ml.node == unlock->node_idx) { > - dlm_lock_get(lock); > - found = 1; > + list_for_each_entry(iter, queue, list) { > + if (iter->ml.cookie == unlock->cookie && > + iter->ml.node == unlock->node_idx) { > + dlm_lock_get(iter); > + lock = iter; > break; > } > } > - if (found) > + if (lock) > break; > /* scan granted -> converting -> blocked queues */ > queue++; > } > spin_unlock(&res->spinlock); > - if (!found) { > + if (!lock) { > status = DLM_IVLOCKID; > goto not_found; > } > @@ -505,7 +504,7 @@ int dlm_unlock_lock_handler(struct o2net_msg *msg, u32 len, void *data, > dlm_kick_thread(dlm, res); > > not_found: > - if (!found) > + if (!lock) > mlog(ML_ERROR, "failed to find lock to unlock! " > "cookie=%u:%llu\n", > dlm_get_lock_cookie_node(be64_to_cpu(unlock->cookie)), > diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c > index 0e4b16d4c037..38cc75bd3127 100644 > --- a/fs/ocfs2/quota_local.c > +++ b/fs/ocfs2/quota_local.c > @@ -923,19 +923,19 @@ static struct ocfs2_quota_chunk *ocfs2_find_free_entry(struct super_block *sb, > { > struct mem_dqinfo *info = sb_dqinfo(sb, type); > struct ocfs2_mem_dqinfo *oinfo = info->dqi_priv; > - struct ocfs2_quota_chunk *chunk; > + struct ocfs2_quota_chunk *chunk = NULL, *iter; > struct ocfs2_local_disk_chunk *dchunk; > int found = 0, len; > > - list_for_each_entry(chunk, &oinfo->dqi_chunk, qc_chunk) { > + list_for_each_entry(iter, &oinfo->dqi_chunk, qc_chunk) { > dchunk = (struct ocfs2_local_disk_chunk *) > - chunk->qc_headerbh->b_data; > + iter->qc_headerbh->b_data; > if (le32_to_cpu(dchunk->dqc_free) > 0) { > - found = 1; > + chunk = iter; > break; > } > } > - if (!found) > + if (!chunk) > return NULL; > > if (chunk->qc_num < oinfo->dqi_chunks - 1) { > > base-commit: f443e374ae131c168a065ea1748feac6b2e76613