Skip to content

Commit c23d686

Browse files
committed
drm: Manage drm_vblank_cleanup with drmm_
Nothing special here, except that this is the first time that we automatically clean up something that's initialized with an explicit driver call. But the cleanup was done at the very end of the release sequence for all drivers, and that's still the case. At least without more uses of drmm_ through explicit driver calls. Also for this one we need drmm_kcalloc, so lets add those. The motivation here is to allow us to remove the explicit calls to drm_dev_fini() from all drivers. v2: Sort includes (Laurent) v3: Motivate the change in the commit message better (Sam) Acked-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200323144950.3018436-25-daniel.vetter@ffwll.ch
1 parent 641b910 commit c23d686

4 files changed

Lines changed: 28 additions & 21 deletions

File tree

‎drivers/gpu/drm/drm_drv.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@ EXPORT_SYMBOL(devm_drm_dev_init);
751751
*/
752752
void drm_dev_fini(struct drm_device *dev)
753753
{
754-
drm_vblank_cleanup(dev);
755754
}
756755
EXPORT_SYMBOL(drm_dev_fini);
757756

‎drivers/gpu/drm/drm_internal.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ void drm_managed_release(struct drm_device *dev);
9494

9595
/* drm_vblank.c */
9696
void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe);
97-
void drm_vblank_cleanup(struct drm_device *dev);
9897

9998
/* IOCTLS */
10099
int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,

‎drivers/gpu/drm/drm_vblank.c‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <drm/drm_crtc.h>
3131
#include <drm/drm_drv.h>
3232
#include <drm/drm_framebuffer.h>
33+
#include <drm/drm_managed.h>
3334
#include <drm/drm_modeset_helper_vtables.h>
3435
#include <drm/drm_print.h>
3536
#include <drm/drm_vblank.h>
@@ -425,14 +426,10 @@ static void vblank_disable_fn(struct timer_list *t)
425426
spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
426427
}
427428

428-
void drm_vblank_cleanup(struct drm_device *dev)
429+
static void drm_vblank_init_release(struct drm_device *dev, void *ptr)
429430
{
430431
unsigned int pipe;
431432

432-
/* Bail if the driver didn't call drm_vblank_init() */
433-
if (dev->num_crtcs == 0)
434-
return;
435-
436433
for (pipe = 0; pipe < dev->num_crtcs; pipe++) {
437434
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
438435

@@ -441,10 +438,6 @@ void drm_vblank_cleanup(struct drm_device *dev)
441438

442439
del_timer_sync(&vblank->disable_timer);
443440
}
444-
445-
kfree(dev->vblank);
446-
447-
dev->num_crtcs = 0;
448441
}
449442

450443
/**
@@ -453,25 +446,29 @@ void drm_vblank_cleanup(struct drm_device *dev)
453446
* @num_crtcs: number of CRTCs supported by @dev
454447
*
455448
* This function initializes vblank support for @num_crtcs display pipelines.
456-
* Cleanup is handled by the DRM core, or through calling drm_dev_fini() for
457-
* drivers with a &drm_driver.release callback.
449+
* Cleanup is handled automatically through a cleanup function added with
450+
* drmm_add_action().
458451
*
459452
* Returns:
460453
* Zero on success or a negative error code on failure.
461454
*/
462455
int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs)
463456
{
464-
int ret = -ENOMEM;
457+
int ret;
465458
unsigned int i;
466459

467460
spin_lock_init(&dev->vbl_lock);
468461
spin_lock_init(&dev->vblank_time_lock);
469462

463+
dev->vblank = drmm_kcalloc(dev, num_crtcs, sizeof(*dev->vblank), GFP_KERNEL);
464+
if (!dev->vblank)
465+
return -ENOMEM;
466+
470467
dev->num_crtcs = num_crtcs;
471468

472-
dev->vblank = kcalloc(num_crtcs, sizeof(*dev->vblank), GFP_KERNEL);
473-
if (!dev->vblank)
474-
goto err;
469+
ret = drmm_add_action(dev, drm_vblank_init_release, NULL);
470+
if (ret)
471+
return ret;
475472

476473
for (i = 0; i < num_crtcs; i++) {
477474
struct drm_vblank_crtc *vblank = &dev->vblank[i];
@@ -486,10 +483,6 @@ int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs)
486483
DRM_INFO("Supports vblank timestamp caching Rev 2 (21.10.2013).\n");
487484

488485
return 0;
489-
490-
err:
491-
dev->num_crtcs = 0;
492-
return ret;
493486
}
494487
EXPORT_SYMBOL(drm_vblank_init);
495488

‎include/drm/drm_managed.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define _DRM_MANAGED_H_
55

66
#include <linux/gfp.h>
7+
#include <linux/overflow.h>
78
#include <linux/types.h>
89

910
struct drm_device;
@@ -31,6 +32,21 @@ static inline void *drmm_kzalloc(struct drm_device *dev, size_t size, gfp_t gfp)
3132
{
3233
return drmm_kmalloc(dev, size, gfp | __GFP_ZERO);
3334
}
35+
static inline void *drmm_kmalloc_array(struct drm_device *dev,
36+
size_t n, size_t size, gfp_t flags)
37+
{
38+
size_t bytes;
39+
40+
if (unlikely(check_mul_overflow(n, size, &bytes)))
41+
return NULL;
42+
43+
return drmm_kmalloc(dev, bytes, flags);
44+
}
45+
static inline void *drmm_kcalloc(struct drm_device *dev,
46+
size_t n, size_t size, gfp_t flags)
47+
{
48+
return drmm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
49+
}
3450
char *drmm_kstrdup(struct drm_device *dev, const char *s, gfp_t gfp);
3551

3652
void drmm_kfree(struct drm_device *dev, void *data);

0 commit comments

Comments
 (0)