Linux virtualization list
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@linux.ie, daniel@ffwll.ch,
	maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	kraxel@redhat.com, noralf@tronnes.org, sam@ravnborg.org,
	alexander.deucher@amd.com, emil.velikov@collabora.com
Cc: spice-devel@lists.freedesktop.org,
	Thomas Zimmermann <tzimmermann@suse.de>,
	dri-devel@lists.freedesktop.org,
	virtualization@lists.linux-foundation.org
Subject: [PATCH 1/6] drm: Move initialization of encoder into an internal function
Date: Fri,  7 Feb 2020 09:41:30 +0100	[thread overview]
Message-ID: <20200207084135.4524-2-tzimmermann@suse.de> (raw)
In-Reply-To: <20200207084135.4524-1-tzimmermann@suse.de>

Moving encoder init code into an internal function, so it can be reused.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_encoder.c | 78 +++++++++++++++++++++++------------
 1 file changed, 52 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
index e555281f43d4..ffe691a1bf34 100644
--- a/drivers/gpu/drm/drm_encoder.c
+++ b/drivers/gpu/drm/drm_encoder.c
@@ -91,6 +91,47 @@ void drm_encoder_unregister_all(struct drm_device *dev)
 	}
 }
 
+static int __drm_encoder_init(struct drm_device *dev,
+			      struct drm_encoder *encoder,
+			      const struct drm_encoder_funcs *funcs,
+			      int encoder_type, char *name)
+{
+	int ret;
+
+	/* encoder index is used with 32-bit bitmasks */
+	if (WARN_ON(dev->mode_config.num_encoder >= 32))
+		return -EINVAL;
+
+	ret = drm_mode_object_add(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
+	if (ret)
+		return ret;
+
+	encoder->dev = dev;
+	encoder->encoder_type = encoder_type;
+	encoder->funcs = funcs;
+	if (name) {
+		encoder->name = name;
+	} else {
+		encoder->name = kasprintf(GFP_KERNEL, "%s-%d",
+					  drm_encoder_enum_list[encoder_type].name,
+					  encoder->base.id);
+		if (!encoder->name) {
+			ret = -ENOMEM;
+			goto out_put;
+		}
+	}
+
+	INIT_LIST_HEAD(&encoder->bridge_chain);
+	list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
+	encoder->index = dev->mode_config.num_encoder++;
+
+out_put:
+	if (ret)
+		drm_mode_object_unregister(dev, &encoder->base);
+
+	return ret;
+}
+
 /**
  * drm_encoder_init - Init a preallocated encoder
  * @dev: drm device
@@ -111,43 +152,28 @@ int drm_encoder_init(struct drm_device *dev,
 		     const struct drm_encoder_funcs *funcs,
 		     int encoder_type, const char *name, ...)
 {
+	char *namestr = NULL;
 	int ret;
 
-	/* encoder index is used with 32bit bitmasks */
-	if (WARN_ON(dev->mode_config.num_encoder >= 32))
-		return -EINVAL;
-
-	ret = drm_mode_object_add(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
-	if (ret)
-		return ret;
-
-	encoder->dev = dev;
-	encoder->encoder_type = encoder_type;
-	encoder->funcs = funcs;
 	if (name) {
 		va_list ap;
 
 		va_start(ap, name);
-		encoder->name = kvasprintf(GFP_KERNEL, name, ap);
+		namestr = kvasprintf(GFP_KERNEL, name, ap);
 		va_end(ap);
-	} else {
-		encoder->name = kasprintf(GFP_KERNEL, "%s-%d",
-					  drm_encoder_enum_list[encoder_type].name,
-					  encoder->base.id);
-	}
-	if (!encoder->name) {
-		ret = -ENOMEM;
-		goto out_put;
+		if (!namestr)
+			return -ENOMEM;
 	}
 
-	INIT_LIST_HEAD(&encoder->bridge_chain);
-	list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
-	encoder->index = dev->mode_config.num_encoder++;
-
-out_put:
+	ret = __drm_encoder_init(dev, encoder, funcs, encoder_type, namestr);
 	if (ret)
-		drm_mode_object_unregister(dev, &encoder->base);
+		goto err_kfree;
+
+	return 0;
 
+err_kfree:
+	if (name)
+		kfree(namestr);
 	return ret;
 }
 EXPORT_SYMBOL(drm_encoder_init);
-- 
2.25.0

  reply	other threads:[~2020-02-07  8:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-07  8:41 [PATCH 0/6] drm: Provide a simple encoder Thomas Zimmermann
2020-02-07  8:41 ` Thomas Zimmermann [this message]
2020-02-07  8:41 ` [PATCH 2/6] drm: Add drm_simple_encoder_{init,create}() Thomas Zimmermann
2020-02-07 10:33   ` Gerd Hoffmann
2020-02-07 10:50     ` Thomas Zimmermann
2020-02-07 12:31       ` Gerd Hoffmann
2020-02-07 13:37   ` Daniel Vetter
2020-02-07 14:00     ` Ville Syrjälä
2020-02-07 14:02     ` Thomas Zimmermann
2020-02-07 16:26       ` Daniel Vetter
2020-02-07 14:36   ` Noralf Trønnes
2020-02-07 16:25     ` Daniel Vetter
2020-02-10 10:28   ` kbuild test robot
2020-02-07  8:41 ` [PATCH 3/6] drm/ast: Use simple encoder Thomas Zimmermann
2020-02-07  8:41 ` [PATCH 4/6] drm/mgag200: " Thomas Zimmermann
2020-02-07  8:41 ` [PATCH 5/6] drm/qxl: " Thomas Zimmermann
2020-02-10  9:08   ` kbuild test robot
2020-02-07  8:41 ` [PATCH 6/6] drm/simple-pipe: " Thomas Zimmermann

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=20200207084135.4524-2-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@linux.ie \
    --cc=alexander.deucher@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emil.velikov@collabora.com \
    --cc=kraxel@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=noralf@tronnes.org \
    --cc=sam@ravnborg.org \
    --cc=spice-devel@lists.freedesktop.org \
    --cc=virtualization@lists.linux-foundation.org \
    /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