lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Wed, 23 Feb 2022 15:33:14 -0700 From: Ricardo Martinez <ricardo.martinez@...ux.intel.com> To: netdev@...r.kernel.org, linux-wireless@...r.kernel.org Cc: kuba@...nel.org, davem@...emloft.net, johannes@...solutions.net, ryazanov.s.a@...il.com, loic.poulain@...aro.org, m.chetan.kumar@...el.com, chandrashekar.devegowda@...el.com, linuxwwan@...el.com, chiranjeevi.rapolu@...ux.intel.com, haijun.liu@...iatek.com, amir.hanania@...el.com, andriy.shevchenko@...ux.intel.com, dinesh.sharma@...el.com, eliot.lee@...el.com, ilpo.johannes.jarvinen@...el.com, moises.veleta@...el.com, pierre-louis.bossart@...el.com, muralidharan.sethuraman@...el.com, Soumya.Prakash.Mishra@...el.com, sreehari.kancharla@...el.com, madhusmita.sahu@...el.com, Ricardo Martinez <ricardo.martinez@...ux.intel.com> Subject: [PATCH net-next v5 01/13] list: Add list_next_entry_circular() and list_prev_entry_circular() Add macros to get the next or previous entries and wraparound if needed. For example, calling list_next_entry_circular() on the last element should return the first element in the list. Signed-off-by: Ricardo Martinez <ricardo.martinez@...ux.intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com> --- include/linux/list.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index dd6c2041d09c..c147eeb2d39d 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -563,6 +563,19 @@ static inline void list_splice_tail_init(struct list_head *list, #define list_next_entry(pos, member) \ list_entry((pos)->member.next, typeof(*(pos)), member) +/** + * list_next_entry_circular - get the next element in list + * @pos: the type * to cursor. + * @head: the list head to take the element from. + * @member: the name of the list_head within the struct. + * + * Wraparound if pos is the last element (return the first element). + * Note, that list is expected to be not empty. + */ +#define list_next_entry_circular(pos, head, member) \ + (list_is_last(&(pos)->member, head) ? \ + list_first_entry(head, typeof(*(pos)), member) : list_next_entry(pos, member)) + /** * list_prev_entry - get the prev element in list * @pos: the type * to cursor @@ -571,6 +584,19 @@ static inline void list_splice_tail_init(struct list_head *list, #define list_prev_entry(pos, member) \ list_entry((pos)->member.prev, typeof(*(pos)), member) +/** + * list_prev_entry_circular - get the prev element in list + * @pos: the type * to cursor. + * @head: the list head to take the element from. + * @member: the name of the list_head within the struct. + * + * Wraparound if pos is the first element (return the last element). + * Note, that list is expected to be not empty. + */ +#define list_prev_entry_circular(pos, head, member) \ + (list_is_first(&(pos)->member, head) ? \ + list_last_entry(head, typeof(*(pos)), member) : list_prev_entry(pos, member)) + /** * list_for_each - iterate over a list * @pos: the &struct list_head to use as a loop cursor. -- 2.17.1
Powered by blists - more mailing lists