Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3317064pxm; Mon, 28 Feb 2022 17:17:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJwu5ei+LN9RWc6BU+/yjMSzMPTPND40tm5ML+x92JfHPTBbJLBXwVJdt8pezpGK4HnuX9OS X-Received: by 2002:a17:902:e805:b0:14f:d33b:b769 with SMTP id u5-20020a170902e80500b0014fd33bb769mr23484545plg.24.1646097424026; Mon, 28 Feb 2022 17:17:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646097424; cv=none; d=google.com; s=arc-20160816; b=IkIs/yOQE14GIyVf56CCcR762vd47fxIdDN89JoFwWKpk+Q7knsgH4/g4TXSmlntaX AeERpRpLMSTdOHmdB+ffwZGDAVmPYykJ+qU+IYZTffp/YNBQr1Tgajedzfk4HgxKBJtI lfo9k0kwM7+3rk0cfj6NyYwhAA0653GCSdWFSLpvSA4NuQ/+W/CPs1ju/I8Woi1tXVgc W/aumwll8a7B3p95WaZWL2Pagj19cBFK5hzVxiE8JttpdXhVLn2re4Ng681DB6/Wd71W lZZPDGPLbi5a4snp/Ch9A2EdQTJaRCv3cOz7QuuN07sIEjGu9P0KbPBnLKqJ97wNUkqt JvNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=fF0KdNOD0SYiidqwuX5jPlXXH6R6EEEm7Sb7HXwHwrQ=; b=EX5iMTB5mIQ/QxMIKkflivjXNXNRGOypb+8ygqxetW9mIEh6xJ21AV1F7Z1C6Zrw/b WjF7VrT4KKdQIjXUwPPx/fBEKOJHHNROhhnwzgX2AU7DT3H99e96larsPpYbZjV9Akwj A5+OPyy3Jgt/hE4RY1ODvL8wsSDxevRWqYIRuscSKcYDXKeLcvqhoDDO4P9XXCm81dRp V20djSXa4WeR2877tBeS+NhW3EWZQKHrztfm0mNqCCRrChojb3fUYTbhzXDpsuRux0uB sA7neLnpgel5iQQWP/rD4dRjMkENBCUPwfgg1iwYHgZay3FsFbMkHIUwT3292erW/9f8 mDHw== 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 h10-20020a056a001a4a00b004f41a2a6d4dsi2585666pfv.228.2022.02.28.17.16.47; Mon, 28 Feb 2022 17:17:03 -0800 (PST) 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 S231919AbiCAAsS (ORCPT + 99 others); Mon, 28 Feb 2022 19:48:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231397AbiCAAsP (ORCPT ); Mon, 28 Feb 2022 19:48:15 -0500 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4EE5127CCE; Mon, 28 Feb 2022 16:47:33 -0800 (PST) Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 2210V56x017328; Mon, 28 Feb 2022 18:31:05 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 2210V0er017322; Mon, 28 Feb 2022 18:31:00 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Mon, 28 Feb 2022 18:30:59 -0600 From: Segher Boessenkool To: James Bottomley Cc: Mike Rapoport , Christian =?iso-8859-1?Q?K=F6nig?= , Linus Torvalds , linux-wireless , alsa-devel@alsa-project.org, KVM list , "Gustavo A. R. Silva" , linux-iio@vger.kernel.org, nouveau@lists.freedesktop.org, Rasmus Villemoes , dri-devel , Cristiano Giuffrida , "Bos, H.J." , linux1394-devel@lists.sourceforge.net, drbd-dev@lists.linbit.com, linux-arch , CIFS , linux-aspeed@lists.ozlabs.org, linux-scsi , linux-rdma , linux-staging@lists.linux.dev, amd-gfx list , Jason Gunthorpe , intel-wired-lan@lists.osuosl.org, kgdb-bugreport@lists.sourceforge.net, bcm-kernel-feedback-list@broadcom.com, Dan Carpenter , Linux Media Mailing List , Kees Cook , Arnd Bergman , Linux PM , intel-gfx , Brian Johannesmeyer , Nathan Chancellor , dma , Christophe JAILLET , Jakob Koschel , v9fs-developer@lists.sourceforge.net, linux-tegra , Thomas Gleixner , Andy Shevchenko , Linux ARM , linux-sgx@vger.kernel.org, linux-block , Netdev , linux-usb@vger.kernel.org, samba-technical@lists.samba.org, Linux Kernel Mailing List , Linux F2FS Dev Mailing List , tipc-discussion@lists.sourceforge.net, Linux Crypto Mailing List , linux-fsdevel , linux-mediatek@lists.infradead.org, Andrew Morton , linuxppc-dev Subject: Re: [PATCH 2/6] treewide: remove using list iterator after loop body as a ptr Message-ID: <20220301003059.GE614@gate.crashing.org> References: <20220228110822.491923-1-jakobkoschel@gmail.com> <20220228110822.491923-3-jakobkoschel@gmail.com> <2e4e95d6-f6c9-a188-e1cd-b1eae465562a@amd.com> <282f0f8d-f491-26fc-6ae0-604b367a5a1a@amd.com> <7D0C2A5D-500E-4F38-AD0C-A76E132A390E@kernel.org> <73fa82a20910c06784be2352a655acc59e9942ea.camel@HansenPartnership.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <73fa82a20910c06784be2352a655acc59e9942ea.camel@HansenPartnership.com> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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 On Mon, Feb 28, 2022 at 05:28:58PM -0500, James Bottomley wrote: > On Mon, 2022-02-28 at 23:59 +0200, Mike Rapoport wrote: > > > > On February 28, 2022 10:42:53 PM GMT+02:00, James Bottomley < > > James.Bottomley@HansenPartnership.com> wrote: > > > On Mon, 2022-02-28 at 21:07 +0100, Christian K?nig wrote: > [...] > > > > > I do wish we could actually poison the 'pos' value after the > > > > > loop somehow - but clearly the "might be uninitialized" I was > > > > > hoping for isn't the way to do it. > > > > > > > > > > Anybody have any ideas? > > > > > > > > I think we should look at the use cases why code is touching > > > > (pos) after the loop. > > > > > > > > Just from skimming over the patches to change this and experience > > > > with the drivers/subsystems I help to maintain I think the > > > > primary pattern looks something like this: > > > > > > > > list_for_each_entry(entry, head, member) { > > > > if (some_condition_checking(entry)) > > > > break; > > > > } > > > > do_something_with(entry); > > > > > > Actually, we usually have a check to see if the loop found > > > anything, but in that case it should something like > > > > > > if (list_entry_is_head(entry, head, member)) { > > > return with error; > > > } > > > do_somethin_with(entry); > > > > > > Suffice? The list_entry_is_head() macro is designed to cope with > > > the bogus entry on head problem. > > > > Won't suffice because the end goal of this work is to limit scope of > > entry only to loop. Hence the need for additional variable. > > Well, yes, but my objection is more to the size of churn than the > desire to do loop local. I'm not even sure loop local is possible, > because it's always annoyed me that for (int i = 0; ... in C++ defines > i in the outer scope not the loop scope, which is why I never use it. In C its scope is the rest of the declaration and the entire loop, not anything after it. This was the same in C++98 already, btw (but in pre-standard versions of C++ things were like you remember, yes, and it was painful). Segher