2023-11-16 20:52:50

by Yuran Pereira

[permalink] [raw]
Subject: [PATCH] drm/nouveau: Removes unnecessary args check in nouveau_uvmm_sm_prepare

Checking `args` after calling `op_map_prepare` is unnecessary since
if `op_map_prepare` was to be called with NULL args, it would lead
to a NULL pointer dereference, thus never hitting that check.

Hence this check can be removed, and a note added to remind users of
this function to ensure that args != NULL when calling this function
for a map operation as it was suggested by Danilo [1]

[1] https://lore.kernel.org/lkml/[email protected]

Suggested-by: Danilo Krummrich <[email protected]>
Signed-off-by: Yuran Pereira <[email protected]>
---
drivers/gpu/drm/nouveau/nouveau_uvmm.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_uvmm.c b/drivers/gpu/drm/nouveau/nouveau_uvmm.c
index 5cf892c50f43..c8c3f1b1b604 100644
--- a/drivers/gpu/drm/nouveau/nouveau_uvmm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_uvmm.c
@@ -604,6 +604,10 @@ op_unmap_prepare(struct drm_gpuva_op_unmap *u)
drm_gpuva_unmap(u);
}

+/*
+ * Note: @args should not be NULL when calling for
+ * a map operation.
+ */
static int
nouveau_uvmm_sm_prepare(struct nouveau_uvmm *uvmm,
struct nouveau_uvma_prealloc *new,
@@ -624,7 +628,7 @@ nouveau_uvmm_sm_prepare(struct nouveau_uvmm *uvmm,
if (ret)
goto unwind;

- if (args && vmm_get_range) {
+ if (vmm_get_range) {
ret = nouveau_uvmm_vmm_get(uvmm, vmm_get_start,
vmm_get_range);
if (ret) {
--
2.25.1


2023-11-30 00:09:17

by Danilo Krummrich

[permalink] [raw]
Subject: Re: [PATCH] drm/nouveau: Removes unnecessary args check in nouveau_uvmm_sm_prepare

On 11/16/23 21:52, Yuran Pereira wrote:
> Checking `args` after calling `op_map_prepare` is unnecessary since
> if `op_map_prepare` was to be called with NULL args, it would lead
> to a NULL pointer dereference, thus never hitting that check.
>
> Hence this check can be removed, and a note added to remind users of
> this function to ensure that args != NULL when calling this function
> for a map operation as it was suggested by Danilo [1]
>
> [1] https://lore.kernel.org/lkml/[email protected]
>
> Suggested-by: Danilo Krummrich <[email protected]>
> Signed-off-by: Yuran Pereira <[email protected]>

Applied to drm-misc-next.

> ---
> drivers/gpu/drm/nouveau/nouveau_uvmm.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_uvmm.c b/drivers/gpu/drm/nouveau/nouveau_uvmm.c
> index 5cf892c50f43..c8c3f1b1b604 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_uvmm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_uvmm.c
> @@ -604,6 +604,10 @@ op_unmap_prepare(struct drm_gpuva_op_unmap *u)
> drm_gpuva_unmap(u);
> }
>
> +/*
> + * Note: @args should not be NULL when calling for
> + * a map operation.
> + */
> static int
> nouveau_uvmm_sm_prepare(struct nouveau_uvmm *uvmm,
> struct nouveau_uvma_prealloc *new,
> @@ -624,7 +628,7 @@ nouveau_uvmm_sm_prepare(struct nouveau_uvmm *uvmm,
> if (ret)
> goto unwind;
>
> - if (args && vmm_get_range) {
> + if (vmm_get_range) {
> ret = nouveau_uvmm_vmm_get(uvmm, vmm_get_start,
> vmm_get_range);
> if (ret) {