drm: Cleanups after drmm_add_final_kfree rollout

A few things:
- Update the example driver in the documentation.
- We can drop the old kfree in drm_dev_release.
- Add a WARN_ON check in drm_dev_register to make sure everyone calls
  drmm_add_final_kfree and there's no leaks.

v2: Restore the full cleanup, I accidentally left some moved code
behind when fixing the bisectability of the series.

Acked-by: Sam Ravnborg <sam@ravnborg.org>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200323144950.3018436-20-daniel.vetter@ffwll.ch
This commit is contained in:
Daniel Vetter 2020-03-23 15:49:18 +01:00
parent 780e41edf8
commit 5dad34f3c4

View File

@ -297,8 +297,6 @@ void drm_minor_release(struct drm_minor *minor)
*
* drm_mode_config_cleanup(drm);
* drm_dev_fini(drm);
* kfree(priv->userspace_facing);
* kfree(priv);
* }
*
* static struct drm_driver driver_drm_driver = {
@ -326,10 +324,11 @@ void drm_minor_release(struct drm_minor *minor)
* kfree(drm);
* return ret;
* }
* drmm_add_final_kfree(drm, priv);
*
* drm_mode_config_init(drm);
*
* priv->userspace_facing = kzalloc(..., GFP_KERNEL);
* priv->userspace_facing = drmm_kzalloc(..., GFP_KERNEL);
* if (!priv->userspace_facing)
* return -ENOMEM;
*
@ -837,10 +836,7 @@ static void drm_dev_release(struct kref *ref)
drm_managed_release(dev);
if (!dev->driver->release && !dev->managed.final_kfree) {
WARN_ON(!list_empty(&dev->managed.resources));
kfree(dev);
} else if (dev->managed.final_kfree)
if (dev->managed.final_kfree)
kfree(dev->managed.final_kfree);
}
@ -961,6 +957,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
if (!driver->load)
drm_mode_config_validate(dev);
WARN_ON(!dev->managed.final_kfree);
if (drm_dev_needs_global_mutex(dev))
mutex_lock(&drm_global_mutex);