Skip to contentSkip to conversation

mm: kmemleak: small cleanup

PATCH Applied Luiz Capitulino 3 participants 8 messages Apr 30, 2025 – May 1, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mm: kmemleak: small cleanup

Hi,

This is a trivial mm/kmemleak.c cleanup. I found these while reading through the code.

Luiz Capitulino (3):
mm: kmemleak: drop kmemleak_warning variable
mm: kmemleak: drop wrong comment
mm: kmemleak: mark variables as __read_mostly

 mm/kmemleak.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/3 mm: kmemleak: drop kmemleak_warning variable

The kmemleak_warning variable is not used since commit c5665868183f ("mm:
kmemleak: use the memory pool for early allocations"), drop it.

---
 mm/kmemleak.c | 3 ---
 1 file changed, 3 deletions(-)
mm/kmemleak.c +0 -3
index c12cef3eeb32..e6df94c7b032 100644
@@ -215,8 +215,6 @@ static int kmemleak_enabled = 1;
 static int kmemleak_free_enabled = 1;
 /* set in the late_initcall if there were no errors */
 static int kmemleak_late_initialized;
-/* set if a kmemleak warning was issued */
-static int kmemleak_warning;
 /* set if a fatal kmemleak error has occurred */
 static int kmemleak_error;
 
@@ -254,7 +252,6 @@ static void kmemleak_disable(void);
 #define kmemleak_warn(x...)	do {		\
 	pr_warn(x);				\
 	dump_stack();				\
-	kmemleak_warning = 1;			\
 } while (0)
 
 /*
Signature · 1 line
2.49.0
#3 lore raw

PATCH 2/3 mm: kmemleak: drop wrong comment

In reply to Luiz Capitulino

Newly created objects have object->count == 0, so the comment is incorrect. Just drop it.

---
 mm/kmemleak.c | 2 --
 1 file changed, 2 deletions(-)
mm/kmemleak.c +0 -2
index e6df94c7b032..06baa3475252 100644
@@ -322,8 +322,6 @@ static void hex_dump_object(struct seq_file *seq,
  *		sufficient references to it (count >= min_count)
  * - black - ignore, it doesn't contain references (e.g. text section)
  *		(min_count == -1). No function defined for this color.
- * Newly created objects don't have any color assigned (object->count == -1)
- * before the next memory scan when they become white.
  */
 static bool color_white(const struct kmemleak_object *object)
 {
Signature · 1 line
2.49.0
#5 lore raw

PATCH 3/3 mm: kmemleak: mark variables as __read_mostly

In reply to Luiz Capitulino

The variables kmemleak_enabled and kmemleak_free_enabled are read in the kmemleak alloc and free path respectively, but are only written to if/when kmemleak is disabled.

---
 mm/kmemleak.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/kmemleak.c +2 -2
index 06baa3475252..da9cee34ee1b 100644
@@ -210,9 +210,9 @@ static struct kmem_cache *object_cache;
 static struct kmem_cache *scan_area_cache;
 
 /* set if tracing memory operations is enabled */
-static int kmemleak_enabled = 1;
+static int kmemleak_enabled __read_mostly = 1;
 /* same as above but only for the kmemleak_free() callback */
-static int kmemleak_free_enabled = 1;
+static int kmemleak_free_enabled __read_mostly = 1;
 /* set in the late_initcall if there were no errors */
 static int kmemleak_late_initialized;
 /* set if a fatal kmemleak error has occurred */
Signature · 1 line
2.49.0
Acked-by on the v1 series
#7 lore raw
In reply to Luiz Capitulino
Quoted 5 lines · Luiz Capitulino

Hi,

This is a trivial mm/kmemleak.c cleanup. I found these while reading through the code.

Quoted 8 lines

Luiz Capitulino (3):
mm: kmemleak: drop kmemleak_warning variable
mm: kmemleak: drop wrong comment
mm: kmemleak: mark variables as __read_mostly

  mm/kmemleak.c | 9 ++-------
  1 file changed, 2 insertions(+), 7 deletions(-)

For the series

Thanks Luiz!

Signature · 3 lines
Cheers,

David / dhildenb