Skip to content

Commit 2e1483c

Browse files
committed
kmemleak: Remove some of the kmemleak false positives
There are allocations for which the main pointer cannot be found but they are not memory leaks. This patch fixes some of them. For more information on false positives, see Documentation/kmemleak.txt. Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 4f2294b commit 2e1483c

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎drivers/char/vt.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
#include <linux/io.h>
105105
#include <asm/system.h>
106106
#include <linux/uaccess.h>
107+
#include <linux/kmemleak.h>
107108

108109
#define MAX_NR_CON_DRIVER 16
109110

@@ -2880,6 +2881,12 @@ static int __init con_init(void)
28802881
*/
28812882
for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {
28822883
vc_cons[currcons].d = vc = alloc_bootmem(sizeof(struct vc_data));
2884+
/*
2885+
* Kmemleak does not track the memory allocated via
2886+
* alloc_bootmem() but this block contains pointers to
2887+
* other blocks allocated via kmalloc.
2888+
*/
2889+
kmemleak_alloc(vc, sizeof(struct vc_data), 1, GFP_ATOMIC);
28832890
INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK);
28842891
visual_init(vc, currcons, 1);
28852892
vc->vc_screenbuf = (unsigned short *)alloc_bootmem(vc->vc_screenbuf_size);

‎fs/block_dev.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/uio.h>
2626
#include <linux/namei.h>
2727
#include <linux/log2.h>
28+
#include <linux/kmemleak.h>
2829
#include <asm/uaccess.h>
2930
#include "internal.h"
3031

@@ -492,6 +493,11 @@ void __init bdev_cache_init(void)
492493
bd_mnt = kern_mount(&bd_type);
493494
if (IS_ERR(bd_mnt))
494495
panic("Cannot create bdev pseudo-fs");
496+
/*
497+
* This vfsmount structure is only used to obtain the
498+
* blockdev_superblock, so tell kmemleak not to report it.
499+
*/
500+
kmemleak_not_leak(bd_mnt);
495501
blockdev_superblock = bd_mnt->mnt_sb; /* For writeback */
496502
}
497503

‎include/linux/percpu.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ struct percpu_data {
8686
void *ptrs[1];
8787
};
8888

89+
/* pointer disguising messes up the kmemleak objects tracking */
90+
#ifndef CONFIG_DEBUG_KMEMLEAK
8991
#define __percpu_disguise(pdata) (struct percpu_data *)~(unsigned long)(pdata)
92+
#else
93+
#define __percpu_disguise(pdata) (struct percpu_data *)(pdata)
94+
#endif
9095

9196
#define per_cpu_ptr(ptr, cpu) \
9297
({ \

0 commit comments

Comments
 (0)