All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Paul Cercueil <paul@crapouillou.net>
Cc: David Airlie <airlied@linux.ie>, Sam Ravnborg <sam@ravnborg.org>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	od@zcrc.me, dri-devel <dri-devel@lists.freedesktop.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	stable <stable@vger.kernel.org>
Subject: Re: [PATCH v2 2/3] drm/ingenic: Register devm action to cleanup encoders
Date: Wed, 20 Jan 2021 15:04:59 +0100	[thread overview]
Message-ID: <CAKMK7uEu7vWcJFC6S_hmKB4UMwPocwiOEy1iFnftOs5zfsRNYQ@mail.gmail.com> (raw)
In-Reply-To: <TFI8NQ.468S4PLHPA963@crapouillou.net>

On Wed, Jan 20, 2021 at 2:21 PM Paul Cercueil <paul@crapouillou.net> wrote:
>
>
>
> Le mer. 20 janv. 2021 à 14:01, Daniel Vetter <daniel@ffwll.ch> a
> écrit :
> > On Wed, Jan 20, 2021 at 1:36 PM Paul Cercueil <paul@crapouillou.net>
> > wrote:
> >>
> >>  Since the encoders have been devm-allocated, they will be freed way
> >>  before drm_mode_config_cleanup() is called. To avoid use-after-free
> >>  conditions, we then must ensure that drm_encoder_cleanup() is called
> >>  before the encoders are freed.
> >>
> >>  v2: Use the new __drmm_simple_encoder_alloc() function
> >>
> >>  Fixes: c369cb27c267 ("drm/ingenic: Support multiple panels/bridges")
> >>  Cc: <stable@vger.kernel.org> # 5.8+
> >>  Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> >>  ---
> >>
> >>  Notes:
> >>      Use the V1 of this patch to fix v5.11 and older kernels. This
> >> V2 only
> >>      applies on the current drm-misc-next branch.
> >>
> >>   drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 16 +++++++---------
> >>   1 file changed, 7 insertions(+), 9 deletions(-)
> >>
> >>  diff --git a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> >> b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> >>  index 7bb31fbee29d..158433b4c084 100644
> >>  --- a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> >>  +++ b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> >>  @@ -1014,20 +1014,18 @@ static int ingenic_drm_bind(struct device
> >> *dev, bool has_components)
> >>                          bridge =
> >> devm_drm_panel_bridge_add_typed(dev, panel,
> >>
> >> DRM_MODE_CONNECTOR_DPI);
> >>
> >>  -               encoder = devm_kzalloc(dev, sizeof(*encoder),
> >> GFP_KERNEL);
> >>  -               if (!encoder)
> >>  -                       return -ENOMEM;
> >>  +               encoder = __drmm_simple_encoder_alloc(drm,
> >> sizeof(*encoder), 0,
> >
> > Please don't use the __ prefixed functions, those are the internal
> > ones. The official one comes with type checking and all that included.
> > Otherwise lgtm.
> > -Daniel
>
> The non-prefixed one assumes that I want to allocate a struct that
> contains the encoder, not just the drm_encoder itself.

Hm, but using the internal one is also a bit too ugly. A
drm_plain_simple_enocder_alloc(drm, type) wrapper would be the right
thing here I think? Setting the offsets and struct sizes directly in
these in drivers really doesn't feel like a good idea. I think simple
encoder is the only case where we really have a need for a
non-embeddable struct.
-Daniel

>
> -Paul
>
> >>  +
> >> DRM_MODE_ENCODER_DPI);
> >>  +               if (IS_ERR(encoder)) {
> >>  +                       ret = PTR_ERR(encoder);
> >>  +                       dev_err(dev, "Failed to init encoder:
> >> %d\n", ret);
> >>  +                       return ret;
> >>  +               }
> >>
> >>                  encoder->possible_crtcs = 1;
> >>
> >>                  drm_encoder_helper_add(encoder,
> >> &ingenic_drm_encoder_helper_funcs);
> >>
> >>  -               ret = drm_simple_encoder_init(drm, encoder,
> >> DRM_MODE_ENCODER_DPI);
> >>  -               if (ret) {
> >>  -                       dev_err(dev, "Failed to init encoder:
> >> %d\n", ret);
> >>  -                       return ret;
> >>  -               }
> >>  -
> >>                  ret = drm_bridge_attach(encoder, bridge, NULL, 0);
> >>                  if (ret) {
> >>                          dev_err(dev, "Unable to attach bridge\n");
> >>  --
> >>  2.29.2
> >>
> >
> >
> > --
> > Daniel Vetter
> > Software Engineer, Intel Corporation
> > http://blog.ffwll.ch
>
>


-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Vetter <daniel@ffwll.ch>
To: Paul Cercueil <paul@crapouillou.net>
Cc: David Airlie <airlied@linux.ie>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	od@zcrc.me, Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	stable <stable@vger.kernel.org>, Sam Ravnborg <sam@ravnborg.org>
Subject: Re: [PATCH v2 2/3] drm/ingenic: Register devm action to cleanup encoders
Date: Wed, 20 Jan 2021 15:04:59 +0100	[thread overview]
Message-ID: <CAKMK7uEu7vWcJFC6S_hmKB4UMwPocwiOEy1iFnftOs5zfsRNYQ@mail.gmail.com> (raw)
In-Reply-To: <TFI8NQ.468S4PLHPA963@crapouillou.net>

On Wed, Jan 20, 2021 at 2:21 PM Paul Cercueil <paul@crapouillou.net> wrote:
>
>
>
> Le mer. 20 janv. 2021 à 14:01, Daniel Vetter <daniel@ffwll.ch> a
> écrit :
> > On Wed, Jan 20, 2021 at 1:36 PM Paul Cercueil <paul@crapouillou.net>
> > wrote:
> >>
> >>  Since the encoders have been devm-allocated, they will be freed way
> >>  before drm_mode_config_cleanup() is called. To avoid use-after-free
> >>  conditions, we then must ensure that drm_encoder_cleanup() is called
> >>  before the encoders are freed.
> >>
> >>  v2: Use the new __drmm_simple_encoder_alloc() function
> >>
> >>  Fixes: c369cb27c267 ("drm/ingenic: Support multiple panels/bridges")
> >>  Cc: <stable@vger.kernel.org> # 5.8+
> >>  Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> >>  ---
> >>
> >>  Notes:
> >>      Use the V1 of this patch to fix v5.11 and older kernels. This
> >> V2 only
> >>      applies on the current drm-misc-next branch.
> >>
> >>   drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 16 +++++++---------
> >>   1 file changed, 7 insertions(+), 9 deletions(-)
> >>
> >>  diff --git a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> >> b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> >>  index 7bb31fbee29d..158433b4c084 100644
> >>  --- a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> >>  +++ b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> >>  @@ -1014,20 +1014,18 @@ static int ingenic_drm_bind(struct device
> >> *dev, bool has_components)
> >>                          bridge =
> >> devm_drm_panel_bridge_add_typed(dev, panel,
> >>
> >> DRM_MODE_CONNECTOR_DPI);
> >>
> >>  -               encoder = devm_kzalloc(dev, sizeof(*encoder),
> >> GFP_KERNEL);
> >>  -               if (!encoder)
> >>  -                       return -ENOMEM;
> >>  +               encoder = __drmm_simple_encoder_alloc(drm,
> >> sizeof(*encoder), 0,
> >
> > Please don't use the __ prefixed functions, those are the internal
> > ones. The official one comes with type checking and all that included.
> > Otherwise lgtm.
> > -Daniel
>
> The non-prefixed one assumes that I want to allocate a struct that
> contains the encoder, not just the drm_encoder itself.

Hm, but using the internal one is also a bit too ugly. A
drm_plain_simple_enocder_alloc(drm, type) wrapper would be the right
thing here I think? Setting the offsets and struct sizes directly in
these in drivers really doesn't feel like a good idea. I think simple
encoder is the only case where we really have a need for a
non-embeddable struct.
-Daniel

>
> -Paul
>
> >>  +
> >> DRM_MODE_ENCODER_DPI);
> >>  +               if (IS_ERR(encoder)) {
> >>  +                       ret = PTR_ERR(encoder);
> >>  +                       dev_err(dev, "Failed to init encoder:
> >> %d\n", ret);
> >>  +                       return ret;
> >>  +               }
> >>
> >>                  encoder->possible_crtcs = 1;
> >>
> >>                  drm_encoder_helper_add(encoder,
> >> &ingenic_drm_encoder_helper_funcs);
> >>
> >>  -               ret = drm_simple_encoder_init(drm, encoder,
> >> DRM_MODE_ENCODER_DPI);
> >>  -               if (ret) {
> >>  -                       dev_err(dev, "Failed to init encoder:
> >> %d\n", ret);
> >>  -                       return ret;
> >>  -               }
> >>  -
> >>                  ret = drm_bridge_attach(encoder, bridge, NULL, 0);
> >>                  if (ret) {
> >>                          dev_err(dev, "Unable to attach bridge\n");
> >>  --
> >>  2.29.2
> >>
> >
> >
> > --
> > Daniel Vetter
> > Software Engineer, Intel Corporation
> > http://blog.ffwll.ch
>
>


-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2021-01-20 20:10 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 12:35 [PATCH v2 0/3] Fixes to bridge/panel and ingenic-drm Paul Cercueil
2021-01-20 12:35 ` Paul Cercueil
2021-01-20 12:35 ` [PATCH v2 1/3] drm: bridge/panel: Cleanup connector on bridge detach Paul Cercueil
2021-01-20 12:35   ` Paul Cercueil
2021-01-20 16:03   ` Daniel Vetter
2021-01-20 16:03     ` Daniel Vetter
2021-01-20 16:25     ` Paul Cercueil
2021-01-20 16:25       ` Paul Cercueil
2021-01-20 17:38       ` Daniel Vetter
2021-01-20 17:38         ` Daniel Vetter
2021-03-24  2:15         ` Laurent Pinchart
2021-03-24  2:15           ` Laurent Pinchart
2021-03-24  9:39           ` Daniel Vetter
2021-03-24  9:39             ` Daniel Vetter
2021-03-24  9:46             ` Laurent Pinchart
2021-03-24  9:46               ` Laurent Pinchart
2021-01-20 12:35 ` [PATCH v2 2/3] drm/ingenic: Register devm action to cleanup encoders Paul Cercueil
2021-01-20 12:35   ` Paul Cercueil
2021-01-20 13:01   ` Daniel Vetter
2021-01-20 13:01     ` Daniel Vetter
2021-01-20 13:21     ` Paul Cercueil
2021-01-20 13:21       ` Paul Cercueil
2021-01-20 14:04       ` Daniel Vetter [this message]
2021-01-20 14:04         ` Daniel Vetter
2021-01-20 15:55         ` Paul Cercueil
2021-01-20 15:55           ` Paul Cercueil
2021-01-20 12:35 ` [PATCH v2 3/3] drm/ingenic: Fix non-OSD mode Paul Cercueil
2021-01-20 12:35   ` Paul Cercueil
2021-01-20 16:26   ` Daniel Vetter
2021-01-20 16:26     ` Daniel Vetter

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=CAKMK7uEu7vWcJFC6S_hmKB4UMwPocwiOEy1iFnftOs5zfsRNYQ@mail.gmail.com \
    --to=daniel@ffwll.ch \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=od@zcrc.me \
    --cc=paul@crapouillou.net \
    --cc=sam@ravnborg.org \
    --cc=stable@vger.kernel.org \
    /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: link
Be 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.