* [PATCH v2] list: Add a macro to test if entry is pointing to the head
@ 2020-09-29 13:43 Andy Shevchenko
2020-09-29 14:40 ` Rojewski, Cezary
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2020-09-29 13:43 UTC (permalink / raw)
To: Cezary Rojewski, linux-kernel, Andrew Morton; +Cc: Andy Shevchenko
Add a macro to test if entry is pointing to the head of the list
which is useful in cases like:
list_for_each_entry(pos, &head, member) {
if (cond)
break;
}
if (list_entry_is_head(pos, &head, member))
return -ERRNO;
that allows to avoid additional variable to be added to track if loop
has not been stopped in the middle.
While here, convert list_for_each_entry*() family of macros to use a new one.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: converted users inside list.h, dropped ambiguous description
include/linux/list.h | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/include/linux/list.h b/include/linux/list.h
index 796975c3c35c..89bdc92e75c3 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -609,6 +609,15 @@ static inline void list_splice_tail_init(struct list_head *list,
pos != (head); \
pos = n, n = pos->prev)
+/**
+ * list_entry_is_head - test if the entry points to the head of the list
+ * @pos: the type * to cursor
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ */
+#define list_entry_is_head(pos, head, member) \
+ (&pos->member == (head))
+
/**
* list_for_each_entry - iterate over list of given type
* @pos: the type * to use as a loop cursor.
@@ -617,7 +626,7 @@ static inline void list_splice_tail_init(struct list_head *list,
*/
#define list_for_each_entry(pos, head, member) \
for (pos = list_first_entry(head, typeof(*pos), member); \
- &pos->member != (head); \
+ !list_entry_is_head(pos, head, member); \
pos = list_next_entry(pos, member))
/**
@@ -628,7 +637,7 @@ static inline void list_splice_tail_init(struct list_head *list,
*/
#define list_for_each_entry_reverse(pos, head, member) \
for (pos = list_last_entry(head, typeof(*pos), member); \
- &pos->member != (head); \
+ !list_entry_is_head(pos, head, member); \
pos = list_prev_entry(pos, member))
/**
@@ -653,7 +662,7 @@ static inline void list_splice_tail_init(struct list_head *list,
*/
#define list_for_each_entry_continue(pos, head, member) \
for (pos = list_next_entry(pos, member); \
- &pos->member != (head); \
+ !list_entry_is_head(pos, head, member); \
pos = list_next_entry(pos, member))
/**
@@ -667,7 +676,7 @@ static inline void list_splice_tail_init(struct list_head *list,
*/
#define list_for_each_entry_continue_reverse(pos, head, member) \
for (pos = list_prev_entry(pos, member); \
- &pos->member != (head); \
+ !list_entry_is_head(pos, head, member); \
pos = list_prev_entry(pos, member))
/**
@@ -679,7 +688,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* Iterate over list of given type, continuing from current position.
*/
#define list_for_each_entry_from(pos, head, member) \
- for (; &pos->member != (head); \
+ for (; !list_entry_is_head(pos, head, member); \
pos = list_next_entry(pos, member))
/**
@@ -692,7 +701,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* Iterate backwards over list of given type, continuing from current position.
*/
#define list_for_each_entry_from_reverse(pos, head, member) \
- for (; &pos->member != (head); \
+ for (; !list_entry_is_head(pos, head, member); \
pos = list_prev_entry(pos, member))
/**
@@ -705,7 +714,7 @@ static inline void list_splice_tail_init(struct list_head *list,
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_first_entry(head, typeof(*pos), member), \
n = list_next_entry(pos, member); \
- &pos->member != (head); \
+ !list_entry_is_head(pos, head, member); \
pos = n, n = list_next_entry(n, member))
/**
@@ -721,7 +730,7 @@ static inline void list_splice_tail_init(struct list_head *list,
#define list_for_each_entry_safe_continue(pos, n, head, member) \
for (pos = list_next_entry(pos, member), \
n = list_next_entry(pos, member); \
- &pos->member != (head); \
+ !list_entry_is_head(pos, head, member); \
pos = n, n = list_next_entry(n, member))
/**
@@ -736,7 +745,7 @@ static inline void list_splice_tail_init(struct list_head *list,
*/
#define list_for_each_entry_safe_from(pos, n, head, member) \
for (n = list_next_entry(pos, member); \
- &pos->member != (head); \
+ !list_entry_is_head(pos, head, member); \
pos = n, n = list_next_entry(n, member))
/**
@@ -752,7 +761,7 @@ static inline void list_splice_tail_init(struct list_head *list,
#define list_for_each_entry_safe_reverse(pos, n, head, member) \
for (pos = list_last_entry(head, typeof(*pos), member), \
n = list_prev_entry(pos, member); \
- &pos->member != (head); \
+ !list_entry_is_head(pos, head, member); \
pos = n, n = list_prev_entry(n, member))
/**
--
2.28.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] list: Add a macro to test if entry is pointing to the head
2020-09-29 13:43 [PATCH v2] list: Add a macro to test if entry is pointing to the head Andy Shevchenko
@ 2020-09-29 14:40 ` Rojewski, Cezary
0 siblings, 0 replies; 3+ messages in thread
From: Rojewski, Cezary @ 2020-09-29 14:40 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-kernel, Andrew Morton
On 2020-09-29 3:43 PM, Andy Shevchenko wrote:
> Add a macro to test if entry is pointing to the head of the list
> which is useful in cases like:
>
> list_for_each_entry(pos, &head, member) {
> if (cond)
> break;
> }
> if (list_entry_is_head(pos, &head, member))
> return -ERRNO;
>
> that allows to avoid additional variable to be added to track if loop
> has not been stopped in the middle.
>
> While here, convert list_for_each_entry*() family of macros to use a new one.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: converted users inside list.h, dropped ambiguous description
Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>
This is a good addition to the list of helper macros found in list.h.
When looking at below:
> /**
> * list_for_each_entry - iterate over list of given type
> * @pos: the type * to use as a loop cursor.
> @@ -617,7 +626,7 @@ static inline void list_splice_tail_init(struct list_head *list,
> */
> #define list_for_each_entry(pos, head, member) \
> for (pos = list_first_entry(head, typeof(*pos), member); \
> - &pos->member != (head); \
> + !list_entry_is_head(pos, head, member); \
> pos = list_next_entry(pos, member))
>
it seems such helper should have been here a long time ago (notice the
usage of helpers for initial assignment and cursor update while the
loop-exit check was devoid of such).
Czarek
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] list: Add a macro to test if entry is pointing to the head
@ 2020-09-29 18:19 kernel test robot
0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2020-09-29 18:19 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 3104 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20200929134342.51489-1-andriy.shevchenko@linux.intel.com>
References: <20200929134342.51489-1-andriy.shevchenko@linux.intel.com>
TO: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
TO: Cezary Rojewski <cezary.rojewski@intel.com>
TO: linux-kernel(a)vger.kernel.org
TO: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>
CC: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Hi Andy,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linux/master]
[also build test WARNING on hnaz-linux-mm/master linus/master v5.9-rc7 next-20200929]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Andy-Shevchenko/list-Add-a-macro-to-test-if-entry-is-pointing-to-the-head/20200929-214516
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git bcf876870b95592b52519ed4aafcf9d95999bc9c
:::::: branch date: 5 hours ago
:::::: commit date: 5 hours ago
config: m68k-randconfig-s031-20200929 (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.2-201-g24bdaac6-dirty
# https://github.com/0day-ci/linux/commit/14b9d0b5de0db1b59e77c8589c5c5701d31c7ae4
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Andy-Shevchenko/list-Add-a-macro-to-test-if-entry-is-pointing-to-the-head/20200929-214516
git checkout 14b9d0b5de0db1b59e77c8589c5c5701d31c7ae4
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
echo
echo "sparse warnings: (new ones prefixed by >>)"
echo
fs/orangefs/devorangefs-req.c: note: in included file (through include/linux/mmzone.h, include/linux/gfp.h, include/linux/slab.h, ...):
>> include/linux/spinlock.h:393:9: sparse: sparse: context imbalance in 'orangefs_devreq_read' - different lock contexts for basic block
vim +/orangefs_devreq_read +393 include/linux/spinlock.h
c2f21ce2e31286 Thomas Gleixner 2009-12-02 390
3490565b633c70 Denys Vlasenko 2015-07-13 391 static __always_inline void spin_unlock(spinlock_t *lock)
c2f21ce2e31286 Thomas Gleixner 2009-12-02 392 {
c2f21ce2e31286 Thomas Gleixner 2009-12-02 @393 raw_spin_unlock(&lock->rlock);
c2f21ce2e31286 Thomas Gleixner 2009-12-02 394 }
c2f21ce2e31286 Thomas Gleixner 2009-12-02 395
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 18365 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-29 18:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-29 13:43 [PATCH v2] list: Add a macro to test if entry is pointing to the head Andy Shevchenko
2020-09-29 14:40 ` Rojewski, Cezary
2020-09-29 18:19 kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.