public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sui Jingfeng <sui.jingfeng@linux.dev>
To: Lucas Stach <l.stach@pengutronix.de>,
	Russell King <linux+etnaviv@armlinux.org.uk>,
	Christian Gmeiner <christian.gmeiner@gmail.com>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>
Cc: etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn,
	Sui Jingfeng <suijingfeng@loongson.cn>
Subject: [PATCH v1 7/8] drm/etnaviv: Add dedicated functions to create and destroy platform device
Date: Fri, 23 Jun 2023 18:08:21 +0800	[thread overview]
Message-ID: <20230623100822.274706-8-sui.jingfeng@linux.dev> (raw)
In-Reply-To: <20230623100822.274706-1-sui.jingfeng@linux.dev>

From: Sui Jingfeng <suijingfeng@loongson.cn>

Also rename the virtual master 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 <suijingfeng@loongson.cn>
---
 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 14c2e9690ce1..7d0eeab3e8b7 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
@@ -655,12 +655,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();
@@ -680,23 +712,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;
 	}
 
@@ -712,7 +734,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


  parent reply	other threads:[~2023-06-23 10:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-23 10:08 [PATCH v1 0/8] drm/etnaviv: Various cleanup Sui Jingfeng
2023-06-23 10:08 ` [PATCH v1 1/8] drm/etnaviv: Using the size_t variable to store the number of pages Sui Jingfeng
2023-07-17  9:43   ` Lucas Stach
2023-07-17 10:12     ` Sui Jingfeng
2023-07-17 10:38       ` Lucas Stach
2023-06-23 10:08 ` [PATCH v1 2/8] drm/etnaviv: Using the unsigned int type to count " Sui Jingfeng
2023-06-23 10:08 ` [PATCH v1 3/8] drm/etnaviv: Drop the second argument of the etnaviv_gem_new_impl() Sui Jingfeng
2023-07-17  9:51   ` Lucas Stach
2023-07-17 18:34     ` suijingfeng
2023-07-18  8:12       ` Lucas Stach
2023-07-18 16:16         ` suijingfeng
2023-07-18 16:24           ` Sui Jingfeng
2023-07-19  8:16           ` Lucas Stach
2023-06-23 10:08 ` [PATCH v1 4/8] drm/etnaviv: Remove surplus else after return Sui Jingfeng
2023-07-17  9:58   ` Lucas Stach
2023-06-23 10:08 ` [PATCH v1 5/8] drm/etnaviv: Keep the curly brace aligned Sui Jingfeng
2023-06-23 10:08 ` [PATCH v1 6/8] drm/etnaviv: No indentation by double tabs Sui Jingfeng
2023-06-23 10:08 ` Sui Jingfeng [this message]
2023-06-23 10:08 ` [PATCH v1 8/8] drm/etnaviv: Add a helper to get a pointer to the first available node Sui Jingfeng
2023-07-17 10:07   ` Lucas Stach
2023-07-17 10:20     ` suijingfeng
2023-07-17 10:36     ` Sui Jingfeng
2023-07-17  8:36 ` [PATCH v1 0/8] drm/etnaviv: Various cleanup suijingfeng
2023-07-17 10:09   ` Lucas Stach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230623100822.274706-8-sui.jingfeng@linux.dev \
    --to=sui.jingfeng@linux.dev \
    --cc=airlied@gmail.com \
    --cc=christian.gmeiner@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=etnaviv@lists.freedesktop.org \
    --cc=l.stach@pengutronix.de \
    --cc=linux+etnaviv@armlinux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongson-kernel@lists.loongnix.cn \
    --cc=suijingfeng@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox