Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6321677rwd; Mon, 19 Jun 2023 05:50:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CIxi3/ASHU4R/4TmIeZsvFcIY+R1E1ILVTSpYx2WRXmNQ1e4g++BA5MDJ/3078o44Gu5c X-Received: by 2002:a05:6a20:8e01:b0:10e:f1e3:8217 with SMTP id y1-20020a056a208e0100b0010ef1e38217mr9067533pzj.17.1687179038484; Mon, 19 Jun 2023 05:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687179038; cv=none; d=google.com; s=arc-20160816; b=WMRZpX5pBrU1VReS694BC91jX/eVBubWberw/tSfiCcfVhUKBgyZ1oNzvLdcceMokd ntK5zwt3c+MTu7r6nVY0bOI06fWh7D7nJwbt2VcQOlPtjDt1kTtDtvsEU+hDBtTKTOuU RRAmqovnBnQEC8yJ9QdJtzDT7Hpf8CQg9xxIERNmTc/mXA+PqxRkR5H11czCDZaP3m3h rU9WY+RsaDXKJtQlhOVdYCRE8Y9FhyVsW6/iYaNLxPLnGbAP5vKQztYyez5EMA+WQv5e 8A3L96GgEEAIksAlDJpiQaUTPt7ZnS0WSCb+8mC4if4TMD/jO35EDJ1eipC2jUOt7oQN C+vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=0lvP6UU76dFFHF28ZQO68S90lwikV6LUi3ioLomLC5I=; b=AoL/xUYjIJ21b1sqTHVqbO1RhP0eQcAo45F7BJZNuLDz63mmGbwqWzIyTeJaBL9/PR zi8VBG60mhEhPe0anWuI+R5Wy3bNyVJY3Igb+O4mHgBl+kHFQRE/pXuuQw6OSUN5wFAb Le65hVttDety16cSU2JQe5lUb9VP6G+2E2LDrE7a3Cmns6wwyWFG57IGmYNDTdGKlP1J pgDJA/QZhchBfQWbwHArwbpl21Te70soMLdMptgDgMryQCa28EunxHFdTHCSvbGpEW0s Jzabcg0FRFWHuyFHDOOcJA/PIQbNjLFi6az4BRe7YXEMiaSEnaIAHghDVjaT+UgtkJ8h YE/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h70-20020a638349000000b0055383ee451fsi6356904pge.729.2023.06.19.05.50.24; Mon, 19 Jun 2023 05:50:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229782AbjFSMm2 (ORCPT + 99 others); Mon, 19 Jun 2023 08:42:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbjFSMmP (ORCPT ); Mon, 19 Jun 2023 08:42:15 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B3F3BAB for ; Mon, 19 Jun 2023 05:42:13 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id A5FA6102961; Mon, 19 Jun 2023 20:42:11 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id ee75ca21548344d3bab114fc829fc0fe for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:12 CST X-Transaction-ID: ee75ca21548344d3bab114fc829fc0fe X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng , Philipp Zabel , Bjorn Helgaas Subject: [PATCH v10 04/11] drm/etnaviv: Add helpers for private data construction and destruction Date: Mon, 19 Jun 2023 20:41:54 +0800 Message-Id: <20230619124201.2215558-5-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,RCVD_IN_SBL_CSS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sui Jingfeng There are numerous members in the struct etnaviv_drm_private, which are shared by all GPU core. This patch introduces two dedicated functions for the construction and destruction of the instances of this structure. The goal is to keep its members from leaking to the outside. The code needed for error handling can also be simplified. Cc: Lucas Stach Cc: Christian Gmeiner Cc: Philipp Zabel Cc: Bjorn Helgaas Cc: Daniel Vetter Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 73 +++++++++++++++++---------- drivers/gpu/drm/etnaviv/etnaviv_drv.h | 1 + 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index cec005035d0e..6a048be02857 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -24,9 +24,47 @@ #include "etnaviv_perfmon.h" /* - * DRM operations: + * etnaviv private data construction and destructions: */ +static struct etnaviv_drm_private * +etnaviv_alloc_private(struct device *dev, struct drm_device *drm) +{ + struct etnaviv_drm_private *priv; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return ERR_PTR(-ENOMEM); + + priv->drm = drm; + + xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); + + mutex_init(&priv->gem_lock); + INIT_LIST_HEAD(&priv->gem_list); + priv->num_gpus = 0; + priv->shm_gfp_mask = GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; + priv->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(dev); + if (IS_ERR(priv->cmdbuf_suballoc)) { + kfree(priv); + dev_err(dev, "Failed to create cmdbuf suballocator\n"); + return ERR_PTR(-ENOMEM); + } + + return priv; +} + +static void etnaviv_free_private(struct etnaviv_drm_private *priv) +{ + if (!priv) + return; + + etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); + + xa_destroy(&priv->active_contexts); + + kfree(priv); +} static void load_gpu(struct drm_device *dev) { @@ -511,35 +549,21 @@ static int etnaviv_bind(struct device *dev) if (IS_ERR(drm)) return PTR_ERR(drm); - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) { - dev_err(dev, "failed to allocate private data\n"); - ret = -ENOMEM; + priv = etnaviv_alloc_private(dev, drm); + if (IS_ERR(priv)) { + ret = PTR_ERR(priv); goto out_put; } + drm->dev_private = priv; dma_set_max_seg_size(dev, SZ_2G); - xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); - - mutex_init(&priv->gem_lock); - INIT_LIST_HEAD(&priv->gem_list); - priv->num_gpus = 0; - priv->shm_gfp_mask = GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; - - priv->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(drm->dev); - if (IS_ERR(priv->cmdbuf_suballoc)) { - dev_err(drm->dev, "Failed to create cmdbuf suballocator\n"); - ret = PTR_ERR(priv->cmdbuf_suballoc); - goto out_free_priv; - } - dev_set_drvdata(dev, drm); ret = component_bind_all(dev, drm); if (ret < 0) - goto out_destroy_suballoc; + goto out_free_priv; load_gpu(drm); @@ -551,10 +575,8 @@ static int etnaviv_bind(struct device *dev) out_unbind: component_unbind_all(dev, drm); -out_destroy_suballoc: - etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); out_free_priv: - kfree(priv); + etnaviv_free_private(priv); out_put: drm_dev_put(drm); @@ -570,12 +592,9 @@ static void etnaviv_unbind(struct device *dev) component_unbind_all(dev, drm); - etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); - - xa_destroy(&priv->active_contexts); + etnaviv_free_private(priv); drm->dev_private = NULL; - kfree(priv); drm_dev_put(drm); } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h index b3eb1662e90c..e58f82e698de 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -35,6 +35,7 @@ struct etnaviv_file_private { }; struct etnaviv_drm_private { + struct drm_device *drm; int num_gpus; struct etnaviv_gpu *gpu[ETNA_MAX_PIPES]; gfp_t shm_gfp_mask; -- 2.25.1