Skip to content

Commit 63e2da3

Browse files
arndbAlexei Starovoitov
authored andcommitted
bpf: work around -Wuninitialized warning
Splitting these out into separate helper functions means that we actually pass an uninitialized variable into another function call if dec_active() happens to not be inlined, and CONFIG_PREEMPT_RT is disabled: kernel/bpf/memalloc.c: In function 'add_obj_to_free_list': kernel/bpf/memalloc.c:200:9: error: 'flags' is used uninitialized [-Werror=uninitialized] 200 | dec_active(c, flags); Avoid this by passing the flags by reference, so they either get initialized and dereferenced through a pointer, or the pointer never gets accessed at all. Fixes: 18e027b ("bpf: Factor out inc/dec of active flag into helpers.") Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20230725202653.2905259-1-arnd@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 13fd5e1 commit 63e2da3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

kernel/bpf/memalloc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ static void inc_active(struct bpf_mem_cache *c, unsigned long *flags)
183183
WARN_ON_ONCE(local_inc_return(&c->active) != 1);
184184
}
185185

186-
static void dec_active(struct bpf_mem_cache *c, unsigned long flags)
186+
static void dec_active(struct bpf_mem_cache *c, unsigned long *flags)
187187
{
188188
local_dec(&c->active);
189189
if (IS_ENABLED(CONFIG_PREEMPT_RT))
190-
local_irq_restore(flags);
190+
local_irq_restore(*flags);
191191
}
192192

193193
static void add_obj_to_free_list(struct bpf_mem_cache *c, void *obj)
@@ -197,7 +197,7 @@ static void add_obj_to_free_list(struct bpf_mem_cache *c, void *obj)
197197
inc_active(c, &flags);
198198
__llist_add(obj, &c->free_llist);
199199
c->free_cnt++;
200-
dec_active(c, flags);
200+
dec_active(c, &flags);
201201
}
202202

203203
/* Mostly runs from irq_work except __init phase. */
@@ -344,7 +344,7 @@ static void free_bulk(struct bpf_mem_cache *c)
344344
cnt = --c->free_cnt;
345345
else
346346
cnt = 0;
347-
dec_active(c, flags);
347+
dec_active(c, &flags);
348348
if (llnode)
349349
enque_to_free(tgt, llnode);
350350
} while (cnt > (c->high_watermark + c->low_watermark) / 2);
@@ -384,7 +384,7 @@ static void check_free_by_rcu(struct bpf_mem_cache *c)
384384
llist_for_each_safe(llnode, t, llist_del_all(&c->free_llist_extra_rcu))
385385
if (__llist_add(llnode, &c->free_by_rcu))
386386
c->free_by_rcu_tail = llnode;
387-
dec_active(c, flags);
387+
dec_active(c, &flags);
388388
}
389389

390390
if (llist_empty(&c->free_by_rcu))
@@ -408,7 +408,7 @@ static void check_free_by_rcu(struct bpf_mem_cache *c)
408408
inc_active(c, &flags);
409409
WRITE_ONCE(c->waiting_for_gp.first, __llist_del_all(&c->free_by_rcu));
410410
c->waiting_for_gp_tail = c->free_by_rcu_tail;
411-
dec_active(c, flags);
411+
dec_active(c, &flags);
412412

413413
if (unlikely(READ_ONCE(c->draining))) {
414414
free_all(llist_del_all(&c->waiting_for_gp), !!c->percpu_size);

0 commit comments

Comments
 (0)