Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp486206pxb; Thu, 7 Apr 2022 10:30:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykstGDiMtFim60F+ydSE5WJVWRb/HcRvNgGQJDN9IyJzF1ybW3gEApwNxoKZqeB1iXw/Rj X-Received: by 2002:a05:6402:35c7:b0:41d:1a10:4760 with SMTP id z7-20020a05640235c700b0041d1a104760mr236449edc.28.1649352640849; Thu, 07 Apr 2022 10:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649352640; cv=none; d=google.com; s=arc-20160816; b=1D8KrGZy5KjW1uq4Gp76yHYrIRZLVH14IeXCkSGg43KkwEXxxcap2HCJIUePm5cnPZ sFmof3g+LhQHLc4zKV/JHT/LJvs3qtqGuU3qEtundFLDfqH8yQIe6CXwcH2G5MCNW3/7 oHCSmD1GC3Yl9S7XgICkMaHmBKl0KdyMzduyzVgRkf5d29yhCUnFrIofXtq0RlIMc0GS AIEAznfebHHvqNQlZzuc2ztSuTAPiilY1xwzodQunS91H/P1aQ+QnzJHBz+jo2farWFf 0u01roKE36ae0rrMKNx+D2vM67vo4dKnqZfGgaMhCAkaCdU2YKDdQil5xhJOLeo4lcKX alKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fIZenjsGtzoZOCvRY/8dIr7NFNGibTLVVWT+oNYuIJo=; b=e9TlILnwMC7Iy3kBnFcDhWNuiXHNlnoCjxy7xbTgTciX+3Ga2dE339DHE17N2C1Mkb RMsel0UvOpqm6IKiYCeZr88/F1hlYlTAQvrP2LIGULxBCT6HVsFCSV9mtO81dFN2xpeO k5WsoRlkC+DuMN73Qz0lxZmVhi1I3tkVGpL9sCTA/ojgmGEtF2HtywPgN6b4DHW91mZE hx0yOAVIx68B3PTMJHdFCLStz+vyXWtPTz6zX0xRhpZlk7YldXYpPSxRcd4GYPVpZ+p2 HjK7OcfjGyyj7SKIpJ98eo9ijio2opQ4O7/HB5zMMOT4Sy4/wa+osHy1TFHWlV07ZLRp wVzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="IEzc/255"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oy1-20020a170907104100b006e7fd3f1dd2si8895552ejb.1001.2022.04.07.10.30.12; Thu, 07 Apr 2022 10:30:40 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b="IEzc/255"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244414AbiDGKeE (ORCPT + 99 others); Thu, 7 Apr 2022 06:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244318AbiDGKdh (ORCPT ); Thu, 7 Apr 2022 06:33:37 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23944BB0AE; Thu, 7 Apr 2022 03:31:15 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id bg10so9913517ejb.4; Thu, 07 Apr 2022 03:31:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fIZenjsGtzoZOCvRY/8dIr7NFNGibTLVVWT+oNYuIJo=; b=IEzc/255dt97HZarz+h4rN2mCO7j6l7/vbTvJxhhhDXx3gsbrsyYxJTx7T6m3q/z7P R/q2STBfwPvXpIrtlJWG+TQeP1X/IEnFbDf3tYOjq0H2eXbXTiswDLo/yLngVcJQ6evF EgLZlnOAiycgSvMmsY6gaYqxmGSYvNHf2XlHkZy85K9XdR31ldsPJQEQ56DE+1kzLQuI fKSk1UFKUjSgPyL+Kz+3n+zycAChi+t4w7pYoQdBKpISy8tzFyJG7gdTjVmLzzAVhfCN oqiwz+QPjJookkQzLOMOZZZmOrpbaZ4nW8oXH0193pisDN0c8HquvkpOGVfLb7PAONNx wSjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fIZenjsGtzoZOCvRY/8dIr7NFNGibTLVVWT+oNYuIJo=; b=2JGYxPL9egtyt/rpybytNdrov8ThbG8n1XZOkitxl/KOazqsd7uwffaG4G+4snJ6c3 eD+MUuzaCp5c4kSpYpkoGSYqA7yUj9nptrHFsJxxG8LQr9CRDGpmz1+bTNFaqr3XG2Bt 2YlvY0Fp0OpQ040kDd6gFa2WfPOAG3+mzZT548/rXf2J42t3CTopsXTCmeOMwdvqaGcF HBTsqXS8QVwe6bAlJxGdO5iig8ftZ0oqEN8oGixgT6NOEXD68Jp7Et6YXpCyXyvT/Ato aSh4ltKomRPx9WunAHKQPIZFVzS/YD8d+HCRseTmsKj4ukYPpzzzWxXZTRTUMlT02608 1xkA== X-Gm-Message-State: AOAM530VVGxbGDniPoVvsYBGacmp8KzNCdYVLbj6soCbAPpEBUN1nfIk JQPwdoO2iiPOFd4apTUbKiA= X-Received: by 2002:a17:907:7b9d:b0:6df:fb8f:fe82 with SMTP id ne29-20020a1709077b9d00b006dffb8ffe82mr12586465ejc.652.1649327473634; Thu, 07 Apr 2022 03:31:13 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id c5-20020a170906d18500b006ce371f09d4sm7413573ejz.57.2022.04.07.03.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 03:31:13 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Cc: Jakub Kicinski , Paolo Abeni , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , Lars Povlsen , Steen Hegelund , UNGLinuxDriver@microchip.com, Ariel Elior , Manish Chopra , Edward Cree , Martin Habets , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Jiri Pirko , Casper Andersson , Bjarni Jonasson , Jakob Koschel , Colin Ian King , Michael Walle , Christophe JAILLET , Arnd Bergmann , Eric Dumazet , Di Zhu , Xu Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH net-next 10/15] net: qede: Remove check of list iterator against head past the loop body Date: Thu, 7 Apr 2022 12:28:55 +0200 Message-Id: <20220407102900.3086255-11-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407102900.3086255-1-jakobkoschel@gmail.com> References: <20220407102900.3086255-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 When list_for_each_entry() completes the iteration over the whole list without breaking the loop, the iterator value will be a bogus pointer computed based on the head element. While it is safe to use the pointer to determine if it was computed based on the head element, either with list_entry_is_head() or &pos->member == head, using the iterator variable after the loop should be avoided. In preparation to limit the scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1]. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/net/ethernet/qlogic/qede/qede_filter.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qede/qede_filter.c b/drivers/net/ethernet/qlogic/qede/qede_filter.c index 3010833ddde3..3d167e37e654 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_filter.c +++ b/drivers/net/ethernet/qlogic/qede/qede_filter.c @@ -829,18 +829,21 @@ int qede_configure_vlan_filters(struct qede_dev *edev) int qede_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid) { struct qede_dev *edev = netdev_priv(dev); - struct qede_vlan *vlan; + struct qede_vlan *vlan = NULL; + struct qede_vlan *iter; int rc = 0; DP_VERBOSE(edev, NETIF_MSG_IFDOWN, "Removing vlan 0x%04x\n", vid); /* Find whether entry exists */ __qede_lock(edev); - list_for_each_entry(vlan, &edev->vlan_list, list) - if (vlan->vid == vid) + list_for_each_entry(iter, &edev->vlan_list, list) + if (iter->vid == vid) { + vlan = iter; break; + } - if (list_entry_is_head(vlan, &edev->vlan_list, list)) { + if (!vlan) { DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), "Vlan isn't configured\n"); goto out; -- 2.25.1