dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Melissa Wen <melissa.srw@gmail.com>
Cc: Rob Clark <robdclark@chromium.org>,
	Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	Chris Wilson <chris@chris-wilson.co.uk>,
	Sean Paul <seanpaul@chromium.org>,
	Sam Ravnborg <sam@ravnborg.org>,
	Emil Velikov <emil.velikov@collabora.com>
Subject: Re: [PATCH 04/24] drm/vgem: Use devm_drm_dev_alloc
Date: Wed, 9 Sep 2020 13:20:54 +0200	[thread overview]
Message-ID: <CAKMK7uFJ3Yf-rnb5VAYj1xF2VZmoY+yt+zWyRcaMLU0t6eCyoA@mail.gmail.com> (raw)
In-Reply-To: <20200909110144.pyptgix7y7yftuxy@smtp.gmail.com>

On Wed, Sep 9, 2020 at 1:01 PM Melissa Wen <melissa.srw@gmail.com> wrote:
>
> Hi Daniel,
>
> looks good to me, just a few things inline.
>
> On 09/04, Daniel Vetter wrote:
> > This means we also need to slightly restructure the exit code, so that
> > final cleanup of the drm_device is triggered by unregistering the
> > platform device. Note that devres is both clean up when the driver is
> > unbound (not the case for vgem, we don't bind), and also when unregistering
> > the device (very much the case for vgem). Therefore we can rely on devres
> > even though vgem isn't a proper platform device driver.
> >
> > This also somewhat untangles the load code, since the drm and platform device
> > setup are no longer interleaved, but two distinct steps.
> >
> > v2: use devres_open/release_group so we can use devm without real
> > hacks in the driver core or having to create an entire fake bus for
> > testing drivers. Might want to extract this into helpers eventually,
> > maybe as a mock_drm_dev_alloc or test_drm_dev_alloc.
> >
> > Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Cc: Emil Velikov <emil.velikov@collabora.com>
> > Cc: Sean Paul <seanpaul@chromium.org>
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Sam Ravnborg <sam@ravnborg.org>
> > Cc: Rob Clark <robdclark@chromium.org>
> > ---
> >  drivers/gpu/drm/vgem/vgem_drv.c | 55 ++++++++++++++-------------------
> >  1 file changed, 24 insertions(+), 31 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
> > index 313339bbff90..f95537627463 100644
> > --- a/drivers/gpu/drm/vgem/vgem_drv.c
> > +++ b/drivers/gpu/drm/vgem/vgem_drv.c
> > @@ -401,16 +401,8 @@ static int vgem_prime_mmap(struct drm_gem_object *obj,
> >       return 0;
> >  }
> >
> > -static void vgem_release(struct drm_device *dev)
> > -{
> > -     struct vgem_device *vgem = container_of(dev, typeof(*vgem), drm);
> > -
> > -     platform_device_unregister(vgem->platform);
> > -}
> > -
> >  static struct drm_driver vgem_driver = {
> >       .driver_features                = DRIVER_GEM | DRIVER_RENDER,
> > -     .release                        = vgem_release,
> >       .open                           = vgem_open,
> >       .postclose                      = vgem_postclose,
> >       .gem_free_object_unlocked       = vgem_gem_free_object,
> > @@ -442,48 +434,49 @@ static struct drm_driver vgem_driver = {
> >  static int __init vgem_init(void)
> >  {
> >       int ret;
> > +     struct platform_device *pdev;
> >
> > -     vgem_device = kzalloc(sizeof(*vgem_device), GFP_KERNEL);
> > -     if (!vgem_device)
> > -             return -ENOMEM;
> > +     pdev = platform_device_register_simple("vgem", -1, NULL, 0);
> > +     if (IS_ERR(pdev))
> > +             return PTR_ERR(vgem_device->platform);
> I caught this line right above.
> It should be: return PTR_ERR (pdev), right?

Yes I will fix.

> > -     vgem_device->platform =
> > -             platform_device_register_simple("vgem", -1, NULL, 0);
> > -     if (IS_ERR(vgem_device->platform)) {
> > -             ret = PTR_ERR(vgem_device->platform);
> > -             goto out_free;
> > +     if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
> > +             ret = -ENOMEM;
> > +             goto out_unregister;
> >       }
> >
> > -     dma_coerce_mask_and_coherent(&vgem_device->platform->dev,
> > +     dma_coerce_mask_and_coherent(&pdev->dev,
> >                                    DMA_BIT_MASK(64));
> > -     ret = drm_dev_init(&vgem_device->drm, &vgem_driver,
> > -                        &vgem_device->platform->dev);
> > -     if (ret)
> > -             goto out_unregister;
> > -     drmm_add_final_kfree(&vgem_device->drm, vgem_device);
> > +
> > +     vgem_device = devm_drm_dev_alloc(&pdev->dev, &vgem_driver,
> > +                                      struct vgem_device, drm);
> > +     if (IS_ERR(vgem_device)) {
> > +             ret = PTR_ERR(vgem_device);
> > +             goto out_devres;
> > +     }
> > +     vgem_device->platform = pdev;
> >
> >       /* Final step: expose the device/driver to userspace */
> >       ret = drm_dev_register(&vgem_device->drm, 0);
> >       if (ret)
> > -             goto out_put;
> > +             goto out_devres;
> >
> >       return 0;
> >
> > -out_put:
> > -     drm_dev_put(&vgem_device->drm);
> > -     platform_device_unregister(vgem_device->platform);
> > -     return ret;
> > +out_devres:
> > +     devres_release_group(&pdev->dev, NULL);
> >  out_unregister:
> > -     platform_device_unregister(vgem_device->platform);
> > -out_free:
> > -     kfree(vgem_device);
> > +     platform_device_unregister(pdev);
> >       return ret;
> >  }
> >
> >  static void __exit vgem_exit(void)
> >  {
> > +     struct platform_device *pdev = vgem_device->platform;
> > +
> Well, there has never been a check for a null vgem_device here before,
> as in vkms. Should?

I think it should, but that's kinda a separate patch. Want to type it?
-Daniel

> >       drm_dev_unregister(&vgem_device->drm);
> > -     drm_dev_put(&vgem_device->drm);
> > +     devres_release_group(&pdev->dev, NULL);
> > +     platform_device_unregister(pdev);
> >  }
> >
> >  module_init(vgem_init);
> > --
> > 2.28.0
>
> Apart from these two points,
>
> Reviewed-by: Melissa Wen <melissa.srw@gmail.com>
>
> Thanks!
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel



-- 
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:[~2020-09-09 11:21 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-04 14:39 [PATCH 00/24] drm_managed, leftovers Daniel Vetter
2020-09-04 14:39 ` [PATCH 01/24] drm/armada: Use devm_drm_dev_alloc Daniel Vetter
2020-09-10  1:20   ` Dave Airlie
2020-09-04 14:39 ` [PATCH 02/24] drm/armada: Don't use drm_device->dev_private Daniel Vetter
2020-09-04 14:39 ` [PATCH 03/24] drm/aspeed: Use managed drmm_mode_config_cleanup Daniel Vetter
2020-09-04 14:39 ` [PATCH 04/24] drm/vgem: Use devm_drm_dev_alloc Daniel Vetter
2020-09-09 11:01   ` Melissa Wen
2020-09-09 11:20     ` Daniel Vetter [this message]
2020-09-09 16:29       ` Melissa Wen
2020-09-09 12:07   ` [PATCH] " Daniel Vetter
2020-09-04 14:39 ` [PATCH 05/24] drm/vkms: " Daniel Vetter
2020-09-08 23:42   ` Melissa Wen
2020-09-09  9:18   ` [PATCH] " Daniel Vetter
2020-09-09  9:22     ` Melissa Wen
2020-09-04 14:39 ` [PATCH 06/24] drm/xlnx: " Daniel Vetter
2020-09-07  8:22   ` [PATCH] " Daniel Vetter
2020-09-08 19:16     ` Hyun Kwon
2020-09-11  8:47       ` Daniel Vetter
2020-09-04 14:39 ` [PATCH 07/24] drm/i915/selftest: Create mock_destroy_device Daniel Vetter
2020-09-04 14:39 ` [PATCH 08/24] drm/i915/selftests: align more to real device lifetimes Daniel Vetter
2020-09-11  8:59   ` [Intel-gfx] " Maarten Lankhorst
2020-09-11  9:08   ` Matthew Auld
2020-09-04 14:39 ` [PATCH 09/24] drm/dev: Remove drm_dev_init Daniel Vetter
2020-09-04 14:39 ` [PATCH 10/24] drm/arc: Switch to devm_drm_dev_alloc Daniel Vetter
2020-10-23 12:31   ` Daniel Vetter
2020-09-04 14:39 ` [PATCH 11/24] drm/arc: Stop using drm_device->dev_private Daniel Vetter
2020-09-04 15:09   ` Daniel Vetter
2020-09-04 14:39 ` [PATCH 12/24] drm/arc: Delete arcpgu_priv->fb Daniel Vetter
2020-09-04 14:39 ` [PATCH 13/24] drm/arc: Embedded a drm_simple_display_pipe Daniel Vetter
2020-09-04 14:39 ` [PATCH 14/24] drm/arc: Embedd a drm_connector for sim case Daniel Vetter
2020-09-04 14:39 ` [PATCH 15/24] drm/arc: Drop surplus connector registration Daniel Vetter
2020-09-04 14:39 ` [PATCH 16/24] drm/arc: Use drmm_mode_config_cleanup Daniel Vetter
2020-09-04 14:39 ` [PATCH 17/24] drm/arc: Align with simple pipe helpers Daniel Vetter
2020-09-04 14:39 ` [PATCH 18/24] drm/arc: Convert to drm_simple_kms_pipe_helper Daniel Vetter
2020-09-04 14:39 ` [PATCH 19/24] drm/arc: Drop crtc check in arc_pgu_update Daniel Vetter
2020-09-04 14:39 ` [PATCH 20/24] drm/arc: Inline arcpgu_crtc.c Daniel Vetter
2020-09-04 14:39 ` [PATCH 21/24] drm/arc: Inline arcpgu_drm_hdmi_init Daniel Vetter
2020-09-04 14:39 ` [PATCH 22/24] drm/arc: Inline remaining files Daniel Vetter
2020-09-04 14:39 ` [PATCH 23/24] drm/arc: Initialize sim connector before display pipe Daniel Vetter
2020-09-04 14:39 ` [PATCH 24/24] drm/arc: Move to drm/tiny Daniel Vetter
2020-09-09  7:54   ` Thomas Zimmermann

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=CAKMK7uFJ3Yf-rnb5VAYj1xF2VZmoY+yt+zWyRcaMLU0t6eCyoA@mail.gmail.com \
    --to=daniel.vetter@ffwll.ch \
    --cc=chris@chris-wilson.co.uk \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emil.velikov@collabora.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=melissa.srw@gmail.com \
    --cc=robdclark@chromium.org \
    --cc=sam@ravnborg.org \
    --cc=seanpaul@chromium.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 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).