mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jakob Koschel <jakobkoschel@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jakob Koschel <jakobkoschel@gmail.com>,
	linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Greg Kroah-Hartman <greg@kroah.com>,
	Mike Rapoport <rppt@kernel.org>,
	"Brian Johannesmeyer" <bjohannesmeyer@gmail.com>,
	Cristiano Giuffrida <c.giuffrida@vu.nl>,
	"Bos, H.J." <h.j.bos@vu.nl>
Subject: [PATCH] list: always set pos in list_prepare_entry()
Date: Sun,  6 Mar 2022 17:26:35 +0100	[thread overview]
Message-ID: <20220306162635.2930407-1-jakobkoschel@gmail.com> (raw)

In order to assign the result from list_prepare_entry() to another
variable, it should also be set when pos != NULL.

This will be useful once the list iterator is no longer used after
the loop.

The original code:

	list_for_each_entry(fl, head, list) {
		if (...)
			break;
	}

	list_for_each_entry_continue(fl, head, list) {

	}

can then just be turned into something like this:


	list_for_each_entry(fl, head, list) {
		if (...) {
			tmp = fl;
			break;
		}
	}

	fl = list_prepare_entry(tmp, head, list);
	list_for_each_entry_continue(fl, head, list) {

	}


The compiler should happily optimize away the
TRUE case if the variable being assigned is the same:

	pos = list_prepare_entry(pos, head, list);

and only do it in the case where the variable to assign
is different:

	pos = list_prepare_entry(tmp, head, list);

Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 include/linux/list.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/list.h b/include/linux/list.h
index dd6c2041d09c..050747fb5ea8 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -659,7 +659,7 @@ static inline void list_splice_tail_init(struct list_head *list,
  * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
  */
 #define list_prepare_entry(pos, head, member) \
-	((pos) ? : list_entry(head, typeof(*pos), member))
+	((pos) ? pos : list_entry(head, typeof(*pos), member))

 /**
  * list_for_each_entry_continue - continue iteration over list of given type

base-commit: 719fce7539cd3e186598e2aed36325fe892150cf
--
2.25.1


             reply	other threads:[~2022-03-06 16:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-06 16:26 Jakob Koschel [this message]
2022-03-07  9:49 ` Andy Shevchenko
2022-03-07 10:47   ` Jakob Koschel

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=20220306162635.2930407-1-jakobkoschel@gmail.com \
    --to=jakobkoschel@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bjohannesmeyer@gmail.com \
    --cc=c.giuffrida@vu.nl \
    --cc=greg@kroah.com \
    --cc=h.j.bos@vu.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rppt@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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®