]> git.baikalelectronics.ru Git - kernel.git/commit
include/linux/list.h: add a macro to test if entry is pointing to the head
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 16 Oct 2020 03:11:31 +0000 (20:11 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Sep 2021 10:26:20 +0000 (12:26 +0200)
commitf22945a5623be9411c10b2ab5ed0713d78723828
tree43493d3e7dae90c9d85ac3ca93f507fcfd7938e4
parent12a4dcd786ac1924145db8387b8cd57a6e61e110
include/linux/list.h: add a macro to test if entry is pointing to the head

commit e130816164e244b692921de49771eeb28205152d upstream.

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>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>
Link: https://lkml.kernel.org/r/20200929134342.51489-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/list.h