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 9A6D3C761A6 for ; Tue, 21 Mar 2023 20:49:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229798AbjCUUto (ORCPT ); Tue, 21 Mar 2023 16:49:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbjCUUtl (ORCPT ); Tue, 21 Mar 2023 16:49:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08EA2BDD6; Tue, 21 Mar 2023 13:49:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9A48A61E22; Tue, 21 Mar 2023 20:49:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E938DC433D2; Tue, 21 Mar 2023 20:49:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679431780; bh=2Wwfj2ffEfWI7ejpq1BZ8zSr3+KnhBGdy+rl/B7TI1Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EPgqBAS7OR+RSqF8lbVStrb3JyJDsZt/Mzt6cOlEW+lT8jRf0pka0FLWTZASzZIZ8 HRtDURVlmBpxTegB9ZoocN1gcjQSp21+CzqT3O1Ri9QLwFKZs4FUHkWHBumykMpp/Q UzNepFpaQaz2voK9f27YCAqKxmVBlms0GUqlHdjbX4/qe/QMNwbVjPU2ZEbhXIZN7x BW0C0eVO/bsOnospfulgKT1palYALQ6o2BMXRK8V1dXoetbzJnBB3hpNEvOpjlSe/Z 2j9FSoPw75EBRj5UC6BYzT4/icvkhEnB+agr+b65iqxUIqRIlY6LMJkRMUiUOl5o7t cyFq/FUkwHR5w== Date: Tue, 21 Mar 2023 13:49:38 -0700 From: Saeed Mahameed To: Jakob Koschel Cc: Boris Pismenny , Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Pietro Borrello , Cristiano Giuffrida , "Bos, H.J." Subject: Re: [PATCH net-next] net/mlx5e: avoid usage of list iterator after loop Message-ID: References: <20230301-net-mlx5e-avoid-iter-after-loop-v1-1-064c0e9b1505@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20230301-net-mlx5e-avoid-iter-after-loop-v1-1-064c0e9b1505@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13 Mar 16:26, Jakob Koschel wrote: >If potentially no valid element is found, 'priv_rx' would contain an >invalid pointer past the iterator loop. To ensure 'priv_rx' is always >valid, we only set it if the correct element was found. That allows >adding a WARN_ON() in case the code works incorrectly, exposing >currently undetectable potential bugs. > >Additionally, Linus proposed to avoid any use of the list iterator >variable after the loop, in the attempt to move the list iterator >variable declaration into the macro to avoid any potential misuse after >the loop [1]. > >Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] >Signed-off-by: Jakob Koschel Applied to net-next-mlx5. Thanks.