Skip to content

Commit b4601d0

Browse files
surenbaghdasaryanakpm00
authored andcommitted
mm/slab: fix 'variable obj_exts set but not used' warning
slab_post_alloc_hook() uses prepare_slab_obj_exts_hook() to obtain slabobj_ext object. Currently the only user of slabobj_ext object in this path is memory allocation profiling, therefore when it's not enabled this object is not needed. This also generates a warning when compiling with CONFIG_MEM_ALLOC_PROFILING=n. Move the code under this configuration to fix the warning. If more slabobj_ext users appear in the future, the code will have to be changed back to call prepare_slab_obj_exts_hook(). Link: https://lkml.kernel.org/r/[email protected] Fixes: 4b87369 ("mm/slab: add allocation accounting into slab allocation and free paths") Signed-off-by: Suren Baghdasaryan <[email protected]> Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Cc: Kent Overstreet <[email protected]> Cc: Kees Cook <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 399ab86 commit b4601d0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mm/slub.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -3902,7 +3902,6 @@ bool slab_post_alloc_hook(struct kmem_cache *s, struct list_lru *lru,
39023902
unsigned int orig_size)
39033903
{
39043904
unsigned int zero_size = s->object_size;
3905-
struct slabobj_ext *obj_exts;
39063905
bool kasan_init = init;
39073906
size_t i;
39083907
gfp_t init_flags = flags & gfp_allowed_mask;
@@ -3945,18 +3944,20 @@ bool slab_post_alloc_hook(struct kmem_cache *s, struct list_lru *lru,
39453944
kmemleak_alloc_recursive(p[i], s->object_size, 1,
39463945
s->flags, init_flags);
39473946
kmsan_slab_alloc(s, p[i], init_flags);
3947+
#ifdef CONFIG_MEM_ALLOC_PROFILING
39483948
if (need_slab_obj_ext()) {
3949+
struct slabobj_ext *obj_exts;
3950+
39493951
obj_exts = prepare_slab_obj_exts_hook(s, flags, p[i]);
3950-
#ifdef CONFIG_MEM_ALLOC_PROFILING
39513952
/*
39523953
* Currently obj_exts is used only for allocation profiling.
39533954
* If other users appear then mem_alloc_profiling_enabled()
39543955
* check should be added before alloc_tag_add().
39553956
*/
39563957
if (likely(obj_exts))
39573958
alloc_tag_add(&obj_exts->ref, current->alloc_tag, s->size);
3958-
#endif
39593959
}
3960+
#endif
39603961
}
39613962

39623963
return memcg_slab_post_alloc_hook(s, lru, flags, size, p);

0 commit comments

Comments
 (0)