From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm: Provide a driver hook for drm_dev_release()
Date: Wed, 14 Dec 2016 00:04:38 +0200 [thread overview]
Message-ID: <2757324.EZA4uORW4R@avalon> (raw)
In-Reply-To: <20161208081840.27842-1-chris@chris-wilson.co.uk>
Hi Chris,
Thank you for the patch.
On Thursday 08 Dec 2016 08:18:40 Chris Wilson wrote:
> Some state is coupled into the device lifetime outside of the
> load/unload timeframe and requires teardown during final unreference
> from drm_dev_release(). For example, dmabufs hold both a device and
> module reference and may live longer than expected (i.e. the current
> pattern of the driver tearing down its state and then releasing a
> reference to the drm device) and yet touch driver private state when
> destroyed.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
> drivers/gpu/drm/drm_drv.c | 3 +++
> include/drm/drm_drv.h | 8 ++++++++
> 2 files changed, 11 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index f74b7d06ec01..f945bbcc8eb3 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -595,6 +595,9 @@ static void drm_dev_release(struct kref *ref)
> {
> struct drm_device *dev = container_of(ref, struct drm_device, ref);
>
> + if (dev->driver->release)
> + dev->driver->release(dev);
> +
> if (drm_core_check_feature(dev, DRIVER_GEM))
> drm_gem_destroy(dev);
For drivers embedding the drm_device structure, you should only call
.release() at the very end of this function, as the callback will free memory,
including the embedded struct drm_device. Similarly, the kfree() at the end
should be made conditional. Or, better, you could implement a release function
that just wraps kfree(), and set it as the release handler in drm_dev_alloc().
Drivers using drm_dev_init() would need to provide their own release handler.
> diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
> index c4fc49583dc0..554104ccb939 100644
> --- a/include/drm/drm_drv.h
> +++ b/include/drm/drm_drv.h
> @@ -71,6 +71,14 @@ struct drm_driver {
> void (*postclose) (struct drm_device *, struct drm_file *);
> void (*lastclose) (struct drm_device *);
> int (*unload) (struct drm_device *);
> + /**
> + * @release:
> + *
> + * Optional callback for destroying device state after the final
> + * reference is released, i.e. the device is being destroyed.
> + */
> + void (*release) (struct drm_device *);
> +
> int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file
> *file_priv);
> int (*dma_quiescent) (struct drm_device *);
> int (*context_dtor) (struct drm_device *dev, int context);
--
Regards,
Laurent Pinchart
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2016-12-13 22:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-08 8:18 [PATCH] drm: Provide a driver hook for drm_dev_release() Chris Wilson
2016-12-08 8:45 ` ✓ Fi.CI.BAT: success for " Patchwork
2016-12-08 10:31 ` [Intel-gfx] [PATCH] " Daniel Vetter
2016-12-13 22:04 ` Laurent Pinchart [this message]
2017-01-19 11:20 ` Chris Wilson
2017-01-19 20:55 ` Laurent Pinchart
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=2757324.EZA4uORW4R@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.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.