Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6318443rwd; Mon, 19 Jun 2023 05:47:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ZeOtsghqYMFVn+mAUrTkNG84a9thox4v9UTvsKuw0pQon2VewUhpByzRXY/MtbEvolu5F X-Received: by 2002:a17:90a:bb85:b0:25c:1655:157d with SMTP id v5-20020a17090abb8500b0025c1655157dmr10110717pjr.34.1687178851103; Mon, 19 Jun 2023 05:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687178851; cv=none; d=google.com; s=arc-20160816; b=H7if+LgwPErPAIi82/+uvhCZjr4BmwnX6Z/12gJiOyUbOJ0H+mKiW86h9dof3xkBmi lcsXVtbrcNUx6kgtyoHm9hMbTvGBzbBcD6/IGlu7MWAvpB1KET8XB0ym/7sB56+JgYYu BlrLHF2GnQ3dY8YqMnLQZgYX2qy95z0LnhdpByCtZXyPyBiJ1K6YhCB43gW5EhD4pz7V F2Eso73nobOqaDIEvIMh2MJTxe3e8xFM6r2T5IoGJ6O0BqHu1mGz0I/c7Q31+Z20R1Ji O6bfFLed7rQe8dG8kwX6bzto8uFTlliJxwesnjowDGKE4FctE+ArK0rxbO9shnCMyyps HqMQ== 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=t3349AnY481YxNS/a9V2dzyst3an933sL9IUNyIfneyeh1OhUJJG2WK7feXQOsCKgZ hnvxKpIm3qUk/4YimLSia875KeQ3Igvj28qsAyRlguXvN9mRir/w2XfXJCy1/HR1i09t AF03hsbtYmBnwoDJU2xeMWOZ/jXoJaaFzAM3APggPFhTN0UC71so/ELQDYVxLlL6VfBs Tw5+2RyyMFwvG6G7cJ6zKZBzR4fbttOQ0WqTABAHI2CazdmlHjfezK+cGJx0+tw+3Klg dDkCJE+LhLbcY8WIEmj1iNe66fZIZ0cTKQF1F9eOj/1VN/pZUjvM1X5NSGSoNDtSxXUf JUUg== 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 w71-20020a63824a000000b0053fb89f1e10si9714723pgd.501.2023.06.19.05.47.18; Mon, 19 Jun 2023 05:47: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 S230522AbjFSMmX (ORCPT + 99 others); Mon, 19 Jun 2023 08:42:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbjFSMmN (ORCPT ); Mon, 19 Jun 2023 08:42:13 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 47A7191 for ; Mon, 19 Jun 2023 05:42:12 -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 947331001EB; Mon, 19 Jun 2023 20:42:10 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id cf32779ce696411688a85d1ebc14d26a for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:11 CST X-Transaction-ID: cf32779ce696411688a85d1ebc14d26a 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 03/11] drm/etnaviv: Add dedicated functions to create and destroy platform device Date: Mon, 19 Jun 2023 20:41:53 +0800 Message-Id: <20230619124201.2215558-4-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 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