FROMGIT: mm: slub: fix the leak of alloc/free traces debugfs interface

Fix the leak of alloc/free traces debugfs interface, reported by kmemleak
like below,

unreferenced object 0xffff00091ae1b540 (size 64):
  comm "lsbug", pid 1607, jiffies 4294958291 (age 1476.340s)
  hex dump (first 32 bytes):
    02 00 00 00 00 00 00 00 6b 6b 6b 6b 6b 6b 6b 6b  ........kkkkkkkk
    6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
  backtrace:
    [<ffff8000106b06b8>] slab_post_alloc_hook+0xa0/0x418
    [<ffff8000106b5c7c>] kmem_cache_alloc_trace+0x1e4/0x378
    [<ffff8000106b5e40>] slab_debugfs_start+0x30/0x50
    slab_debugfs_start at mm/slub.c:5831
    [<ffff8000107b3dbc>] seq_read_iter+0x214/0xd50
    [<ffff8000107b4b84>] seq_read+0x28c/0x418
    [<ffff8000109560b4>] full_proxy_read+0xdc/0x148
    [<ffff800010738f24>] vfs_read+0x104/0x340
    [<ffff800010739ee0>] ksys_read+0xf8/0x1e0
    [<ffff80001073a03c>] __arm64_sys_read+0x74/0xa8

Link: https://lkml.kernel.org/r/1624248060-30286-1-git-send-email-faiyazm@codeaurora.org
Fixes: 3589836402ca ("mm: slub: move sysfs slab alloc/free interfaces to debugfs")
Link: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/mm/slub.c?h=next-20210617&id=84a2bdb1b458fc968d6d9e07dab388dc679bd747
Signed-off-by: Faiyaz Mohammed <faiyazm@codeaurora.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
BUG: 176858818
(cherry picked from commit 29d055e7966b5beae75db7980df78f99344f74ae
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/mm/slub.c?h=next-20210624&id=29d055e7966b5beae75db7980df78f99344f74ae)

Change-Id: I26fd4285b3e8f2a48f7c1320adceb0208e0fbc45
Signed-off-by: Faiyaz Mohammed <faiyazm@codeaurora.org>
This commit is contained in:
Faiyaz Mohammed
2021-06-23 10:50:06 +05:30
committed by Suren Baghdasaryan
parent 850f11aa85
commit b007e43692

View File

@@ -5749,31 +5749,23 @@ static int slab_debugfs_show(struct seq_file *seq, void *v)
static void slab_debugfs_stop(struct seq_file *seq, void *v) static void slab_debugfs_stop(struct seq_file *seq, void *v)
{ {
kfree(v);
} }
static void *slab_debugfs_next(struct seq_file *seq, void *v, loff_t *ppos) static void *slab_debugfs_next(struct seq_file *seq, void *v, loff_t *ppos)
{ {
loff_t *spos = v;
struct loc_track *t = seq->private; struct loc_track *t = seq->private;
if (*ppos < t->count) { v = ppos;
*ppos = ++*spos; ++*ppos;
return spos; if (*ppos <= t->count)
} return v;
*ppos = ++*spos;
return NULL; return NULL;
} }
static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos) static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos)
{ {
loff_t *spos = kmalloc(sizeof(loff_t), GFP_KERNEL); return ppos;
if (!spos)
return NULL;
*spos = *ppos;
return spos;
} }
static const struct seq_operations slab_debugfs_sops = { static const struct seq_operations slab_debugfs_sops = {