2021-12-14 12:51:37

by Jiasheng Jiang

[permalink] [raw]
Subject: [PATCH v2] drm: mali-dp: potential dereference of null pointer

The return value of kzalloc() needs to be checked.
To avoid use of null pointer '&state->base' in case of the
failure of alloc.

Fixes: 99665d072183 ("drm: mali-dp: add malidp_crtc_state struct")
Signed-off-by: Jiasheng Jiang <[email protected]>
Reported-by: Brian Starkey <[email protected]>
---
Changelog:

v1 -> v2

*Change 1. Add r-p.
---
drivers/gpu/drm/arm/malidp_crtc.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp_crtc.c
index 494075ddbef6..b5928b52e279 100644
--- a/drivers/gpu/drm/arm/malidp_crtc.c
+++ b/drivers/gpu/drm/arm/malidp_crtc.c
@@ -487,7 +487,10 @@ static void malidp_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
malidp_crtc_destroy_state(crtc, crtc->state);

- __drm_atomic_helper_crtc_reset(crtc, &state->base);
+ if (state)
+ __drm_atomic_helper_crtc_reset(crtc, &state->base);
+ else
+ __drm_atomic_helper_crtc_reset(crtc, NULL);
}

static int malidp_crtc_enable_vblank(struct drm_crtc *crtc)
--
2.25.1



2021-12-14 12:54:17

by Liviu Dudau

[permalink] [raw]
Subject: Re: [PATCH v2] drm: mali-dp: potential dereference of null pointer

Hi Jiasheng,

On Tue, Dec 14, 2021 at 08:51:10PM +0800, Jiasheng Jiang wrote:
> The return value of kzalloc() needs to be checked.
> To avoid use of null pointer '&state->base' in case of the
> failure of alloc.
>
> Fixes: 99665d072183 ("drm: mali-dp: add malidp_crtc_state struct")
> Signed-off-by: Jiasheng Jiang <[email protected]>
> Reported-by: Brian Starkey <[email protected]>

By R-b Brian meant "Reviewed-by" but I now can see how it can be confused with "Reported-by".

You don't have to send another version of the patch, I will add the correct tag to
your v1 when pushing it into drm-misc-next.

Best regards,
Liviu


> ---
> Changelog:
>
> v1 -> v2
>
> *Change 1. Add r-p.
> ---
> drivers/gpu/drm/arm/malidp_crtc.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp_crtc.c
> index 494075ddbef6..b5928b52e279 100644
> --- a/drivers/gpu/drm/arm/malidp_crtc.c
> +++ b/drivers/gpu/drm/arm/malidp_crtc.c
> @@ -487,7 +487,10 @@ static void malidp_crtc_reset(struct drm_crtc *crtc)
> if (crtc->state)
> malidp_crtc_destroy_state(crtc, crtc->state);
>
> - __drm_atomic_helper_crtc_reset(crtc, &state->base);
> + if (state)
> + __drm_atomic_helper_crtc_reset(crtc, &state->base);
> + else
> + __drm_atomic_helper_crtc_reset(crtc, NULL);
> }
>
> static int malidp_crtc_enable_vblank(struct drm_crtc *crtc)
> --
> 2.25.1
>

--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯