Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools lib: Add list_last_entry_or_null()

Add list_last_entry_or_null() to get the last element from a list,
returns NULL if the list is empty.

Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220709015033.38326-6-yangjihong1@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Yang Jihong and committed by
Arnaldo Carvalho de Melo
e432947e 97179d9d

+11
+11
tools/include/linux/list.h
··· 385 385 (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL) 386 386 387 387 /** 388 + * list_last_entry_or_null - get the last element from a list 389 + * @ptr: the list head to take the element from. 390 + * @type: the type of the struct this is embedded in. 391 + * @member: the name of the list_head within the struct. 392 + * 393 + * Note that if the list is empty, it returns NULL. 394 + */ 395 + #define list_last_entry_or_null(ptr, type, member) \ 396 + (!list_empty(ptr) ? list_last_entry(ptr, type, member) : NULL) 397 + 398 + /** 388 399 * list_next_entry - get the next element in list 389 400 * @pos: the type * to cursor 390 401 * @member: the name of the list_head within the struct.