drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
The error paths in reserve_gtt_with_resource() and
insert_gtt_with_resource() use kfree() to release a vma_res object
that was allocated with i915_vma_resource_alloc().
While kfree() can handle slab-allocated objects, it is better practice
to use the symmetric free function.
Replace kfree() with the specific i915_vma_resource_free() helper to
improve readability and ensure the alloc/free pairing is explicit.
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
Changes in v2:
- Reword commit message to describe this as a readability change.
- Drop the Fixes tag.
---
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
index 7ab4c4e60264..16e72ef57bed 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
@@ -1524,7 +1524,7 @@ static int reserve_gtt_with_resource(struct i915_vma *vma, u64 offset)
i915_vma_resource_init_from_vma(vma_res, vma);
vma->resource = vma_res;
} else {
- kfree(vma_res);
+ i915_vma_resource_free(vma_res);
}
mutex_unlock(&vm->mutex);
@@ -1704,7 +1704,7 @@ static int insert_gtt_with_resource(struct i915_vma *vma)
i915_vma_resource_init_from_vma(vma_res, vma);
vma->resource = vma_res;
} else {
- kfree(vma_res);
+ i915_vma_resource_free(vma_res);
}
mutex_unlock(&vm->mutex);
--
2.34.1
Hi Zilin, On Thu, Nov 13, 2025 at 06:34:05AM +0000, Zilin Guan wrote: > The error paths in reserve_gtt_with_resource() and > insert_gtt_with_resource() use kfree() to release a vma_res object > that was allocated with i915_vma_resource_alloc(). > > While kfree() can handle slab-allocated objects, it is better practice > to use the symmetric free function. > > Replace kfree() with the specific i915_vma_resource_free() helper to > improve readability and ensure the alloc/free pairing is explicit. > > Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Thanks for your patch, Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> Andi
Hi Zilin,
Thanks for addressing my comments.
> The error paths in reserve_gtt_with_resource() and
> insert_gtt_with_resource() use kfree() to release a vma_res object
> that was allocated with i915_vma_resource_alloc().
>
> While kfree() can handle slab-allocated objects, it is better practice
> to use the symmetric free function.
>
> Replace kfree() with the specific i915_vma_resource_free() helper to
> improve readability and ensure the alloc/free pairing is explicit.
>
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
> ---
> Changes in v2:
> - Reword commit message to describe this as a readability change.
> - Drop the Fixes tag.
> ---
> drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> index 7ab4c4e60264..16e72ef57bed 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> @@ -1524,7 +1524,7 @@ static int reserve_gtt_with_resource(struct i915_vma *vma, u64 offset)
> i915_vma_resource_init_from_vma(vma_res, vma);
> vma->resource = vma_res;
> } else {
> - kfree(vma_res);
> + i915_vma_resource_free(vma_res);
> }
> mutex_unlock(&vm->mutex);
>
> @@ -1704,7 +1704,7 @@ static int insert_gtt_with_resource(struct i915_vma *vma)
> i915_vma_resource_init_from_vma(vma_res, vma);
> vma->resource = vma_res;
> } else {
> - kfree(vma_res);
> + i915_vma_resource_free(vma_res);
> }
> mutex_unlock(&vm->mutex);
>
> --
> 2.34.1
>
Reviewed-by: Krzysztof Karas <krzysztof.karas@intel.com>
--
Best Regards,
Krzysztof
© 2016 - 2025 Red Hat, Inc.