From: gouhao gouhao@uniontech.com
mainline inclusion from mainline-v5.14.0-rc7 commit 100163df420305b78153e6f5ec10c90d755acee3 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I469VQ CVE: NA
----------------------------------------
Allow passing ddc adapter pointer to the init function. Even if drm_connector_init() sometime in the future decides to e.g. memset() all connector fields to zeros, the newly added function ensures that at its completion the ddc member of connector is correctly set.
Signed-off-by: Andrzej Pietrasiewicz andrzej.p@collabora.com Acked-by: Thomas Zimmermann tzimmermann@suse.de Reviewed-by: Emil Velikov emil.velikov@collabora.com Reviewed-by: Sam Ravnborg sam@ravnborg.org Signed-off-by: Neil Armstrong narmstrong@baylibre.com Link: https://patchwork.freedesktop.org/patch/msgid/3915224ae895240fd0973cf7f06b9d...
Signed-off-by: gouhao gouhao@uniontech.com --- drivers/gpu/drm/drm_connector.c | 35 +++++++++++++++++++++++++++++++++ include/drm/drm_connector.h | 7 +++++++ 2 files changed, 42 insertions(+)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index 6011d769d..ed49d0e93 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -290,6 +290,41 @@ out_put: } EXPORT_SYMBOL(drm_connector_init);
+/** + * drm_connector_init_with_ddc - 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 + * @ddc: pointer to the associated ddc adapter + * + * Initialises a preallocated connector. Connectors should be + * subclassed as part of driver connector objects. + * + * Ensures that the ddc field of the connector is correctly set. + * + * Returns: + * Zero on success, error code on failure. + */ +int drm_connector_init_with_ddc(struct drm_device *dev, + struct drm_connector *connector, + const struct drm_connector_funcs *funcs, + 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; +} +EXPORT_SYMBOL(drm_connector_init_with_ddc); + /** * drm_connector_attach_encoder - attach a connector to an encoder * @connector: connector to attach diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index d8f4e66fb..db9b04888 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -1006,6 +1006,8 @@ struct drm_connector { * this field, then an appropriate symbolic link is created in connector * sysfs directory to make it easy for the user to tell which i2c * adapter is for a particular display. + * + * The field should be set by calling drm_connector_init_with_ddc(). */ struct i2c_adapter *ddc;
@@ -1094,6 +1096,11 @@ int drm_connector_init(struct drm_device *dev, struct drm_connector *connector, const struct drm_connector_funcs *funcs, int connector_type); +int drm_connector_init_with_ddc(struct drm_device *dev, + struct drm_connector *connector, + const struct drm_connector_funcs *funcs, + int connector_type, + struct i2c_adapter *ddc); int drm_connector_register(struct drm_connector *connector); void drm_connector_unregister(struct drm_connector *connector); int drm_connector_attach_encoder(struct drm_connector *connector,