Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1696713pxa; Sun, 2 Aug 2020 17:41:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3upzPochcSd83m78OeDDO3j+vhCPKz3iEt/N+cAO5NZHsrQb27XcjLu5C2dk+aYe5nSFE X-Received: by 2002:a17:906:b59:: with SMTP id v25mr14065625ejg.436.1596415273700; Sun, 02 Aug 2020 17:41:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596415273; cv=none; d=google.com; s=arc-20160816; b=I8LyLa423XDu2TZ2Oq3HrIhQ4fcSmGK0BYwT/A0dMVSfrxR4uxlPJo3RKc62nZpGsR /958158KVtt/IdCSPowqVl/VZqUGl00ZCmrxXDYtaulWeRPuWji/OXQRyNU9gvNyQRTb fL3ZcxcNSGk7GCIOPZbqOWI+Mf9xr1oc1ZHmwGA7RNxFm10V2Y2J5IxKQpMnuc2/FdZC HdLrp0a2T7scXpdeuzGMcfd2WoL6lI7hiDTZ+a5XnKuNGnG/s7XHqI5iV++xYIZF7imL RwpZiHwqkbwvmmrNDPHJZgiZLRvcHFrt3z8xQqizk+FGLwJCNYZUwNaBxwcOEXg4drov E2wA== 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=2I9cPVvF0Vifvg/7QXGMIgPuKC6OxgTWEEGETmpDQ4Y=; b=Hb8IUbxk9SD0ACdgZBnQUqhBnCQvI3DbsARvjJVCJ7gYhivCGeFAwmBwjn9yxJIVG7 ml+Lm3O+fcUxvL/EIuCD5bUKIky2m6FcrHALghd4A5sXemFi/FERixGcqheuycorZmgH OFG+vC+w2GSoQbolWSUXw1LaL1wIne/7piWjzmJeEanrFMoO6IolzaagpfkiRINRgNG1 ueGxCX4SfNvO7ixc1YoSz2lVbyw0WDWRJcxu3pqj+n1AVEI7m2OqtPtZIzJmpAaldFXf 3sRLNdqG7GXR/YahIlPuTWjeNKi8bl2b46BMudliRrtZFu+B0hSRe1jm2EujaOYK3c3R 92mw== 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 r25si9032243edw.333.2020.08.02.17.40.51; Sun, 02 Aug 2020 17:41:13 -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 S1727955AbgHCAkp (ORCPT + 99 others); Sun, 2 Aug 2020 20:40:45 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:9313 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726257AbgHCAko (ORCPT ); Sun, 2 Aug 2020 20:40:44 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id BD4E0F42E83C1676A573; Mon, 3 Aug 2020 08:40:38 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Mon, 3 Aug 2020 08:40:30 +0800 From: Tian Tao To: , , , , , , , , CC: Subject: [PATCH drm/hisilicon v2 2/3] drm/hisilicon: Code refactoring for hibmc_drv_de Date: Mon, 3 Aug 2020 08:38:33 +0800 Message-ID: <1596415114-21175-3-git-send-email-tiantao6@hisilicon.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1596415114-21175-1-git-send-email-tiantao6@hisilicon.com> References: <1596415114-21175-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. v2: edit commit message. Signed-off-by: Tian Tao --- 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..af24c72 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->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..91ef15c 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 plane; + struct drm_crtc crtc; struct drm_encoder encoder; struct drm_connector connector; bool mode_config_initialized; -- 2.7.4