Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3197022pxm; Mon, 28 Feb 2022 14:16:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIc1c9ZF48h4Ms/UEmxRRsOYdm+AIcVudrFoxgZiUpCnLMdmlQ2OWSTiwmNmvZmXIUWJn5 X-Received: by 2002:a17:903:1c1:b0:14f:dad3:e7dd with SMTP id e1-20020a17090301c100b0014fdad3e7ddmr22177695plh.130.1646086568141; Mon, 28 Feb 2022 14:16:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646086568; cv=none; d=google.com; s=arc-20160816; b=zqrUQRqFrLfgv0iPc7IAd3b5te2Z6vrmJ2TDBUDwvqu5mT87NEcuRbWKyG405yP1/L gt25eeZ+ZFA+Le/2ualFTVaITVT7SH6xIQ7gC0RD0VZ1vmOlKeviZANTIbAk5oXfS3hy knZF651e6a2KwxbJDwuUrSTpo27+gg0JNUKnguFHAmTIgQOJA/v7967L1yRMeopw9viQ IAITZPO0UaR4iuDDd7nYkEl68y9GBjweTivz/1PucY91hFCYPH0Mh8eWkd/7NzXbDWUu BFLoUuUGCMqBdMoFGI6bqFw8TDkJQW5yhRuykv6IxyEhnU+SDI6ZYAa8eyhjEVt6KlrZ dVsg== 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=rjAgW0TZYa01aB+RWuD5jL6/P65QVmPGzGS1fypwqkM=; b=EvYw/zvlC/TWAQ7oVwFxkmxJdztsl6SdeLOsUilRXhUiyzAKaiKxYly4XFkD4pLLKa riLjHOSHxqXClMnlQ5JhQMCVQiOP+MrgLj33JRST1avG5c/TfYanNzyGzdzVY6epFwrn Mw7YmGa9Wgleh9zQtkyrVfLBpqf9dBxDE8SNI1eROP0BoqpWg/9R7wBY+oL4YkCSSTuq XkstOzaWcT8RnjH/fTT5899n2l1emDt3crzvfxKyLAGtNDwchBk0iqd5XreM4R7da7dd WcZBjpJ+8bsA8gxki8fW378bhWvRsrcSi+OghrHn0/gsJkIrQIFmjGHTuqxgUz8lrXLa 30dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SsE2iptd; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 g7-20020a63dd47000000b0036c40839091si10711771pgj.610.2022.02.28.14.15.56; Mon, 28 Feb 2022 14:16:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-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=SsE2iptd; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 S231305AbiB1WGS (ORCPT + 72 others); Mon, 28 Feb 2022 17:06:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbiB1WGL (ORCPT ); Mon, 28 Feb 2022 17:06:11 -0500 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 50F44C4B55; Mon, 28 Feb 2022 14:05:31 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id qx21so27621667ejb.13; Mon, 28 Feb 2022 14:05:31 -0800 (PST) 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=rjAgW0TZYa01aB+RWuD5jL6/P65QVmPGzGS1fypwqkM=; b=SsE2iptdX/xTNU84zbtZf+FZ8hKTkJX9H9ZM578+fdgJrDU7+0yGKs3Y1+Ec8zM22z 4L/SCSccM9eH+aBbsU9p5ll5VTrDlXvOt1QFHQZ0QoX++s1RFseEQQ8VJGBWAvwFCFIq jeFzH1SGTYgHS7irPmR7cmG6wYjaX3+E6LxhLklpw86+z7E18Zuelcsa1QvD5X9AuKj5 NYlhLrqxXUYjh+QgOiXwDeMKoQqdSp4BR7hulFUTvSZMfnkNflEuO+lrt30n2JUf7UIn 5TdA8KwzIEgmQjPXnxPtLxIzLgpwPLiA+LehnjNWRY5HBdt4E59Tm/VNBLrMAmAi/DS2 EEuw== 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=rjAgW0TZYa01aB+RWuD5jL6/P65QVmPGzGS1fypwqkM=; b=W/12CwqZ3uzF9/7JkXERS4Y+CdZGwbbbQ0nWvsM7TR1zmYzDQ26zI1lWM+qtzN/t1i XtDLx3/As3xn++hIWRYWHc+ZWHdBfXN63sO2xLAW9UlAiLBZuqIm0rP5a1jqCDrwOkjZ dQccJ/7ZLiYu7KLCH5U25inYMSnunbQzlWsk8OkOlrGDB05bYe6bdNrvLbywT+HUzs3w FrkFGkFM85IXPhqoa3rByMdo/mvXvVUwb1rQiGL9ZO3OvQl8OKMRECNJSvOJLtOSUwhD 0y/onbfE+nza7Kt2o5oUKpgj64lq1VLWbXAiVXpZz2QzDJWpeNMdnAyN+dmjq73P9SyC Gp9w== X-Gm-Message-State: AOAM5317JvYWqn+H3SXcsseeu1Ak49y9S5UGir6uxGGuNvVTz3RflWEV mvwm/Fvfl9DIpNtBFqCK+YE= X-Received: by 2002:a17:906:370f:b0:6ce:6e7:7344 with SMTP id d15-20020a170906370f00b006ce06e77344mr16083589ejc.654.1646085929715; Mon, 28 Feb 2022 14:05:29 -0800 (PST) Received: from smtpclient.apple ([2a02:8109:9d80:3f6c:957a:1d13:c949:d1f3]) by smtp.gmail.com with ESMTPSA id v2-20020a17090606c200b006a728f4a9bcsm4769566ejb.148.2022.02.28.14.05.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Feb 2022 14:05:29 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.60.0.1.1\)) Subject: Re: [PATCH 2/6] treewide: remove using list iterator after loop body as a ptr From: Jakob Koschel In-Reply-To: <0b65541a-3da7-dc35-690a-0ada75b0adae@amd.com> Date: Mon, 28 Feb 2022 23:05:26 +0100 Cc: James Bottomley , Linus Torvalds , alsa-devel@alsa-project.org, linux-aspeed@lists.ozlabs.org, "Gustavo A. R. Silva" , linux-iio@vger.kernel.org, nouveau@lists.freedesktop.org, Rasmus Villemoes , dri-devel , Cristiano Giuffrida , amd-gfx list , samba-technical@lists.samba.org, linux1394-devel@lists.sourceforge.net, drbd-dev@lists.linbit.com, linux-arch , CIFS , KVM list , linux-scsi , linux-rdma , linux-staging@lists.linux.dev, "Bos, H.J." , 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 , linux-fsdevel , Christophe JAILLET , 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, linux-wireless , Linux Kernel Mailing List , Linux F2FS Dev Mailing List , tipc-discussion@lists.sourceforge.net, Linux Crypto Mailing List , dma , linux-mediatek@lists.infradead.org, Andrew Morton , linuxppc-dev , Mike Rapoport Content-Transfer-Encoding: quoted-printable Message-Id: <192A6D7F-E803-47AE-9C7A-267B4E87C856@gmail.com> 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> <0b65541a-3da7-dc35-690a-0ada75b0adae@amd.com> To: =?utf-8?Q?Christian_K=C3=B6nig?= X-Mailer: Apple Mail (2.3693.60.0.1.1) 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-wireless@vger.kernel.org > On 28. Feb 2022, at 21:56, Christian K=C3=B6nig = wrote: >=20 >=20 >=20 > Am 28.02.22 um 21:42 schrieb James Bottomley: >> On Mon, 2022-02-28 at 21:07 +0100, Christian K=C3=B6nig wrote: >>> Am 28.02.22 um 20:56 schrieb Linus Torvalds: >>>> On Mon, Feb 28, 2022 at 4:19 AM Christian K=C3=B6nig >>>> wrote: >>>> [SNIP] >>>> Anybody have any ideas? >>> I think we should look at the use cases why code is touching (pos) >>> after the loop. >>>=20 >>> 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: >>>=20 >>> list_for_each_entry(entry, head, member) { >>> if (some_condition_checking(entry)) >>> break; >>> } >>> do_something_with(entry); There are other cases where the list iterator variable is used after the = loop Some examples: - list_for_each_entry_continue() and list_for_each_entry_from(). - (although very rare) the head is actually of the correct struct type. (ppc440spe_get_group_entry(): = drivers/dma/ppc4xx/adma.c:1436) - to use pos->list for example for list_add_tail(): (add_static_vm_early(): arch/arm/mm/ioremap.c:107) If the scope of the list iterator is limited those still need fixing in = a different way. >>=20 >> Actually, we usually have a check to see if the loop found anything, >> but in that case it should something like >>=20 >> if (list_entry_is_head(entry, head, member)) { >> return with error; >> } >> do_somethin_with(entry); >>=20 >> Suffice? The list_entry_is_head() macro is designed to cope with the >> bogus entry on head problem. >=20 > That will work and is also what people already do. >=20 > The key problem is that we let people do the same thing over and over = again with slightly different implementations. >=20 > Out in the wild I've seen at least using a separate variable, using a = bool to indicate that something was found and just assuming that the = list has an entry. >=20 > The last case is bogus and basically what can break badly. >=20 > If we would have an unified macro which search for an entry combined = with automated reporting on patches to use that macro I think the = potential to introduce such issues will already go down massively = without auditing tons of existing code. Having a unified way to do the same thing would indeed be great. >=20 > Regards, > Christian. >=20 >>=20 >> James >>=20 >>=20 >=20 - Jakob