* [PATCH v2] drm/msm/mdp5: check the return of kzalloc()
@ 2022-04-07 2:31 xkernel.wang
2022-04-08 12:21 ` Dmitry Baryshkov
0 siblings, 1 reply; 2+ messages in thread
From: xkernel.wang @ 2022-04-07 2:31 UTC (permalink / raw)
To: robdclark, quic_abhinavk
Cc: sean, airlied, linux-arm-msm, linux-kernel, dri-devel,
Xiaoke Wang, freedreno
From: Xiaoke Wang <xkernel.wang@foxmail.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.
Besides, since mdp5_plane_reset() is void type, so we should better
set `plane-state` to NULL after releasing it.
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
ChangeLog:
v1->v2 simplify the patch and update the description.
drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c
index c6b69af..50e8542 100644
--- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c
+++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c
@@ -90,7 +90,10 @@ static void mdp5_plane_reset(struct drm_plane *plane)
__drm_atomic_helper_plane_destroy_state(plane->state);
kfree(to_mdp5_plane_state(plane->state));
+ plane->state = NULL;
mdp5_state = kzalloc(sizeof(*mdp5_state), GFP_KERNEL);
+ if (!mdp5_state)
+ return;
if (plane->type == DRM_PLANE_TYPE_PRIMARY)
mdp5_state->base.zpos = STAGE_BASE;
--
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] drm/msm/mdp5: check the return of kzalloc()
2022-04-07 2:31 [PATCH v2] drm/msm/mdp5: check the return of kzalloc() xkernel.wang
@ 2022-04-08 12:21 ` Dmitry Baryshkov
0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Baryshkov @ 2022-04-08 12:21 UTC (permalink / raw)
To: xkernel.wang
Cc: freedreno, airlied, linux-arm-msm, quic_abhinavk, dri-devel,
linux-kernel, sean
On Thu, 7 Apr 2022 at 05:33, <xkernel.wang@foxmail.com> wrote:
>
> From: Xiaoke Wang <xkernel.wang@foxmail.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.
>
> Besides, since mdp5_plane_reset() is void type, so we should better
> set `plane-state` to NULL after releasing it.
>
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
> ChangeLog:
> v1->v2 simplify the patch and update the description.
> drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c
> index c6b69af..50e8542 100644
> --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c
> +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c
> @@ -90,7 +90,10 @@ static void mdp5_plane_reset(struct drm_plane *plane)
> __drm_atomic_helper_plane_destroy_state(plane->state);
>
> kfree(to_mdp5_plane_state(plane->state));
> + plane->state = NULL;
> mdp5_state = kzalloc(sizeof(*mdp5_state), GFP_KERNEL);
> + if (!mdp5_state)
> + return;
>
> if (plane->type == DRM_PLANE_TYPE_PRIMARY)
> mdp5_state->base.zpos = STAGE_BASE;
> --
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-08 12:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 2:31 [PATCH v2] drm/msm/mdp5: check the return of kzalloc() xkernel.wang
2022-04-08 12:21 ` Dmitry Baryshkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).