Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3358938rwd; Sat, 3 Jun 2023 04:01:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42Z2Xw0lAeoVLZUaGVmYbFmMLHj8730oO5edsnc/LULof71zAiZ/dFyZMILQxnSkZLjFVU X-Received: by 2002:a05:6a20:3c90:b0:103:8c8b:c689 with SMTP id b16-20020a056a203c9000b001038c8bc689mr1807506pzj.51.1685790091578; Sat, 03 Jun 2023 04:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685790091; cv=none; d=google.com; s=arc-20160816; b=I+AOGtbkrHVk1y9UIsE5yypFJJK0DssPxml4M4jBHU7T2qygFMoCCHBSFzqQRKqMYz mUxqgf+qhX5lX4SNmhxyiuBqfTb1tTGw7eWYKOTQ3cfs/4sasDrTq+PHEKfMygYZhKN3 pk43KNtyL0XYej9sAcgANwIYQJUhO8mu7YanChCyqpIdComs+3xnGW/vaqMRCL5InLL5 M8d0Fc4OJ0wdmYT7PFuIsHAUQemsN8fvHbxO3PrJwMBebxQPP8yrz/UNO2Kv+fS3RHjx 9zj9MO3Gfb5RSpjnGLffvJU2pnEjRc5OJrAuMGh1XQsDiukuMHckxRg/Q2UzgtHlpHJ5 UMcw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a631753000000b005346bd7dee9si2465784pgx.682.2023.06.03.04.01.16; Sat, 03 Jun 2023 04:01:31 -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 S237140AbjFCLAY (ORCPT + 99 others); Sat, 3 Jun 2023 07:00:24 -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 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. 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