From patchwork Wed Mar 29 20:51:26 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: 76813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp680014vqo; Wed, 29 Mar 2023 13:53:38 -0700 (PDT) X-Google-Smtp-Source: AKy350YoYlUn0seZ14dwcmA9+lgvD0KKdpZbt0Eoy8W3Nxm/Yp92IH0J1cGbsl0x2WXnbVMI2jWN X-Received: by 2002:a05:6402:712:b0:502:20f0:3ee1 with SMTP id w18-20020a056402071200b0050220f03ee1mr19756225edx.31.1680123217870; Wed, 29 Mar 2023 13:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680123217; cv=none; d=google.com; s=arc-20160816; b=hIVFr+a0hvCJMKgry3dGlbSLHSK1Wz8yL7Jp3XNANAiB1gNJedNSISHv4VsWLQyLTF Me/spBUh7NVfYwfpxNHMAQLcJ2i4nRJb6wpX+uBZyRjTPD3oNn9eAbxPiY36bygWVxvd XfeHXe3j7a6EKhYgA7IPiCRYWqexuSPS6LlVNVvpvjjVhFSfwlw+Pydq/0oWZBXVxggB /J+GBseNuxAsigPFzyNQKk7SPevlQTGmyDX3xPuhcFojo1efSuzzBz6JQ8stD1gzjYjg V6P0yG0Yx6sL8eTK9+Kxd+ZLs9gCDi8PfmIPyNmS0uEuDT0XrIMUOVgwLIswbuoUsCaa oKdg== 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=1+WNe+CkowrnSULz7GNQKTUGdWlhhFBc1XTTAQhIEeQ=; b=zKY/JHfeNe/LxZEb7aXrg3Tyv6hSuwyHHujotil25EG2Qd7825CwPSRSBz/Thcomvm p2tpXaKbqpRr1yI3Bur0m9X1ehQcLHgmVr+rzp0+IXOlNmz8JE0gLtgnMjWN6o8Py7ja k3b0ofi7xEUgIX7KHnhnox7Veek6GI/jkc/6Lo77vEl37queNCqBKCGBPUuwQi/gm1GR Crj32JEhakXTaNRnFZJ1vDiSo70d2KOpFP03NcJkOejbknIyKhz/QBmTV9bwhX3MGWu8 XRjgAcEMNsqPDo4Rq4G0RtOHQTw1+yXFlFETTNcVgwyeqRcm1Mj3Jz1HPyt7nrE/ThBq ny2w== 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 g22-20020aa7d1d6000000b004bf976a1b56si32735630edp.627.2023.03.29.13.52.55; Wed, 29 Mar 2023 13:53:37 -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 S229943AbjC2Uv7 (ORCPT + 99 others); Wed, 29 Mar 2023 16:51:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229618AbjC2Uvq (ORCPT ); Wed, 29 Mar 2023 16:51:46 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B0B094C20 for ; Wed, 29 Mar 2023 13:51:44 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:36106.2084148567 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 0D4F81002CE; Thu, 30 Mar 2023 04:51:43 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-7b48884fd-tj646 with ESMTP id 2cb5b1d07b6b49949d5f7ab88250ec0d for l.stach@pengutronix.de; Thu, 30 Mar 2023 04:51:44 CST X-Transaction-ID: 2cb5b1d07b6b49949d5f7ab88250ec0d 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 Subject: [PATCH v3 3/6] drm/etnaviv: add dedicate functions to create and destroy platform device Date: Thu, 30 Mar 2023 04:51:26 +0800 Message-Id: <20230329205129.1513734-4-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230329205129.1513734-1-15330273260@189.cn> References: <20230329205129.1513734-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=0.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS 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?1761736883180513455?= X-GMAIL-MSGID: =?utf-8?q?1761736883180513455?= From: Sui Jingfeng Also rename the virtual master device as etnaviv_platform_device, for better reflection that it is a platform device, not the drm device control structure. Another benefit is that we no longer need to call of_node_put() for three different case. Instead, we only need 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 44ca803237a5..ce0537af80bd 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -697,12 +697,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; + + *ppdev = NULL; + + platform_device_unregister(pdev); +} + +static int __init etnaviv_init(void) +{ + int ret; struct device_node *np; etnaviv_validate_init(); @@ -723,22 +755,12 @@ static int __init etnaviv_init(void) if (!of_device_is_available(np)) continue; - 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); + of_node_put(np); + if (ret) goto unregister_platform_driver; - } - etnaviv_drm = pdev; - of_node_put(np); break; } @@ -754,7 +776,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); }