From: Rob Clark <robdclark@gmail.com> To: xkernel.wang@foxmail.com Cc: Sean Paul <sean@poorly.run>, David Airlie <airlied@linux.ie>, linux-arm-msm <linux-arm-msm@vger.kernel.org>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, dri-devel <dri-devel@lists.freedesktop.org>, freedreno <freedreno@lists.freedesktop.org> Subject: Re: [PATCH] drm/msm/mdp5: check the return of kzalloc() Date: Wed, 6 Apr 2022 09:24:22 -0700 [thread overview] Message-ID: <CAF6AEGu+Sg79Sn=t=-3b9ZbDanN7KeSzUX+-rchd8SY+b+sUsg@mail.gmail.com> (raw) In-Reply-To: <tencent_F71D40EE9851737338A6289EC3A3942EFE09@qq.com> On Thu, Mar 24, 2022 at 1:37 AM <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. > > Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.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; At this point, you could just: if (!mdp5_state) return; BR, -R > > - 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 * > --
WARNING: multiple messages have this Message-ID (diff)
From: Rob Clark <robdclark@gmail.com> To: xkernel.wang@foxmail.com Cc: Sean Paul <sean@poorly.run>, David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>, linux-arm-msm <linux-arm-msm@vger.kernel.org>, dri-devel <dri-devel@lists.freedesktop.org>, freedreno <freedreno@lists.freedesktop.org>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org> Subject: Re: [PATCH] drm/msm/mdp5: check the return of kzalloc() Date: Wed, 6 Apr 2022 09:24:22 -0700 [thread overview] Message-ID: <CAF6AEGu+Sg79Sn=t=-3b9ZbDanN7KeSzUX+-rchd8SY+b+sUsg@mail.gmail.com> (raw) In-Reply-To: <tencent_F71D40EE9851737338A6289EC3A3942EFE09@qq.com> On Thu, Mar 24, 2022 at 1:37 AM <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. > > Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.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; At this point, you could just: if (!mdp5_state) return; BR, -R > > - 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 * > --
next prev parent reply other threads:[~2022-04-06 16:23 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-24 8:36 [PATCH] drm/msm/mdp5: check the return of kzalloc() xkernel.wang 2022-03-24 8:36 ` xkernel.wang 2022-03-24 17:58 ` Abhinav Kumar 2022-03-24 17:58 ` Abhinav Kumar 2022-04-06 16:24 ` Rob Clark [this message] 2022-04-06 16:24 ` Rob Clark
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CAF6AEGu+Sg79Sn=t=-3b9ZbDanN7KeSzUX+-rchd8SY+b+sUsg@mail.gmail.com' \ --to=robdclark@gmail.com \ --cc=airlied@linux.ie \ --cc=dri-devel@lists.freedesktop.org \ --cc=freedreno@lists.freedesktop.org \ --cc=linux-arm-msm@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=sean@poorly.run \ --cc=xkernel.wang@foxmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.