Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp565151rwd; Wed, 7 Jun 2023 04:07:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5clTFG/owLx08ysnVvZ3xM8AKgmqlkSbLprYsJJUdSMMN+foRTvZSd0DhzvhtxxjNPiNS5 X-Received: by 2002:a17:902:ce88:b0:1b2:3e9f:69d1 with SMTP id f8-20020a170902ce8800b001b23e9f69d1mr5703155plg.18.1686136070576; Wed, 07 Jun 2023 04:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686136070; cv=none; d=google.com; s=arc-20160816; b=jfoNgjbBaN+bQeqG7wbO6KLBDCy8s3ghO9x67oWDpjogKxYb9BVmDEZh+ErhI1g7/T Mi0mJ9UCu3WdR2oRf+R1cqtVyi7SzRJ1QT6hlc9YvM0u9ElW/9hJ2sagK7b38n2OtDPi 7VgE0LwggEsgj+qjcyu4bvx7X187+Gvq0VcNuIaGqUDGGVau5E87qlFH2AaD3o2tfkE0 TWrdN0eBYQxDLVBfQGXRF2RmT4UflZFU3IIIALWZHNHPtHK5NeK6QZ9IwtF66NkQ/byj /N4FQGJ6pJAwRW4tm/Mt37YGcaxl3pmLWD7lH1L3wSIh/wy1noj/CbwIf+bgzMi7n3U6 SKuA== 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=I036IOlE47YU/zkCBkHIDjqcQBQLJoAnED19i/4kJrc=; b=zsyJ7AVrGJMaqOnz2+6l5SKKWXiPyBDnPmhjAI8nnAOrXzb6Y17ESOWFFCM+aYDE3a sH4QSfY/E3kn8XMGfKMlvgh7lxZDeu4VccD8Ei3fivZr1vZ/XHlZe6TB1ItpGMIQFw66 c6/SecDR3RsToLQW7oUhmo1QMTZ0JUayt8qhPq/DlJurYTRL+QQpNHO1UzrFMT044ezO 2tVuTruR24icSWU5BOZZhTcCxw41bFc1WivEDHeVcrEIE4I0EKf9mK3NY8Fry/guQWwR tbqpATNzrgQLndT7MoyPed+xnqyMSNXr2I+FVhc7Aq5Klys58cs86eq8XvqaeP+hlSEk sc/A== 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 ja12-20020a170902efcc00b0019f3064da41si8483553plb.383.2023.06.07.04.07.35; Wed, 07 Jun 2023 04:07:50 -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 S239726AbjFGK4N (ORCPT + 99 others); Wed, 7 Jun 2023 06:56:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235180AbjFGK4K (ORCPT ); Wed, 7 Jun 2023 06:56:10 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.102]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2B15DAA for ; Wed, 7 Jun 2023 03:56:08 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:55208.1520123491 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id 6B6231002B4; Wed, 7 Jun 2023 18:56:04 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id b9c699e2dbda4ae1bf07bf511aa14d53 for l.stach@pengutronix.de; Wed, 07 Jun 2023 18:56:07 CST X-Transaction-ID: b9c699e2dbda4ae1bf07bf511aa14d53 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 , Li Yi Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng , Philipp Zabel , Bjorn Helgaas Subject: [PATCH v8 3/8] drm/etnaviv: add dedicated functions to create and destroy platform devices Date: Wed, 7 Jun 2023 18:55:46 +0800 Message-Id: <20230607105551.568639-4-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230607105551.568639-1-15330273260@189.cn> References: <20230607105551.568639-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,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 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 Also rename the virtual master platform device as etnaviv_platform_device, for better reflection that it is a platform device, not a DRM device. Another benefit is that we no longer need to call of_node_put() for three different cases, Instead, we only need to call it once. 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 | 56 +++++++++++++++++++-------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 31a7f59ccb49..cec005035d0e 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -656,12 +656,44 @@ static struct platform_driver etnaviv_platform_driver = { }, }; -static struct platform_device *etnaviv_drm; +static struct platform_device *etnaviv_platform_device; -static int __init etnaviv_init(void) +static int etnaviv_create_platform_device(const char *name, + struct platform_device **ppdev) { struct platform_device *pdev; int ret; + + pdev = platform_device_alloc(name, PLATFORM_DEVID_NONE); + if (!pdev) + return -ENOMEM; + + ret = platform_device_add(pdev); + if (ret) { + platform_device_put(pdev); + return ret; + } + + *ppdev = pdev; + + return 0; +} + +static void etnaviv_destroy_platform_device(struct platform_device **ppdev) +{ + struct platform_device *pdev = *ppdev; + + if (!pdev) + return; + + platform_device_unregister(pdev); + + *ppdev = NULL; +} + +static int __init etnaviv_init(void) +{ + int ret; struct device_node *np; etnaviv_validate_init(); @@ -681,23 +713,13 @@ static int __init etnaviv_init(void) for_each_compatible_node(np, NULL, "vivante,gc") { if (!of_device_is_available(np)) continue; + of_node_put(np); - pdev = platform_device_alloc("etnaviv", PLATFORM_DEVID_NONE); - if (!pdev) { - ret = -ENOMEM; - of_node_put(np); - goto unregister_platform_driver; - } - - ret = platform_device_add(pdev); - if (ret) { - platform_device_put(pdev); - of_node_put(np); + ret = etnaviv_create_platform_device("etnaviv", + &etnaviv_platform_device); + if (ret) goto unregister_platform_driver; - } - etnaviv_drm = pdev; - of_node_put(np); break; } @@ -713,7 +735,7 @@ module_init(etnaviv_init); static void __exit etnaviv_exit(void) { - platform_device_unregister(etnaviv_drm); + etnaviv_destroy_platform_device(&etnaviv_platform_device); platform_driver_unregister(&etnaviv_platform_driver); platform_driver_unregister(&etnaviv_gpu_driver); } -- 2.25.1