[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4a23c6a6-737a-c910-588b-8d4827d9560c@quicinc.com>
Date: Thu, 24 Mar 2022 10:58:17 -0700
From: Abhinav Kumar <quic_abhinavk@...cinc.com>
To: <xkernel.wang@...mail.com>, <robdclark@...il.com>,
<sean@...rly.run>, <airlied@...ux.ie>, <daniel@...ll.ch>
CC: <linux-arm-msm@...r.kernel.org>, <freedreno@...ts.freedesktop.org>,
<linux-kernel@...r.kernel.org>, <dri-devel@...ts.freedesktop.org>
Subject: Re: [PATCH] drm/msm/mdp5: check the return of kzalloc()
On 3/24/2022 1:36 AM, xkernel.wang@...mail.com wrote:
> From: Xiaoke Wang <xkernel.wang@...mail.com>
>
> kzalloc() is a memory allocation function which can return NULL when
> some internal memory errors happen. So it is better to check it to
> prevent potential wrong memory access.
>
> Signed-off-by: Xiaoke Wang <xkernel.wang@...mail.com>
Reviewed-by: Abhinav Kumar <quic_abhinavk@...cinc.com>
> ---
> drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c
> index c6b69af..5f914cc 100644
> --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c
> +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c
> @@ -90,15 +90,18 @@ static void mdp5_plane_reset(struct drm_plane *plane)
> __drm_atomic_helper_plane_destroy_state(plane->state);
>
> kfree(to_mdp5_plane_state(plane->state));
> - mdp5_state = kzalloc(sizeof(*mdp5_state), GFP_KERNEL);
> + plane->state = NULL;
>
> - if (plane->type == DRM_PLANE_TYPE_PRIMARY)
> - mdp5_state->base.zpos = STAGE_BASE;
> - else
> - mdp5_state->base.zpos = STAGE0 + drm_plane_index(plane);
> - mdp5_state->base.normalized_zpos = mdp5_state->base.zpos;
> + mdp5_state = kzalloc(sizeof(*mdp5_state), GFP_KERNEL);
> + if (mdp5_state) {
> + if (plane->type == DRM_PLANE_TYPE_PRIMARY)
> + mdp5_state->base.zpos = STAGE_BASE;
> + else
> + mdp5_state->base.zpos = STAGE0 + drm_plane_index(plane);
> + mdp5_state->base.normalized_zpos = mdp5_state->base.zpos;
>
> - __drm_atomic_helper_plane_reset(plane, &mdp5_state->base);
> + __drm_atomic_helper_plane_reset(plane, &mdp5_state->base);
> + }
> }
>
> static struct drm_plane_state *
Powered by blists - more mailing lists