From patchwork Wed Jun 7 10:55:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 104420 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp173298vqr; Wed, 7 Jun 2023 04:09:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7mBlqukbGRdofElGBwsgyC/vIol1drQuLmMGVyMk7TdufM8JMvIXR7x6Z6TpLgZnzxl5xS X-Received: by 2002:a05:6a21:99a1:b0:117:4d57:d3ad with SMTP id ve33-20020a056a2199a100b001174d57d3admr2948035pzb.3.1686136155401; Wed, 07 Jun 2023 04:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686136155; cv=none; d=google.com; s=arc-20160816; b=d4XzUf5XuuXEfN0aPBfZeDNK6ACyMd8H9PvLBq6xovTE/oJnU5w7eJoGTNJtG3TpQz OSkGeDEeltJigvK5G6Sll8pfKm+h90m4iLTviNu2a2jPM+wLwNLV/pazR5Ee9448l1iU mkv/ILntlR9zNmlZ2O1Y70HDpzeYB+CSeV0O4KxkEsAN9c5evnqNyWgP+u5c4fIciXJ0 hxGgaBcb97oEDWR/0wqdm5AcLpekf6GhAg+2iVWgDXxHGldexlVuQxUDrFhi5r/Sw4lK QcDJ/qcU6Q9qdJX+VTxaaynFd8C2UYED67xNskS4ODelRVrT84+SWBVwA/1mmLv3xylU /zKw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 134-20020a63028c000000b0053f3d04e66bsi8827724pgc.698.2023.06.07.04.08.58; Wed, 07 Jun 2023 04:09:15 -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 S239766AbjFGK4N (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768041905117824254?= X-GMAIL-MSGID: =?utf-8?q?1768041905117824254?= 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); }