Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp649831rdh; Thu, 26 Oct 2023 11:43:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMfmwa7PD+QhKPvDCQdJQ0MnmsCf7eV9ordOY+l6yJkDWsk/DdNzr89Svb3//e8dBV2Bqv X-Received: by 2002:a25:d214:0:b0:da0:a651:e220 with SMTP id j20-20020a25d214000000b00da0a651e220mr4656803ybg.7.1698345793245; Thu, 26 Oct 2023 11:43:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698345793; cv=none; d=google.com; s=arc-20160816; b=wGGPFw9h9x3ros11HrsHl0RgciMrTCfTVEwDS6uK/mMvraD/XpjHSrkqCK5StB0hfG mgn/q3q0Rkgo+PQ3+T04754Z8Qf+ExhE790aQQj/6VlR9WtljadzYi3sdI1vDVr+zg0L dEW7A0zJpgmkThWRRfu7fi3R5+7TPG9nz+Lxy80W0H/YfyluufMi2cOhJAhC6eQQoY17 KGwaOXkoFfuPAjRX8erEn4DuKyqNB2xUcJ9PI4oUm4217sJ8Ed2loR2KtzErJoAEAFFY yXNSF1pVDfvjLH4F2hVfxdcuJ4vaZxc6XVjxiMkg63f6y+8mmtUqZUSvihQNvBpnHRyh X3rg== 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=yMgObftLxZ0/iptHapd2/YKZ8W4OQcuVi9EXheReHJU=; fh=LFNYP593rS/mtA/ElBXAjnRmX9c+TeKW5ZTSpd60Igs=; b=nztbTM9lVktXIwZg68RJMD5KDHCYWrW6/uqaychsMgQrlIPcLboObC0++nbZWEgJjD vJAh21xzCItX56Q/Fe2T0ggtwr4RVsESNa0+KcpcI6KU3qeUkYAE9y+ges6SFvEmQfR9 5PObbhu3YL+OtDc58nGbUDUdzJwxZa+UnCFQE0aa7BI4cPCZsinMv9aPwLIr7/EqKNyj rBxQussmao8AR6PDJKr+NcafmBtlJevc9POgZN7VHbzIJToWg9OnlQ67QVKlP1CPu7cz bsWw0N6qGj/Fn3pL6CXPJ7Wy9WQ+5giSIViqd2e5cRMzo9D/NsNVj1IcwfLqmeAMU5Gy pM+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=JBBrSCxB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m134-20020a25268c000000b00da03fbfa085si8756650ybm.331.2023.10.26.11.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 11:43:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=JBBrSCxB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 82E348194743; Thu, 26 Oct 2023 11:43:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbjJZSm7 (ORCPT + 99 others); Thu, 26 Oct 2023 14:42:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229649AbjJZSm6 (ORCPT ); Thu, 26 Oct 2023 14:42:58 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E5C710A for ; Thu, 26 Oct 2023 11:42:56 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2c59a4dd14cso17198901fa.2 for ; Thu, 26 Oct 2023 11:42:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1698345774; x=1698950574; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=yMgObftLxZ0/iptHapd2/YKZ8W4OQcuVi9EXheReHJU=; b=JBBrSCxBinB22yJIYzpipzlnM13q9IdMJHyZufqCIPZSOYRLu2vK38b8EnaUqRRB2x 6U57h4ejTrfGe7CuSaR2mPkOwKuQ2uo2Qkn6raELLelysrAWrQsPAtdNfJV0hTwEu0Un PP64OLX1Zqz6NX+fFIRAW2cf0fRM0M0DKT/BQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698345774; x=1698950574; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yMgObftLxZ0/iptHapd2/YKZ8W4OQcuVi9EXheReHJU=; b=hskCzgMX6FfkwZ82TqU80vk7/h+2vZiqCTmt0imr8dn+5z5QwTTp+aXWMCIlat6HaB pNhcsCaaQW0UgElLXjEs4MniGQkJruOLOI1QvlWT0bSeEwzcCiQhZfBEy4jodVtURp/8 fMWVz4yr4ec3cZZ4Fk4LsOh2L5Q+aqw/IdjMo2zPLFCfSZopUmueOrdcPeadqR5xDVvW 4E5sTFUyAclIHef6vAcDa2CuKePwbIZSxBF6HejwMbtDMmgZntlu0isWdHONHlvDVLH9 pasqSQTYJrIwudeE/izwbvDHeupDwmrrcbc2ULkJEAQ7tKSw06ZKn3QEo6vp4ebSJiQ/ jITg== X-Gm-Message-State: AOJu0YyIZoJsVOm9WU5QpbJwBZka8vK82muiKsfHi9s0Ej/XFaJbt7F+ 5arkxT39eG87QLTz71Fzw+4MnAbEEq16Xkq6/wH3iw== X-Received: by 2002:a05:6512:39c8:b0:507:ae8b:a573 with SMTP id k8-20020a05651239c800b00507ae8ba573mr208574lfu.51.1698345774422; Thu, 26 Oct 2023 11:42:54 -0700 (PDT) Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com. [209.85.208.181]) by smtp.gmail.com with ESMTPSA id c24-20020a056512075800b005079ff16d9fsm3090439lfs.138.2023.10.26.11.42.53 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Oct 2023 11:42:53 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2c59a4dd14cso17198551fa.2 for ; Thu, 26 Oct 2023 11:42:53 -0700 (PDT) X-Received: by 2002:a05:6512:1289:b0:507:aa44:28fc with SMTP id u9-20020a056512128900b00507aa4428fcmr150667lfs.53.1698345772939; Thu, 26 Oct 2023 11:42:52 -0700 (PDT) MIME-Version: 1.0 References: <20231020102901.3354273-1-mszeredi@redhat.com> <20231020102901.3354273-2-mszeredi@redhat.com> <3ab474953c734d0bbf0177bf5d208799@AcuMS.aculab.com> In-Reply-To: From: Linus Torvalds Date: Thu, 26 Oct 2023 08:42:35 -1000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 1/2] add list_for_each_entry_del() To: Miklos Szeredi Cc: David Laight , "linux-kernel@vger.kernel.org" , Takashi Iwai , Mauro Carvalho Chehab , Greg Kroah-Hartman , Jakub Kicinski , Paolo Abeni , Al Viro , Christian Brauner , James Bottomley Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 26 Oct 2023 11:43:11 -0700 (PDT) On Wed, 25 Oct 2023 at 23:52, Miklos Szeredi wrote: > > Something like this? > > - list_for_each_entry_del(entry, head, member)) > + while (list_del_first(entry, head, member)) > > This allows the compact loop condition, and I always hated having to > pass the type to list_*entry()... Disadvantage being that the > assignment is now implicit (just as with all the list iterators). So I have two issues with this. One is purely syntactical: I would be personally happier if any new list iterators kept the declaration of the iterator internally to itself. IOW, instead of struct request *rq; list_for_each_entry_del(rq, list, queuelist) { ... we'd move on to modern C which allows declaring variables in for loops (so they aren't visible outside the loop), and turn it into list_for_each_entry_del(struct request, rq, list, queuelist) { ... which would then behind the scenes turn into for (struct request *rq; rq = list_del_first(list, queuelist); ) { ... or something. None of these "we have stale 'rq' variables outside the list" things. (Of course, I realize that people then sometimes intentionally use those stale variables outside the list by breaking out of the loop in the middle, but it's ugly) That said, the *second* issue I have with this whole list_for_each_entry_del() is that it seems a bit mis-designed. You have two cases: - you want to unconditionally delete everything - you might want to have a condition on it and break out early and the first one is often better dealt with by first moving the list to a private list head (presumably using list_splice_init()), and then iterating the private list head instead. That can avoid having to hold a lock over the whole loop (or dropping it and re-taking it), for example. And that *second* case would presumably want to use list_for_each_entry_safe(), and then do the "list_del()" at the _end_ of the loop, not at the beginning? Hmm? I guess the "delete the whole list" is the simple case you want to deal with, and people who can use a private list to avoid locking already do the list_splice_init() thing separately (or create the private list as a separate phase, to also deal with the "I'm not going to delete everything" issue). Linus