Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2163690pxb; Fri, 25 Mar 2022 12:13:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+l+jMWKrLnNCxUSwNqeGBryat41l84JVS1aZqXZ8bRpjaeBSpfksDQNMsVRfIqdDKyMgb X-Received: by 2002:a63:5049:0:b0:385:fb20:c34d with SMTP id q9-20020a635049000000b00385fb20c34dmr792889pgl.537.1648235604760; Fri, 25 Mar 2022 12:13:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648235604; cv=none; d=google.com; s=arc-20160816; b=aVAckrJfD/Xxo9V3nNoF/vOKghOHw24hw9uYKlh1pwG5HflIz8k6NhpQTNFkb9e0Lk 5qCt2Pvju93wX1f/jJ4Qc0kR4Ad7c/WO7HZq/mesLX/alv/U6A1R1jQ+IcBr7uZ0Z9M9 y/uURC0Y+if3HBByZo87Qj9N8c9f8LLa4MhsHQlLzSV7fROX+MCQeU6FYUNY5b538LZ8 kf3JTGWsb47Nqj/Fb1+ljsz58HNpAaa69BXWzvWa7dOjdHGfXHeM2oWT5JZ8amb6ox0V YREQ+4mUSwIcG2f3E9Jm6lTRMaobCndrBqPM0RO+FheNMITIqfpJBTqvkqlZNHVjdt0/ 5AJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=VjoE8BZJVN1iwPK7whmEd/UzvSJx78EIFvypyOblvMU=; b=DimMX/DvhrC+2W5ybvyizpMXijTysA1/TyDm3auUUFsMcsLI3UPPZucjnSyJsyZ2G1 h9CLGSPJjtrADVJoJiM4uoX50INrps6OiTNlHHY0hOwlu3MzVP5CLxGN1vkwTuIb0kD2 zy5yyNFyJlsu2fboZkfK//RSthg84Q9JrY0giaBeuh1JuuwLiBMK/kFHNRq6CEqgTC5Z XN6y6GdTaiNrNdEqS0JLYK+2Qwpne2/tQpaNGxMaXViCYY1ZmqglKmh9NlHN66ss2sDf 0zsEmZw5eFv93khxIBIkFQylN+IRtEmcSt5VxWafrPp5sMb5TkwuLwvzW26q19dCkter Rbng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iD1t79TR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j4-20020a170902c3c400b00153b2d1660dsi2955521plj.533.2022.03.25.12.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 12:13:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iD1t79TR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 353CF213525; Fri, 25 Mar 2022 11:17:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242473AbiCXIZk (ORCPT + 99 others); Thu, 24 Mar 2022 04:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232726AbiCXIZi (ORCPT ); Thu, 24 Mar 2022 04:25:38 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E68341AF2B; Thu, 24 Mar 2022 01:24:06 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id b24so4679850edu.10; Thu, 24 Mar 2022 01:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VjoE8BZJVN1iwPK7whmEd/UzvSJx78EIFvypyOblvMU=; b=iD1t79TR8oKBahp+V8Sy2/3GsPNaxDcNogaMNOUWGUjPVuM4ZB7mBrxURI8PjSfQ5s 1k++OsLCCjbhgMUff4fCxXY0Ow82HGJpwowEukJAWstzEG8H1R3lye60SGC4NDUcrWFF UmmIfvk06isHhveJsA6fIEIgfORjJtV4R2jovSTf7SU176Sm9agB3G7zrpVAgPcRLF3G WIG0E6n8ASnfLXXTPoa9wZPVXT3Jii/L2UNMoMYRMNhZeY3BRgvNHbQN/bpIdTNgV3uX 1/okEsHox2/jVsuDSOBQeQduF5wZIJdoMFmC2ymCZwA1+Ep/SSD04i4d93FBELXZF5IC T2vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VjoE8BZJVN1iwPK7whmEd/UzvSJx78EIFvypyOblvMU=; b=KOc6UpOGSVjTK8LnB0XbjXa4MDb2iORK8e/KjHhZWeweGUZf51LazabunHPqb9d3M8 4MTBgAKBrl2oNgmguuk5v8xV4MYVSu22Ycfk0EWWasieCC8pnD5WcrIK9zwdJCHeTp03 9sb7+4ZynkF6WaClfzwSOnAEnCcvLftF0+KyT21v1hgcKCF+SvYECb7palGehAMYc+Re 2jwvWLQRzN8iPPIIhuTGU0GFQX+3c4/9cbxUPoRduTpghB7rPVjBIu0ZlO5zXORi4Eze 1NYHG9+hdwrp0+eD5AB6q48F0lK/FzXVD84uOdOOCkURRiaMItufU1BsOUpGGOTtkWno amZg== X-Gm-Message-State: AOAM531hffsQz6NZKIC50Bsuh8aikHmlDxTegW58uS6CcP7aPqYGZ2Mn CdAV5902uMaT3VdoPx/mV28= X-Received: by 2002:a05:6402:84f:b0:419:638f:2bd5 with SMTP id b15-20020a056402084f00b00419638f2bd5mr5154017edz.283.1648110245364; Thu, 24 Mar 2022 01:24:05 -0700 (PDT) Received: from smtpclient.apple (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.gmail.com with ESMTPSA id l9-20020a1709060cc900b006ce04bb8668sm820866ejh.184.2022.03.24.01.24.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Mar 2022 01:24:04 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Subject: Re: [PATCH] IB/SA: replace usage of found with dedicated list iterator variable From: Jakob Koschel In-Reply-To: Date: Thu, 24 Mar 2022 09:24:01 +0100 Cc: Jason Gunthorpe , Leon Romanovsky , =?utf-8?Q?H=C3=A5kon_Bugge?= , Mark Bloch , Christophe JAILLET , linux-rdma , Linux Kernel Mailing List , Mike Rapoport , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." Content-Transfer-Encoding: quoted-printable Message-Id: References: <20220324071124.59849-1-jakobkoschel@gmail.com> To: Mark Zhang X-Mailer: Apple Mail (2.3696.80.82.1.1) X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,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 24. Mar 2022, at 08:53, Mark Zhang wrote: >=20 > On 3/24/2022 3:11 PM, Jakob Koschel wrote: >> External email: Use caution opening links or attachments >> 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-=3DwgRr_D8CB-D9Kg-c=3DEHreAsk5SqXPwr9Y7k9= sA6cWXJ6w@mail.gmail.com/ >> Signed-off-by: Jakob Koschel >> --- >> drivers/infiniband/core/sa_query.c | 15 +++++++-------- >> 1 file changed, 7 insertions(+), 8 deletions(-) >> diff --git a/drivers/infiniband/core/sa_query.c = b/drivers/infiniband/core/sa_query.c >> index 74ecd7456a11..74cd84045e5b 100644 >> --- a/drivers/infiniband/core/sa_query.c >> +++ b/drivers/infiniband/core/sa_query.c >> @@ -1035,10 +1035,9 @@ int ib_nl_handle_resolve_resp(struct sk_buff = *skb, >> struct netlink_ext_ack *extack) >> { >> unsigned long flags; >> - struct ib_sa_query *query; >> + struct ib_sa_query *query =3D NULL, *iter; >> struct ib_mad_send_buf *send_buf; >> struct ib_mad_send_wc mad_send_wc; >> - int found =3D 0; >> int ret; >> if ((nlh->nlmsg_flags & NLM_F_REQUEST) || >> @@ -1046,20 +1045,20 @@ int ib_nl_handle_resolve_resp(struct sk_buff = *skb, >> return -EPERM; >> spin_lock_irqsave(&ib_nl_request_lock, flags); >> - list_for_each_entry(query, &ib_nl_request_list, list) { >> + list_for_each_entry(iter, &ib_nl_request_list, list) { >> /* >> * If the query is cancelled, let the timeout routine >> * take care of it. >> */ >> - if (nlh->nlmsg_seq =3D=3D query->seq) { >> - found =3D !ib_sa_query_cancelled(query); >> - if (found) >> - list_del(&query->list); >> + if (nlh->nlmsg_seq =3D=3D iter->seq) { >> + if (!ib_sa_query_cancelled(iter)) >> + list_del(&iter->list); >> + query =3D iter; >> break; >=20 > Should it be: >=20 > if (nlh->nlmsg_seq =3D=3D iter->seq) { > if (!ib_sa_query_cancelled(iter)) { > list_del(&iter->list); > query =3D iter; > } > break; yes you are right. Sorry about that, I'll send a fixed version with v2. >=20 >> } >> } >> - if (!found) { >> + if (!query) { >> spin_unlock_irqrestore(&ib_nl_request_lock, flags); >> goto resp_out; >> } >> base-commit: f443e374ae131c168a065ea1748feac6b2e76613 >> -- >> 2.25.1