Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/msm/mdp4: use drmm-managed allocation for mdp4_crtc

Change struct mdp4_crtc allocation to use drmm_crtc_alloc(). This
removes the need to perform any actions on CRTC destruction.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Abhinav Kumar <quic_abhinavk@quicinc.com>
Patchwork: https://patchwork.freedesktop.org/patch/546184/
Link: https://lore.kernel.org/r/20230708010407.3871346-13-dmitry.baryshkov@linaro.org

+17 -16
+17 -16
drivers/gpu/drm/msm/disp/mdp4/mdp4_crtc.c
··· 6 6 7 7 #include <drm/drm_crtc.h> 8 8 #include <drm/drm_flip_work.h> 9 + #include <drm/drm_managed.h> 9 10 #include <drm/drm_mode.h> 10 11 #include <drm/drm_probe_helper.h> 11 12 #include <drm/drm_vblank.h> ··· 122 121 123 122 msm_gem_unpin_iova(val, kms->aspace); 124 123 drm_gem_object_put(val); 125 - } 126 - 127 - static void mdp4_crtc_destroy(struct drm_crtc *crtc) 128 - { 129 - struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc); 130 - 131 - drm_crtc_cleanup(crtc); 132 - drm_flip_work_cleanup(&mdp4_crtc->unref_cursor_work); 133 - 134 - kfree(mdp4_crtc); 135 124 } 136 125 137 126 /* statically (for now) map planes to mixer stage (z-order): */ ··· 466 475 467 476 static const struct drm_crtc_funcs mdp4_crtc_funcs = { 468 477 .set_config = drm_atomic_helper_set_config, 469 - .destroy = mdp4_crtc_destroy, 470 478 .page_flip = drm_atomic_helper_page_flip, 471 479 .cursor_set = mdp4_crtc_cursor_set, 472 480 .cursor_move = mdp4_crtc_cursor_move, ··· 606 616 "DMA_P", "DMA_S", "DMA_E", 607 617 }; 608 618 619 + static void mdp4_crtc_flip_cleanup(struct drm_device *dev, void *ptr) 620 + { 621 + struct mdp4_crtc *mdp4_crtc = ptr; 622 + 623 + drm_flip_work_cleanup(&mdp4_crtc->unref_cursor_work); 624 + } 625 + 609 626 /* initialize crtc */ 610 627 struct drm_crtc *mdp4_crtc_init(struct drm_device *dev, 611 628 struct drm_plane *plane, int id, int ovlp_id, ··· 620 623 { 621 624 struct drm_crtc *crtc = NULL; 622 625 struct mdp4_crtc *mdp4_crtc; 626 + int ret; 623 627 624 - mdp4_crtc = kzalloc(sizeof(*mdp4_crtc), GFP_KERNEL); 625 - if (!mdp4_crtc) 626 - return ERR_PTR(-ENOMEM); 628 + mdp4_crtc = drmm_crtc_alloc_with_planes(dev, struct mdp4_crtc, base, 629 + plane, NULL, 630 + &mdp4_crtc_funcs, NULL); 631 + if (IS_ERR(mdp4_crtc)) 632 + return ERR_CAST(mdp4_crtc); 627 633 628 634 crtc = &mdp4_crtc->base; 629 635 ··· 648 648 649 649 drm_flip_work_init(&mdp4_crtc->unref_cursor_work, 650 650 "unref cursor", unref_cursor_worker); 651 + ret = drmm_add_action_or_reset(dev, mdp4_crtc_flip_cleanup, mdp4_crtc); 652 + if (ret) 653 + return ERR_PTR(ret); 651 654 652 - drm_crtc_init_with_planes(dev, crtc, plane, NULL, &mdp4_crtc_funcs, 653 - NULL); 654 655 drm_crtc_helper_add(crtc, &mdp4_crtc_helper_funcs); 655 656 656 657 return crtc;