Skip to contentSkip to conversation

lib/test_hmm: use kvfree() to free kvcalloc() allocations

PATCH Applied Hao Ge 2 participants 2 messages May 13

Subsystems (3)
lore
Share & tools
lore

Hao Ge

author
#0 lore raw

PATCH 1/1 lib/test_hmm: use kvfree() to free kvcalloc() allocations

Coccinelle scripts/coccinelle/api/kfree_mismatch.cocci reports the following warnings:

lib/test_hmm.c:1256:15-16: WARNING kvmalloc is used to allocate this memory at line 1191 lib/test_hmm.c:1257:15-16: WARNING kvmalloc is used to allocate this memory at line 1196

Fix this by replacing kfree() with kvfree() to correctly handle the vmalloc() fallback path of kvcalloc().

Fixes 775465fd26a3 ("lib/test_hmm: add zone device private THP test infrastructure")
---
 lib/test_hmm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/test_hmm.c +2 -2
index 213504915737..38996c4baa40 100644
@@ -1253,8 +1253,8 @@ static int dmirror_migrate_to_device(struct dmirror *dmirror,
 	mmap_read_unlock(mm);
 	mmput(mm);
 free_mem:
-	kfree(src_pfns);
-	kfree(dst_pfns);
+	kvfree(src_pfns);
+	kvfree(dst_pfns);
 	return ret;
 }
 
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · Hao Ge

Coccinelle scripts/coccinelle/api/kfree_mismatch.cocci reports the following warnings:

lib/test_hmm.c:1256:15-16: WARNING kvmalloc is used to allocate this memory at line 1191 lib/test_hmm.c:1257:15-16: WARNING kvmalloc is used to allocate this memory at line 1196

Fix this by replacing kfree() with kvfree() to correctly handle the vmalloc() fallback path of kvcalloc().

Fixes 775465fd26a3 ("lib/test_hmm: add zone device private THP test infrastructure")
---
 lib/test_hmm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/test_hmm.c +0 -0
index 213504915737..38996c4baa40 100644

lib/test_hmm.c static int dmirror_migrate_to_device(struct dmirror *dmirror, · line 1260

Quoted 10 lines
lib/test_hmm.c +2 -2
@@ -1253,8 +1253,8 @@ static int dmirror_migrate_to_device(struct dmirror *dmirror,
 	mmap_read_unlock(mm);
 	mmput(mm);
 free_mem:
-	kfree(src_pfns);
-	kfree(dst_pfns);
+	kvfree(src_pfns);
+	kvfree(dst_pfns);
 	return ret;
 }
 

Yep. makes sense!

Thanks!
Balbir