Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3127529pxm; Mon, 28 Feb 2022 12:37:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGoTsKBPAohTGrzzlmK6NcAuDreec5OoYiHN6FoSXilXVUnPHRvstxFlSphtKwr0tUmr7j X-Received: by 2002:a17:902:9895:b0:151:6a35:dab2 with SMTP id s21-20020a170902989500b001516a35dab2mr6808671plp.118.1646080643934; Mon, 28 Feb 2022 12:37:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646080643; cv=none; d=google.com; s=arc-20160816; b=BDIyhz4eiswgG4lVLdGye7pPbPw2UeFTUjV4fiUELWDQ7yd0++i3Vhpo32DtRfL9tQ B120Uy8bVsmzJ4hDbeQoMjr2GOdoNs6gdHgyAgnCcRQT9OxgIwYzUJnOc1Evvk7I6lz/ URbFElGTsO2RQZM4boy0nxvJecGatKzTaUPNFPkCKcWmEhVIYLZmOZRhYdT56raqM4J0 2n84nORer7Vde8C6LBlAkwic+lLl9YFHkquyMI4qqOwfwgqoKSmdiJ8N6N3EStkVwzhT CSH2qMaSOXDt5Gis6SmDCB9KEB7TRdLa+FN7YGssbhACgXTxymGjp33ourpiDN9nO4ST cd7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gT/mxIYbzDn15+z84Rt0/ZmLFqIl34ZjMPCseIzUB9o=; b=UbinXfXtMh2BLyaC6Tb3sS4NGEXr6+3/yupTsEH3aOnL2lToTt84UoB0x30qWF4M92 3Uf/A7/BVvNruxLn+CM4eZwAM/L+SMFYABkQoc0ghx24jxgRJZL24TUtrYOtUUxNpGNR v/9/0Z8W4z3P9U5aS8ICQXlRDD3ABe4eekD6ZfB0nohVlgKwRV7rsHs3cRhacZpXmBt6 26KRXahgrbWic/werUBa7EJmGbjy+qkezgv2TtikjN3yHqBIrpuQhqq94xf1cxk4dqpl U8gut4axKLBrRfyxdY1jsn5Vp2Yz6uFhlhsg1rnUwsPdN41Ko6ilBNJh8RfoxKW79wy8 TYZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Tm2RrZZp; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q2-20020a17090a4f8200b001b96bc9240bsi427066pjh.76.2022.02.28.12.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:37:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-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=@linux-foundation.org header.s=google header.b=Tm2RrZZp; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7447022B12; Mon, 28 Feb 2022 11:56:43 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229894AbiB1T5R (ORCPT + 72 others); Mon, 28 Feb 2022 14:57:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229896AbiB1T5P (ORCPT ); Mon, 28 Feb 2022 14:57:15 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 842A317E0C for ; Mon, 28 Feb 2022 11:56:36 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id dr20so2358481ejc.6 for ; Mon, 28 Feb 2022 11:56:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gT/mxIYbzDn15+z84Rt0/ZmLFqIl34ZjMPCseIzUB9o=; b=Tm2RrZZp9rg85Q2lAdsba4a3IH+hQMy5xZCbUizCCXmPzyfZ+2VRqEslWXZB4tPt3B Xz8lYe63CHEdQCuWSaPC9nNMhFWrnR54Ihwd0u2qPZVZ4zvhHacXKCw+SJS4BR1PfT62 xCFGBc0xrmrOEo0QPHvZeTHUhXNuWYmty+udI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gT/mxIYbzDn15+z84Rt0/ZmLFqIl34ZjMPCseIzUB9o=; b=sPvMN+KmePEpVCRzzsHHQAhUQNjfE4eABf7Cvjy+KjGX3u0OnC82CIfymV+OLuBnST 0JyR9QmSFPjtCC/esRNmoESbAe8UmEtNp/5yLxcgcWiePk7BYQcLWILk0gVeOpKELy/G sDaruOCQ4wXulp5cbvcFyKA+Kli4z5Hw7WUPlXChoUyKiuiJzAfWS1+/gQ3bSX7Ng164 /966HR6JxSM0sWzreWOIw9QxSAL7JXcfpXASAIKzpjSpx+UcltGptrg/15ICLOm4e/55 qPbD2K2dwsRYU+AOjKdkxcethHoMnP9nHRiW+wO0ih0jLJO+IqK5GPGLVwgRDsXjTrmy 9rDQ== X-Gm-Message-State: AOAM531mOfRfAIp7c9AnQggjVcK2DDjMnck1Vmn1g9uK0iImIu3bKkin nc6gve/oZfaAzeKlTo+Yrm6jI3TuT/mMiZXK3iE= X-Received: by 2002:a17:906:7185:b0:6cd:e09c:e5f5 with SMTP id h5-20020a170906718500b006cde09ce5f5mr16101736ejk.287.1646078194871; Mon, 28 Feb 2022 11:56:34 -0800 (PST) Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com. [209.85.218.44]) by smtp.gmail.com with ESMTPSA id eo8-20020a1709069b0800b006ce6eef6836sm4620381ejc.131.2022.02.28.11.56.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Feb 2022 11:56:34 -0800 (PST) Received: by mail-ej1-f44.google.com with SMTP id a23so27064552eju.3 for ; Mon, 28 Feb 2022 11:56:33 -0800 (PST) X-Received: by 2002:ac2:5313:0:b0:443:99c1:7e89 with SMTP id c19-20020ac25313000000b0044399c17e89mr13183568lfh.531.1646078183366; Mon, 28 Feb 2022 11:56:23 -0800 (PST) MIME-Version: 1.0 References: <20220228110822.491923-1-jakobkoschel@gmail.com> <20220228110822.491923-3-jakobkoschel@gmail.com> <2e4e95d6-f6c9-a188-e1cd-b1eae465562a@amd.com> In-Reply-To: <2e4e95d6-f6c9-a188-e1cd-b1eae465562a@amd.com> From: Linus Torvalds Date: Mon, 28 Feb 2022 11:56:07 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/6] treewide: remove using list iterator after loop body as a ptr To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Jakob Koschel , 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-Type: multipart/mixed; boundary="00000000000064a3e305d91971a9" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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-wireless@vger.kernel.org --00000000000064a3e305d91971a9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 28, 2022 at 4:19 AM Christian K=C3=B6nig wrote: > > I don't think that using the extra variable makes the code in any way > more reliable or easier to read. So I think the next step is to do the attached patch (which requires that "-std=3Dgnu11" that was discussed in the original thread). That will guarantee that the 'pos' parameter of list_for_each_entry() is only updated INSIDE the for_each_list_entry() loop, and can never point to the (wrongly typed) head entry. And I would actually hope that it should actually cause compiler warnings about possibly uninitialized variables if people then use the 'pos' pointer outside the loop. Except (a) that code in sgx/encl.c currently initializes 'tmp' to NULL for inexplicable reasons - possibly because it already expected this behavior (b) when I remove that NULL initializer, I still don't get a warning, because we've disabled -Wno-maybe-uninitialized since it results in so many false positives. Oh well. Anyway, give this patch a look, and at least if it's expanded to do "(pos) =3D NULL" in the entry statement for the for-loop, it will avoid the HEAD type confusion that Jakob is working on. And I think in a cleaner way than the horrid games he plays. (But it won't avoid possible CPU speculation of such type confusion. That, in my opinion, is a completely different issue) 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? Linus --00000000000064a3e305d91971a9 Content-Type: application/octet-stream; name=p Content-Disposition: attachment; filename=p Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_l073sb6w0 ZGlmZiAtLWdpdCBhL2luY2x1ZGUvbGludXgvbGlzdC5oIGIvaW5jbHVkZS9saW51eC9saXN0LmgK aW5kZXggZGQ2YzIwNDFkMDljLi5iYWI5OTU1OTZhYWEgMTAwNjQ0Ci0tLSBhL2luY2x1ZGUvbGlu dXgvbGlzdC5oCisrKyBiL2luY2x1ZGUvbGludXgvbGlzdC5oCkBAIC02MzQsMTAgKzYzNCwxMCBA QCBzdGF0aWMgaW5saW5lIHZvaWQgbGlzdF9zcGxpY2VfdGFpbF9pbml0KHN0cnVjdCBsaXN0X2hl YWQgKmxpc3QsCiAgKiBAaGVhZDoJdGhlIGhlYWQgZm9yIHlvdXIgbGlzdC4KICAqIEBtZW1iZXI6 CXRoZSBuYW1lIG9mIHRoZSBsaXN0X2hlYWQgd2l0aGluIHRoZSBzdHJ1Y3QuCiAgKi8KLSNkZWZp bmUgbGlzdF9mb3JfZWFjaF9lbnRyeShwb3MsIGhlYWQsIG1lbWJlcikJCQkJXAotCWZvciAocG9z ID0gbGlzdF9maXJzdF9lbnRyeShoZWFkLCB0eXBlb2YoKnBvcyksIG1lbWJlcik7CVwKLQkgICAg ICFsaXN0X2VudHJ5X2lzX2hlYWQocG9zLCBoZWFkLCBtZW1iZXIpOwkJCVwKLQkgICAgIHBvcyA9 IGxpc3RfbmV4dF9lbnRyeShwb3MsIG1lbWJlcikpCisjZGVmaW5lIGxpc3RfZm9yX2VhY2hfZW50 cnkocG9zLCBoZWFkLCBtZW1iZXIpCQkJCQlcCisJZm9yICh0eXBlb2YocG9zKSBfX2l0ZXIgPSBs aXN0X2ZpcnN0X2VudHJ5KGhlYWQsIHR5cGVvZigqcG9zKSwgbWVtYmVyKTsJXAorCSAgICAgIWxp c3RfZW50cnlfaXNfaGVhZChfX2l0ZXIsIGhlYWQsIG1lbWJlcikgJiYgKCgocG9zKT1fX2l0ZXIp LDEpOwlcCisJICAgICBfX2l0ZXIgPSBsaXN0X25leHRfZW50cnkoX19pdGVyLCBtZW1iZXIpKQog CiAvKioKICAqIGxpc3RfZm9yX2VhY2hfZW50cnlfcmV2ZXJzZSAtIGl0ZXJhdGUgYmFja3dhcmRz IG92ZXIgbGlzdCBvZiBnaXZlbiB0eXBlLgo= --00000000000064a3e305d91971a9--