drm/connector: Consolidate Connector Initialization
authorMaxime Ripard <maxime@cerno.tech>
Mon, 11 Jul 2022 17:38:37 +0000 (19:38 +0200)
committerMaxime Ripard <maxime@cerno.tech>
Wed, 13 Jul 2022 08:46:06 +0000 (10:46 +0200)
We're going to add a DRM-managed connector initialization function.
Since we'll need both the with and without the DDC pointer, having a
single function that takes an optional pointer is easier to maintain.

Let's create a static function that will back both existing variants,
and will be reused by the DRM-managed variant.

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lore.kernel.org/r/20220711173939.1132294-8-maxime@cerno.tech
drivers/gpu/drm/drm_connector.c

index 8818fd8..bbdac23 100644 (file)
@@ -214,27 +214,11 @@ void drm_connector_free_work_fn(struct work_struct *work)
        }
 }
 
-/**
- * drm_connector_init - Init a preallocated connector
- * @dev: DRM device
- * @connector: the connector to init
- * @funcs: callbacks for this connector
- * @connector_type: user visible type of the connector
- *
- * Initialises a preallocated connector. Connectors should be
- * subclassed as part of driver connector objects.
- *
- * At driver unload time the driver's &drm_connector_funcs.destroy hook
- * should call drm_connector_cleanup() and free the connector structure.
- * The connector structure should not be allocated with devm_kzalloc().
- *
- * Returns:
- * Zero on success, error code on failure.
- */
-int drm_connector_init(struct drm_device *dev,
-                      struct drm_connector *connector,
-                      const struct drm_connector_funcs *funcs,
-                      int connector_type)
+static int __drm_connector_init(struct drm_device *dev,
+                               struct drm_connector *connector,
+                               const struct drm_connector_funcs *funcs,
+                               int connector_type,
+                               struct i2c_adapter *ddc)
 {
        struct drm_mode_config *config = &dev->mode_config;
        int ret;
@@ -282,6 +266,9 @@ int drm_connector_init(struct drm_device *dev,
                goto out_put_type_id;
        }
 
+       /* provide ddc symlink in sysfs */
+       connector->ddc = ddc;
+
        INIT_LIST_HEAD(&connector->global_connector_list_entry);
        INIT_LIST_HEAD(&connector->probed_modes);
        INIT_LIST_HEAD(&connector->modes);
@@ -338,6 +325,31 @@ out_put:
 
        return ret;
 }
+
+/**
+ * drm_connector_init - Init a preallocated connector
+ * @dev: DRM device
+ * @connector: the connector to init
+ * @funcs: callbacks for this connector
+ * @connector_type: user visible type of the connector
+ *
+ * Initialises a preallocated connector. Connectors should be
+ * subclassed as part of driver connector objects.
+ *
+ * At driver unload time the driver's &drm_connector_funcs.destroy hook
+ * should call drm_connector_cleanup() and free the connector structure.
+ * The connector structure should not be allocated with devm_kzalloc().
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drm_connector_init(struct drm_device *dev,
+                      struct drm_connector *connector,
+                      const struct drm_connector_funcs *funcs,
+                      int connector_type)
+{
+       return __drm_connector_init(dev, connector, funcs, connector_type, NULL);
+}
 EXPORT_SYMBOL(drm_connector_init);
 
 /**
@@ -366,16 +378,7 @@ int drm_connector_init_with_ddc(struct drm_device *dev,
                                int connector_type,
                                struct i2c_adapter *ddc)
 {
-       int ret;
-
-       ret = drm_connector_init(dev, connector, funcs, connector_type);
-       if (ret)
-               return ret;
-
-       /* provide ddc symlink in sysfs */
-       connector->ddc = ddc;
-
-       return ret;
+       return __drm_connector_init(dev, connector, funcs, connector_type, ddc);
 }
 EXPORT_SYMBOL(drm_connector_init_with_ddc);