Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1252620rdb; Mon, 2 Oct 2023 04:16:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3Tf38aXuAHSFKAgVviWumFw3LYFkIoW1+GPf6g8/h5HHP5Y/1Ftp66gfxsUXGQv5N9Xye X-Received: by 2002:a17:90a:2a42:b0:268:b64b:f684 with SMTP id d2-20020a17090a2a4200b00268b64bf684mr10425702pjg.33.1696245375279; Mon, 02 Oct 2023 04:16:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696245375; cv=none; d=google.com; s=arc-20160816; b=QcsGeKw9IcUH+4JaH/pL+7/bPhjT3ZqjZ4Kl6bgv9dTgrFqNOhbm8j7++G5YWnQvZH GYD+CbrqhM7d3TkyUGzQIJkzw3c/8WHIIT3PjCZV/Jgg+qGk3G06Al3C7dp+ZGJ6zLSO i9GM11qrH5YCS2Jfrqob4tEOR5GX7obUUwrA0JydRXk3l3xzw9QZ1SpN1IMfxVSNigww AAmPJRsprb8gbxYoINGNhcGko0nWjFg4ID/Mka0y+TDvmFgpniovmoJQ0fHmMXMm1Dn9 cYnPqCk3Tl4706niTCQF8wnk+zhZGIMAHJh56ICkgTfeYmjr99ohmmxtvszWyNrpTj9h GJjA== 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; bh=FIVsoqfE1yRlM34jdkAbJd8WQCQxGGM9ifRlFQiCtvY=; fh=zB/Le29j84eF2EWMM5mMCmgRJzHNI4kLocpkF47EhQo=; b=LGQKHQ7GbwhJeuS/M3FRisvULc+19Icrwrj7ictdOy6T6XKrk1Mcxb7ZIQn1iZy/Hs 5QpOWJ0i1VKW6K/hCRkVbm0c5MIP2Ar+Dok2VFPpcAikPdthQ4OTQrLEgsfMiO36hWQV 8Af8zzpKNo9xF2qztJV8QkMnYvef0gvFdZkKxKYrw7UGNv6vHtObMf1d3Qh8u26Oae7F IBL37TNeacs7BT6KimPSzaAJgXlSjyC5ik4H2v4Szg+NrbnqHLcrsAIz3q4Tc3o+0LYn /LxEgwMfu3Y+6fcAxC0yzrUNd1NQnjGjLKw1h67QTEge9wQmSb1NWdcxuQEgtKO8i1/P xFwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id n3-20020a170903404300b001b8921fbd87si24389724pla.490.2023.10.02.04.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 04:16:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id BAABB809B0B5; Mon, 2 Oct 2023 04:13:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236650AbjJBLNE (ORCPT + 99 others); Mon, 2 Oct 2023 07:13:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236677AbjJBLNB (ORCPT ); Mon, 2 Oct 2023 07:13:01 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6094CEE for ; Mon, 2 Oct 2023 04:12:51 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8AxqOiwpRplQJIuAA--.52934S3; Mon, 02 Oct 2023 19:12:48 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxE+SHpRplEh4XAA--.50320S5; Mon, 02 Oct 2023 19:12:08 +0800 (CST) From: Sui Jingfeng To: Lucas Stach Cc: Christian Gmeiner , etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] drm/etnaviv: Add helper functions to create and destroy platform device Date: Mon, 2 Oct 2023 19:12:05 +0800 Message-Id: <20231002111207.513297-4-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231002111207.513297-1-suijingfeng@loongson.cn> References: <20231002111207.513297-1-suijingfeng@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8BxE+SHpRplEh4XAA--.50320S5 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj93XoWxCrWftF45ZryUJr15Ww4fXrc_yoW5GFyUpF 4UGFWFyrW8WFW7Kw1xJrn8ZFW5C3WSg34F9rnFywnI9398AryDJF95JF1UAF9xJrWrG3W5 twn8tF48uF45ZrXCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU90b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4j6r4UJwAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0c Ia020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_ WrylYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwI xGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWU XVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67 kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI42IY 6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVj vjDU0xZFpf9x07j5GYJUUUUU= X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 02 Oct 2023 04:13:23 -0700 (PDT) The newly introduced functions are etnaviv_create_platform_device() and etnaviv_destroy_platform_device(). Those two function are pure function and can be shared for other use case. Currently, the benefit is that we no longer need to call of_node_put() for three different cases, we only need to call it once in the etnaviv_init() function. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 53 +++++++++++++++++++-------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index a3a17316a328..8fe39e31d22d 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -655,11 +655,43 @@ static struct platform_driver etnaviv_platform_driver = { }, }; +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 struct platform_device *etnaviv_drm; static int __init etnaviv_init(void) { - struct platform_device *pdev; int ret; struct device_node *np; @@ -680,23 +712,12 @@ 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_drm); + if (ret) goto unregister_platform_driver; - } - etnaviv_drm = pdev; - of_node_put(np); break; } @@ -712,7 +733,7 @@ module_init(etnaviv_init); static void __exit etnaviv_exit(void) { - platform_device_unregister(etnaviv_drm); + etnaviv_destroy_platform_device(&etnaviv_drm); platform_driver_unregister(&etnaviv_platform_driver); platform_driver_unregister(&etnaviv_gpu_driver); } -- 2.34.1