Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp4986514pxb; Mon, 28 Mar 2022 06:29:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaHFiUdNS0kZIdCfa1IsR19Jkp66m7LKFHa6DwkLzqt2VY3i63CaG/JtDOp8AOJowajoKz X-Received: by 2002:a17:903:2343:b0:154:4a3e:6b24 with SMTP id c3-20020a170903234300b001544a3e6b24mr26328777plh.129.1648474179414; Mon, 28 Mar 2022 06:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648474179; cv=none; d=google.com; s=arc-20160816; b=gfN6U2ZuUe2RH3bU3jtmN9hTB7GX5mi94mHZQX48A9bcrsJvOFLhW43iJd4ykBl8Y8 jIzxsLyDuZWYY4TILOgyccVHx8TjLkRRmNdcKcd3m84Qa6ziKTVQqDBbwK0NaK7FxhHr mySqXOsoYkU2zs3W293yvbuygylTX1/Jsa8xRiKml08/PlBLoK0FquGiGW2ybPV5xZku eWrwxJSChh4iuCTWlE0x/xEMZGqJOmFKOyTD3JE7l2FHqqvSUPyFbymsOlWnA698jSSN tZfOfuVnew/4NjNcFWLJFvxKIBrZ3xv4goViQry3auxbnukqheXsLhq78Hgmsd+8rMK2 X8Sw== 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 :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id; bh=4BQ57pr5posvuGt0pXZWjHeYu52NS8zeiiTtfiB0iF0=; b=jEG0MoF0QLC0xMbTvNS32d0ezyiPJ6K/2IWw1DqrY1USqHXfSyItlFBVZ/0+GMQBM2 DkNo4XCyZPBPaEGTHV1ViAoBvjyKQ31h6/UY45kFLjKCgQD8qLdXUI1aru4lG1nv2KQI gcbZBMJTJNx3Bgy4GXzyH1Uo5FTMG81gjJeJ3ZO0A7NqD0gH4VPi9i7K3SpqeGsTQL8U nqGbtobnYJzi6PTzGIFM4+9fjVuFba+x6wsTLN8Nt+DW5ryNa4v4OORCtgFb0HE7VLRv YR/4ayDFK6224PWFFYa8oVimY0wEEgABJ2YZ9G3cZciqHVQ/NxzThReaUt3OOEFbWSfR OatQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay9-20020a1709028b8900b00153b2d164e8si11631339plb.240.2022.03.28.06.29.25; Mon, 28 Mar 2022 06:29:39 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237426AbiC1CEb (ORCPT + 99 others); Sun, 27 Mar 2022 22:04:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbiC1CE3 (ORCPT ); Sun, 27 Mar 2022 22:04:29 -0400 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F271D2625; Sun, 27 Mar 2022 19:02:49 -0700 (PDT) Received: by mail-pf1-f180.google.com with SMTP id h19so10280547pfv.1; Sun, 27 Mar 2022 19:02:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:cc:references:content-language:in-reply-to :content-transfer-encoding; bh=4BQ57pr5posvuGt0pXZWjHeYu52NS8zeiiTtfiB0iF0=; b=L/jsr11LlvVrBEoX7UklyzxTzurXSSXVZyZEkzm+GvVvxzZvMmncUThENEj/LIFWMn T9gkBpOw724ajmU1Lur9b4UupGQReOfHuVMb9VW9LF2k8mlRo7fVyjM7Dr9hjEvRAtkT pvtSErmj52e4BgmluzUBR8aYY9uJKOQHAVeMx8YRRyJ97N/oTq2Il1rew0VAIT0t9rre Cz8g/u4ZFla8SVCifHLXyubrtxRFOJcHcDuEgdDdDLfLPdIMv7SQeMKwfL4hADDcy4A+ entNL1RcQ7IfLl08ynAYx1kCH+1JS9XQr+e5jsbyOuFrOhbuPhGPvRy48zmKc0qxwTE/ ik1A== X-Gm-Message-State: AOAM533lO9tJKjeNTLTgd8UOkpUKZb+47cI+oyWsMRMYewkBQJEhKAqE m3tHi6iUgyI545PGnn2Abnk= X-Received: by 2002:a63:d454:0:b0:386:86:6aaa with SMTP id i20-20020a63d454000000b0038600866aaamr8571557pgj.60.1648432969176; Sun, 27 Mar 2022 19:02:49 -0700 (PDT) Received: from ?IPV6:2601:647:4000:d7:feaa:14ff:fe9d:6dbd? ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id mw10-20020a17090b4d0a00b001c7cc82daabsm11233309pjb.1.2022.03.27.19.02.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 27 Mar 2022 19:02:48 -0700 (PDT) Message-ID: <49f08642-8878-8574-ce86-d1baf41f1189@acm.org> Date: Sun, 27 Mar 2022 19:02:46 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 From: Bart Van Assche Subject: Re: [PATCH] block: use dedicated list iterator variable To: Jakob Koschel , Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Mike Rapoport , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." References: <20220327214704.2188742-1-jakobkoschel@gmail.com> Content-Language: en-US In-Reply-To: <20220327214704.2188742-1-jakobkoschel@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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/27/22 14:47, 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]. > > Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ > Signed-off-by: Jakob Koschel > --- > block/blk-mq.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/block/blk-mq.c b/block/blk-mq.c > index 8e659dc5fcf3..455fdd488f3c 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -4466,12 +4466,14 @@ static bool blk_mq_elv_switch_none(struct list_head *head, > static void blk_mq_elv_switch_back(struct list_head *head, > struct request_queue *q) > { > - struct blk_mq_qe_pair *qe; > + struct blk_mq_qe_pair *qe = NULL; > + struct blk_mq_qe_pair *iter; > struct elevator_type *t = NULL; > > - list_for_each_entry(qe, head, node) > - if (qe->q == q) { > - t = qe->type; > + list_for_each_entry(iter, head, node) > + if (iter->q == q) { > + t = iter->type; > + qe = iter; > break; > } The current code looks much more readable to me than with the above patch applied. How about replacing the above patch with the patch below? Thanks, Bart. diff --git a/block/blk-mq.c b/block/blk-mq.c index 9c784262fd6b..c9435be54667 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -4451,21 +4451,28 @@ static bool blk_mq_elv_switch_none(struct list_head *head, return true; } -static void blk_mq_elv_switch_back(struct list_head *head, - struct request_queue *q) +static struct blk_mq_qe_pair *blk_lookup_qe_pair(struct list_head *head, + struct request_queue *q) { struct blk_mq_qe_pair *qe; - struct elevator_type *t = NULL; list_for_each_entry(qe, head, node) - if (qe->q == q) { - t = qe->type; - break; - } + if (qe->q == q) + return qe; + + return NULL; +} + +static void blk_mq_elv_switch_back(struct list_head *head, + struct request_queue *q) +{ + struct blk_mq_qe_pair *qe = blk_lookup_qe_pair(head, q); + struct elevator_type *t; - if (!t) + if (!qe) return; + t = qe->type; list_del(&qe->node); kfree(qe);