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.

lib min_heap: update min_heap_push() and min_heap_pop() to return bool values

Modify the min_heap_push() and min_heap_pop() to return a boolean value.
They now return false when the operation fails and true when it succeeds.

Link: https://lkml.kernel.org/r/20240524152958.919343-12-visitorckw@gmail.com
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Bagas Sanjaya <bagasdotme@gmail.com>
Cc: Brian Foster <bfoster@redhat.com>
Cc: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
Cc: Coly Li <colyli@suse.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Matthew Sakai <msakai@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kuan-Wei Chiu and committed by
Andrew Morton
2eb637c6 420f1710

+8 -4
+8 -4
include/linux/min_heap.h
··· 147 147 148 148 /* Remove minimum element from the heap, O(log2(nr)). */ 149 149 static __always_inline 150 - void __min_heap_pop(min_heap_char *heap, size_t elem_size, 150 + bool __min_heap_pop(min_heap_char *heap, size_t elem_size, 151 151 const struct min_heap_callbacks *func, void *args) 152 152 { 153 153 void *data = heap->data; 154 154 155 155 if (WARN_ONCE(heap->nr <= 0, "Popping an empty heap")) 156 - return; 156 + return false; 157 157 158 158 /* Place last element at the root (position 0) and then sift down. */ 159 159 heap->nr--; 160 160 memcpy(data, data + (heap->nr * elem_size), elem_size); 161 161 __min_heapify(heap, 0, elem_size, func, args); 162 + 163 + return true; 162 164 } 163 165 164 166 #define min_heap_pop(_heap, _func, _args) \ ··· 186 184 187 185 /* Push an element on to the heap, O(log2(nr)). */ 188 186 static __always_inline 189 - void __min_heap_push(min_heap_char *heap, const void *element, size_t elem_size, 187 + bool __min_heap_push(min_heap_char *heap, const void *element, size_t elem_size, 190 188 const struct min_heap_callbacks *func, void *args) 191 189 { 192 190 void *data = heap->data; ··· 194 192 int pos; 195 193 196 194 if (WARN_ONCE(heap->nr >= heap->size, "Pushing on a full heap")) 197 - return; 195 + return false; 198 196 199 197 /* Place at the end of data. */ 200 198 pos = heap->nr; ··· 209 207 break; 210 208 func->swp(parent, child, args); 211 209 } 210 + 211 + return true; 212 212 } 213 213 214 214 #define min_heap_push(_heap, _element, _func, _args) \