mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Miklos Szeredi' <mszeredi@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Takashi Iwai <tiwai@suse.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	"Christian Brauner" <brauner@kernel.org>,
	James Bottomley <James.Bottomley@hansenpartnership.com>
Subject: RE: [RFC PATCH 1/2] add list_for_each_entry_del()
Date: Sat, 21 Oct 2023 09:59:59 +0000	[thread overview]
Message-ID: <3ab474953c734d0bbf0177bf5d208799@AcuMS.aculab.com> (raw)
In-Reply-To: <20231020102901.3354273-2-mszeredi@redhat.com>

From: Miklos Szeredi
> Sent: 20 October 2023 11:29
> 
> Add a new list iteration macro that always takes the first element of the
> list and removes it, until the list is empty.
...
> +/**
> + * list_for_each_entry_del - iterate list and remove elements
> + * @pos:	the type * to use as a loop cursor.
> + * @head:	the head for your list.
> + * @member:	the name of the list_head within the struct.
> + *
> + * Delete first element from list before the iteration.  Iterate until
> + * the list is empty.
> + */
> +#define list_for_each_entry_del(pos, head, member)			\
> +	while (!list_empty(head) &&					\
> +		({ pos = list_first_entry(head, typeof(*(pos)), member);\
> +		   list_del(&(pos)->member); 1; }))

That pattern is actually pretty obvious.
Add another wrapper and people end up having to read the
header to find out what it does.

I can't help feeling that if you look inside list_empty(),
list_first_entry() and list_del() there is a lot of
replicated code and tests.

Adding a list_del_first() function that returns the deleted
item or NULL to optimise it might make more sense.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  reply	other threads:[~2023-10-21 10:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-20 10:28 [RFC PATCH 0/2] add list iterate & delete macros Miklos Szeredi
2023-10-20 10:28 ` [RFC PATCH 1/2] add list_for_each_entry_del() Miklos Szeredi
2023-10-21  9:59   ` David Laight [this message]
2023-10-26  9:52     ` Miklos Szeredi
2023-10-26 18:42       ` Linus Torvalds
2023-10-20 10:29 ` [RFC PATCH 2/2] replace trivial incarnations of list_for_each_entry_del() Miklos Szeredi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ab474953c734d0bbf0177bf5d208799@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=brauner@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=mszeredi@redhat.com \
    --cc=pabeni@redhat.com \
    --cc=tiwai@suse.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®