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

Hao Ge posted 1 patch 1 month ago
lib/test_hmm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] lib/test_hmm: use kvfree() to free kvcalloc() allocations
Posted by Hao Ge 1 month ago
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")
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
 lib/test_hmm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/test_hmm.c b/lib/test_hmm.c
index 213504915737..38996c4baa40 100644
--- a/lib/test_hmm.c
+++ b/lib/test_hmm.c
@@ -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;
 }
 
-- 
2.25.1
Re: [PATCH] lib/test_hmm: use kvfree() to free kvcalloc() allocations
Posted by Balbir Singh 1 month ago
On 5/13/26 18:25, Hao Ge wrote:
> 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")
> Signed-off-by: Hao Ge <hao.ge@linux.dev>
> ---
>  lib/test_hmm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/test_hmm.c b/lib/test_hmm.c
> index 213504915737..38996c4baa40 100644
> --- a/lib/test_hmm.c
> +++ b/lib/test_hmm.c
> @@ -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!

Acked-by: Balbir Singh <balbirs@nvidia.com>

Thanks!
Balbir