[PATCH RESEND v2 30/32] drm/vkms: Extract common code for connector initialization

Louis Chauvet
2025-10-29T14:37:46Z

With the introduction of dynamic connector, some code will be shared
between dynamic and static connectors. Extract this part to avoid code
duplication

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/vkms/vkms_connector.c | 44 +++++++++++++++++++++++------------
1 file changed, 29 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_connector.c b/drivers/gpu/drm/vkms/vkms_connector.c
index 1b7ccca2abc0..2c5f04af8784 100644
--- a/drivers/gpu/drm/vkms/vkms_connector.c
+++ b/drivers/gpu/drm/vkms/vkms_connector.c
@@ -108,22 +108,17 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
.best_encoder = vkms_conn_best_encoder,
};

-struct vkms_connector *vkms_connector_init_static(struct vkms_device *vkmsdev,
- struct vkms_config_connector *connector_cfg)
+/**
+ * vkms_connector_init() - Common initialization of vkms connector
+ * @vkmsdev: VKMS device containing the device
+ * @connector: VKMS connector to init. @connector->base must be
+ * already initialized by DRM core.
+ * @connector_cfg: Connector configuration to apply
+ */
+static void vkms_connector_init(struct vkms_device *vkmsdev,
+ struct vkms_connector *connector,
+ const struct vkms_config_connector *connector_cfg)
{
- struct drm_device *dev = &vkmsdev->drm;
- struct vkms_connector *connector;
- int ret;
-
- connector = drmm_kzalloc(dev, sizeof(*connector), GFP_KERNEL);
- if (!connector)
- return ERR_PTR(-ENOMEM);
-
- ret = drmm_connector_init(dev, &connector->base, &vkms_connector_funcs,
- vkms_config_connector_get_type(connector_cfg), NULL);
- if (ret)
- return ERR_PTR(ret);
-
if (vkms_config_connector_get_supported_colorspaces(connector_cfg)) {
if (connector_cfg->type == DRM_MODE_CONNECTOR_HDMIA) {
drm_mode_create_hdmi_colorspace_property(&connector->base,
@@ -143,6 +138,25 @@ struct vkms_connector *vkms_connector_init_static(struct vkms_device *vkmsdev,

if (vkms_config_connector_get_edid_enabled(connector_cfg))
drm_connector_attach_edid_property(&connector->base);
+}
+
+struct vkms_connector *vkms_connector_init_static(struct vkms_device *vkmsdev,
+ struct vkms_config_connector *connector_cfg)
+{
+ struct drm_device *dev = &vkmsdev->drm;
+ struct vkms_connector *connector;
+ int ret;
+
+ connector = drmm_kzalloc(dev, sizeof(*connector), GFP_KERNEL);
+ if (!connector)
+ return ERR_PTR(-ENOMEM);
+
+ ret = drmm_connector_init(dev, &connector->base, &vkms_connector_funcs,
+ vkms_config_connector_get_type(connector_cfg), NULL);
+ if (ret)
+ return ERR_PTR(ret);
+
+ vkms_connector_init(vkmsdev, connector, connector_cfg);

return connector;
}

--
2.51.0