Skip to contentSkip to conversation

common/rc: cleanup old .kmemleak files

PATCH In review Luís Henriques 2 participants 2 messages Jul 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 common/rc: cleanup old .kmemleak files

I've spent a non-negligible amount of time looking into a kmemleak that didn't exist in the code I was testing because there was an old .kmemleak file in the results directory. I don't think this is an intended behaviour, so I'm proposing to remove these files everytime we capture the result of a new scan.

---
 common/rc | 4 ++++
 1 file changed, 4 insertions(+)

Changes since v2:
Incorporated comment from Darrick to explain the usage of '-f' in the test

Changes since v1:
I realised that _capture_kmemleak() is called with /dev/null as argument, so this version is probably better.

common/rc +4 -0
index 741579af82d2..5c4429ed0425 100644
@@ -4433,6 +4433,10 @@ _capture_kmemleak()
 	local kern_knob="$DEBUGFS_MNT/kmemleak"
 	local leak_file="$1"
 
+	# Some callers pass in /dev/null when they want to clear the
+	# kernel's leak report file and do not care what was in that.
+	[ -f "$leak_file" ] && rm -f "$leak_file"
+
 	# Tell the kernel to scan for memory leaks.  Apparently the write
 	# returns before the scan is complete, so do it twice in the hopes
 	# that twice is enough to capture all the leaks.
Reviewed-by on v3 1/1
#1 lore raw
Quoted 7 lines · Luís Henriques

I've spent a non-negligible amount of time looking into a kmemleak that didn't exist in the code I was testing because there was an old .kmemleak file in the results directory. I don't think this is an intended behaviour, so I'm proposing to remove these files everytime we capture the result of a new scan.

Looks good now,

--D

Quoted 26 lines
---
 common/rc | 4 ++++
 1 file changed, 4 insertions(+)

Changes since v2:
Incorporated comment from Darrick to explain the usage of '-f' in the test

Changes since v1:
I realised that _capture_kmemleak() is called with /dev/null as argument, so this version is probably better.

common/rc +4 -0
index 741579af82d2..5c4429ed0425 100644
@@ -4433,6 +4433,10 @@ _capture_kmemleak()
 	local kern_knob="$DEBUGFS_MNT/kmemleak"
 	local leak_file="$1"
 
+	# Some callers pass in /dev/null when they want to clear the
+	# kernel's leak report file and do not care what was in that.
+	[ -f "$leak_file" ] && rm -f "$leak_file"
+
 	# Tell the kernel to scan for memory leaks.  Apparently the write
 	# returns before the scan is complete, so do it twice in the hopes
 	# that twice is enough to capture all the leaks.