Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp256725pxa; Wed, 12 Aug 2020 00:46:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzxKXlhttxTVH9MCf7t0RwN6+2/AIEDty1u+iAmKT3CK/j0knQWmUHeggoW/8mexzPADyk X-Received: by 2002:a17:906:cc47:: with SMTP id mm7mr28314896ejb.362.1597218394050; Wed, 12 Aug 2020 00:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597218394; cv=none; d=google.com; s=arc-20160816; b=D1Lg11Xy00xMPQsfqeY4Nnt0ZwOJpMiKisrUAkQ3Y4SxgEuA93jMz+q49CS9hhCcnv rhCzsPd6PffWt6YXxjFd//9FLg6rORnu/auR23CCmH5lmgogLnbFV8HwXcfmQPOh41t3 7TQaLU03XtJd39fiL8kBCt0Fvhe8tU7ZKSOzK08vErgOyQVtOyTI9DYo3wl849YLJrSt nQtxOexPMP25Uam++P5btqHt05hUq23889doTvF512bJii0QF+4etgGmTpns8usW+nFm WrhW7Rbu0BLheJQ6ME/no+uodaRmmy8rLuBIn047SAgwSK4Y9j/NOwrh9xidEvg3QuyK xtDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=0mswdvZ6i42tosdK4gY5QEDlu1/hiDubhidVfKmfI1k=; b=wkDFbmfZBnj7+LWz42MNTnEfoa8xyirh6O74Vumt19YtZ8qTtJpDrRYpRFfeAPxxqE bYeK0H0TUqOGCbAGr0+lWMW3j+BLgly13AQcBtFIuzw4lKqH6BY/xVA2qbat8NJTkgA6 L2k2xUWN49oXVUnVqz7yinJ5extGvxolZH83lYej2OxmSJYdnGHbOy0VxEkJAReAeKO7 Nh+heAdFUaTurSZxI144xlg4NYnhbaS8+q8E5tr5YJq6wnhaTa9fslIUVrwuRW25dU6O 2S1aH5vL+XqNSFHd7MAxi2NEXa1iSXl0JgUFjZ2olkw0ONXGXD3R5MaFNZcaCUSR4oGT dtIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a1si768822edn.356.2020.08.12.00.46.11; Wed, 12 Aug 2020 00:46:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726893AbgHLHpR (ORCPT + 99 others); Wed, 12 Aug 2020 03:45:17 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:43158 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726479AbgHLHpP (ORCPT ); Wed, 12 Aug 2020 03:45:15 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id E89E35E1AA074BA69AD4; Wed, 12 Aug 2020 15:45:10 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Wed, 12 Aug 2020 15:45:01 +0800 From: Tian Tao To: , , , , , , , , CC: Subject: [PATCH drm/hisilicon v3 2/2] drm/hisilicon: Code refactoring for hibmc_drv_de Date: Wed, 12 Aug 2020 15:42:59 +0800 Message-ID: <1597218179-3938-3-git-send-email-tiantao6@hisilicon.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1597218179-3938-1-git-send-email-tiantao6@hisilicon.com> References: <1597218179-3938-1-git-send-email-tiantao6@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The memory used to be allocated with devres helpers and released automatically. In rare circumstances, the memory's release could have happened before the DRM device got released, which would have caused memory corruption of some kind. Now we're embedding the data structures in struct hibmc_drm_private. The whole release problem has been resolved, because struct hibmc_drm_private is allocated with drmm_kzalloc and always released with the DRM device. Signed-off-by: Tian Tao Reviewed-by: Thomas Zimmermann --- drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 55 ++++++------------------- drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 + 2 files changed, 15 insertions(+), 42 deletions(-) diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c index 66132eb..d9062a3 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c @@ -157,37 +157,6 @@ static const struct drm_plane_helper_funcs hibmc_plane_helper_funcs = { .atomic_update = hibmc_plane_atomic_update, }; -static struct drm_plane *hibmc_plane_init(struct hibmc_drm_private *priv) -{ - struct drm_device *dev = priv->dev; - struct drm_plane *plane; - int ret = 0; - - plane = devm_kzalloc(dev->dev, sizeof(*plane), GFP_KERNEL); - if (!plane) { - DRM_ERROR("failed to alloc memory when init plane\n"); - return ERR_PTR(-ENOMEM); - } - /* - * plane init - * TODO: Now only support primary plane, overlay planes - * need to do. - */ - ret = drm_universal_plane_init(dev, plane, 1, &hibmc_plane_funcs, - channel_formats1, - ARRAY_SIZE(channel_formats1), - NULL, - DRM_PLANE_TYPE_PRIMARY, - NULL); - if (ret) { - DRM_ERROR("failed to init plane: %d\n", ret); - return ERR_PTR(ret); - } - - drm_plane_helper_add(plane, &hibmc_plane_helper_funcs); - return plane; -} - static void hibmc_crtc_dpms(struct drm_crtc *crtc, int dpms) { struct hibmc_drm_private *priv = crtc->dev->dev_private; @@ -534,22 +503,24 @@ static const struct drm_crtc_helper_funcs hibmc_crtc_helper_funcs = { int hibmc_de_init(struct hibmc_drm_private *priv) { struct drm_device *dev = priv->dev; - struct drm_crtc *crtc; - struct drm_plane *plane; + struct drm_crtc *crtc = &priv->crtc; + struct drm_plane *plane = &priv->primary_plane; int ret; - plane = hibmc_plane_init(priv); - if (IS_ERR(plane)) { - DRM_ERROR("failed to create plane: %ld\n", PTR_ERR(plane)); - return PTR_ERR(plane); - } + ret = drm_universal_plane_init(dev, plane, 1, &hibmc_plane_funcs, + channel_formats1, + ARRAY_SIZE(channel_formats1), + NULL, + DRM_PLANE_TYPE_PRIMARY, + NULL); - crtc = devm_kzalloc(dev->dev, sizeof(*crtc), GFP_KERNEL); - if (!crtc) { - DRM_ERROR("failed to alloc memory when init crtc\n"); - return -ENOMEM; + if (ret) { + DRM_ERROR("failed to init plane: %d\n", ret); + return ret; } + drm_plane_helper_add(plane, &hibmc_plane_helper_funcs); + ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL, &hibmc_crtc_funcs, NULL); if (ret) { diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h index a683763..197485e 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h @@ -28,6 +28,8 @@ struct hibmc_drm_private { /* drm */ struct drm_device *dev; + struct drm_plane primary_plane; + struct drm_crtc crtc; struct drm_encoder encoder; struct drm_connector connector; bool mode_config_initialized; -- 2.7.4