From patchwork Sat Jun 3 10:59:39 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: 102834 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1597921vqr; Sat, 3 Jun 2023 04:21:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6x5uktadHli/D3YK1jbJ9QYuxIiCXJg7pm+hZFctBCkGdZnJ7rUihrAueCP4nCXEy7o3VK X-Received: by 2002:a05:6a00:1593:b0:64c:9972:f74b with SMTP id u19-20020a056a00159300b0064c9972f74bmr19788340pfk.12.1685791280455; Sat, 03 Jun 2023 04:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685791280; cv=none; d=google.com; s=arc-20160816; b=vau3cdUY5s6qmnncFrIw5r2ThQp/4lLXSSzJ5KntpV3WW7UD6RXEKrSBGj/4DZ9eBJ zGrzbHsB3DhLz+XKNNwMXbc+wJ69dxsG5MYlr/fGNNajUrPSqZI0D+5rQsXYH71r8u14 6Ead+w/GVXoxct/CaIZL5F6HT3gy/1LwRn6oHwwSU8gao33zJgMeLfrC7G7maUnYBGy3 HQdMs4ntk/fSUwNYUGRihioY3KkrqUAwtIS9vylgdyATjQO73uC3X4i4/ucPkLva+Fn4 0SsQBoT2eqW2aeFM7Rh6Lb8cAIscE0oNmqYqXZ1Fr5GDBZXrZP+rpwsweU10ZLjrcMEx zpQg== 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=uWnKRf32K+J/mfD5Su/uhTadlDH9biueYMZWff3xcsk=; b=n+soeinAZ+tliDL/O3DcDSYxkUhMz5tW6OW8XWb2D20CVmV13xA375VWGHvw/8YBdH 6aMidqRDSeXcIGSF5xefpOrL1tv5QgkSUfgWgAaW/PBvkmro0adK0OPGmgthP14nSJmV pkr5ZBtq9ZUfNghFehGjsXkvNlxrcS70ih6DhkVMztPLcU14gR1hhQuHJqvgWEsDB+kn Un95TfH3B7Zge7ikFs6mOEvL5/KCG3P6hVjYthUSrY39p4xHy7LaH3YfvP0HzE/J9mjQ hXelAY9/pBkQPkI2JC13qwi5AawZUjV7NT1ddQJjM2vCSlQR5jSCOXnXJe5ekXttSavw TUHQ== 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 k197-20020a633dce000000b005030eb175d1si2571684pga.107.2023.06.03.04.21.06; Sat, 03 Jun 2023 04:21:20 -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 S237145AbjFCLAZ (ORCPT + 99 others); Sat, 3 Jun 2023 07:00:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230120AbjFCLAK (ORCPT ); Sat, 3 Jun 2023 07:00:10 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 43DB31B5 for ; Sat, 3 Jun 2023 04:00:08 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:51732.1826327623 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id 75CC61002EF; Sat, 3 Jun 2023 19:00:06 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-7vx9t with ESMTP id 20b188bbcba64f2b8563c07bf6954a0d for l.stach@pengutronix.de; Sat, 03 Jun 2023 19:00:07 CST X-Transaction-ID: 20b188bbcba64f2b8563c07bf6954a0d 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 , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng Subject: [PATCH v7 3/7] drm/etnaviv: add dedicated functions to create and destroy platform devices Date: Sat, 3 Jun 2023 18:59:39 +0800 Message-Id: <20230603105943.3042766-4-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603105943.3042766-1-15330273260@189.cn> References: <20230603105943.3042766-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?1767680277680120021?= X-GMAIL-MSGID: =?utf-8?q?1767680277680120021?= 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. 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); }