1 From 4d70c74659d9746502b23d055dba03d1d28ec388 Mon Sep 17 00:00:00 2001
2 From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
3 Date: Wed, 30 Nov 2022 15:48:35 +0200
4 Subject: [PATCH] i915: Move list_count() to list.h as list_count_nodes() for
7 Some of the existing users, and definitely will be new ones, want to
8 count existing nodes in the list. Provide a generic API for that by
9 moving code from i915 to list.h.
11 Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
12 Acked-by: Jani Nikula <jani.nikula@intel.com>
13 Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
14 Link: https://lore.kernel.org/r/20221130134838.23805-1-andriy.shevchenko@linux.intel.com
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
17 drivers/gpu/drm/i915/gt/intel_engine_cs.c | 15 ++-------------
18 include/linux/list.h | 15 +++++++++++++++
19 2 files changed, 17 insertions(+), 13 deletions(-)
21 --- a/drivers/gpu/drm/i915/gt/intel_engine_cs.c
22 +++ b/drivers/gpu/drm/i915/gt/intel_engine_cs.c
23 @@ -1639,17 +1639,6 @@ static void print_request_ring(struct dr
27 -static unsigned long list_count(struct list_head *list)
29 - struct list_head *pos;
30 - unsigned long count = 0;
32 - list_for_each(pos, list)
38 static unsigned long read_ul(void *p, size_t x)
40 return *(unsigned long *)(p + x);
41 @@ -1824,8 +1813,8 @@ void intel_engine_dump(struct intel_engi
42 spin_lock_irqsave(&engine->sched_engine->lock, flags);
43 engine_dump_active_requests(engine, m);
45 - drm_printf(m, "\tOn hold?: %lu\n",
46 - list_count(&engine->sched_engine->hold));
47 + drm_printf(m, "\tOn hold?: %zu\n",
48 + list_count_nodes(&engine->sched_engine->hold));
49 spin_unlock_irqrestore(&engine->sched_engine->lock, flags);
51 drm_printf(m, "\tMMIO base: 0x%08x\n", engine->mmio_base);
52 --- a/include/linux/list.h
53 +++ b/include/linux/list.h
54 @@ -628,6 +628,21 @@ static inline void list_splice_tail_init
55 pos = n, n = pos->prev)
58 + * list_count_nodes - count nodes in the list
59 + * @head: the head for your list.
61 +static inline size_t list_count_nodes(struct list_head *head)
63 + struct list_head *pos;
66 + list_for_each(pos, head)
73 * list_entry_is_head - test if the entry points to the head of the list
74 * @pos: the type * to cursor
75 * @head: the head for your list.