Commit 2abdd313 authored by Jani Nikula's avatar Jani Nikula Committed by Dave Airlie

drm: store connector name in connector struct (v2)

This makes drm_get_connector_name() thread safe.

[airlied: fix to build.]

Reference: http://lkml.kernel.org/r/645ee6e22cad47d38a2b35c21c8d5fe3@DC1-MBX-01.ptsecurity.ruSigned-off-by: default avatarJani Nikula <jani.nikula@intel.com>
Reviewed-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent b8380580
...@@ -277,21 +277,11 @@ EXPORT_SYMBOL(drm_get_encoder_name); ...@@ -277,21 +277,11 @@ EXPORT_SYMBOL(drm_get_encoder_name);
/** /**
* drm_get_connector_name - return a string for connector * drm_get_connector_name - return a string for connector
* @connector: connector to compute name of * @connector: the connector to get name for
*
* Note that the buffer used by this function is globally shared and owned by
* the function itself.
*
* FIXME: This isn't really multithreading safe.
*/ */
const char *drm_get_connector_name(const struct drm_connector *connector) const char *drm_get_connector_name(const struct drm_connector *connector)
{ {
static char buf[32]; return connector->name;
snprintf(buf, 32, "%s-%d",
drm_connector_enum_list[connector->connector_type].name,
connector->connector_type_id);
return buf;
} }
EXPORT_SYMBOL(drm_get_connector_name); EXPORT_SYMBOL(drm_get_connector_name);
...@@ -824,7 +814,7 @@ int drm_connector_init(struct drm_device *dev, ...@@ -824,7 +814,7 @@ int drm_connector_init(struct drm_device *dev,
ret = drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR); ret = drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR);
if (ret) if (ret)
goto out; goto out_unlock;
connector->base.properties = &connector->properties; connector->base.properties = &connector->properties;
connector->dev = dev; connector->dev = dev;
...@@ -834,9 +824,17 @@ int drm_connector_init(struct drm_device *dev, ...@@ -834,9 +824,17 @@ int drm_connector_init(struct drm_device *dev,
ida_simple_get(connector_ida, 1, 0, GFP_KERNEL); ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
if (connector->connector_type_id < 0) { if (connector->connector_type_id < 0) {
ret = connector->connector_type_id; ret = connector->connector_type_id;
drm_mode_object_put(dev, &connector->base); goto out_put;
goto out;
} }
connector->name =
kasprintf(GFP_KERNEL, "%s-%d",
drm_connector_enum_list[connector_type].name,
connector->connector_type_id);
if (!connector->name) {
ret = -ENOMEM;
goto out_put;
}
INIT_LIST_HEAD(&connector->probed_modes); INIT_LIST_HEAD(&connector->probed_modes);
INIT_LIST_HEAD(&connector->modes); INIT_LIST_HEAD(&connector->modes);
connector->edid_blob_ptr = NULL; connector->edid_blob_ptr = NULL;
...@@ -853,7 +851,11 @@ int drm_connector_init(struct drm_device *dev, ...@@ -853,7 +851,11 @@ int drm_connector_init(struct drm_device *dev,
drm_object_attach_property(&connector->base, drm_object_attach_property(&connector->base,
dev->mode_config.dpms_property, 0); dev->mode_config.dpms_property, 0);
out: out_put:
if (ret)
drm_mode_object_put(dev, &connector->base);
out_unlock:
drm_modeset_unlock_all(dev); drm_modeset_unlock_all(dev);
return ret; return ret;
...@@ -881,6 +883,8 @@ void drm_connector_cleanup(struct drm_connector *connector) ...@@ -881,6 +883,8 @@ void drm_connector_cleanup(struct drm_connector *connector)
connector->connector_type_id); connector->connector_type_id);
drm_mode_object_put(dev, &connector->base); drm_mode_object_put(dev, &connector->base);
kfree(connector->name);
connector->name = NULL;
list_del(&connector->head); list_del(&connector->head);
dev->mode_config.num_connector--; dev->mode_config.num_connector--;
} }
......
...@@ -444,6 +444,7 @@ struct drm_encoder { ...@@ -444,6 +444,7 @@ struct drm_encoder {
* @attr: sysfs attributes * @attr: sysfs attributes
* @head: list management * @head: list management
* @base: base KMS object * @base: base KMS object
* @name: connector name
* @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
* @connector_type_id: index into connector type enum * @connector_type_id: index into connector type enum
* @interlace_allowed: can this connector handle interlaced modes? * @interlace_allowed: can this connector handle interlaced modes?
...@@ -482,6 +483,7 @@ struct drm_connector { ...@@ -482,6 +483,7 @@ struct drm_connector {
struct drm_mode_object base; struct drm_mode_object base;
char *name;
int connector_type; int connector_type;
int connector_type_id; int connector_type_id;
bool interlace_allowed; bool interlace_allowed;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment