Commit 2abdd3137e78adca69b0722307aa2ef89f2cf3b6

Authored by Jani Nikula
Committed by Dave Airlie
1 parent b838058083

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.ru
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>

Showing 2 changed files with 22 additions and 16 deletions Side-by-side Diff

drivers/gpu/drm/drm_crtc.c
... ... @@ -277,21 +277,11 @@
277 277  
278 278 /**
279 279 * drm_get_connector_name - return a string for connector
280   - * @connector: connector to compute name of
281   - *
282   - * Note that the buffer used by this function is globally shared and owned by
283   - * the function itself.
284   - *
285   - * FIXME: This isn't really multithreading safe.
  280 + * @connector: the connector to get name for
286 281 */
287 282 const char *drm_get_connector_name(const struct drm_connector *connector)
288 283 {
289   - static char buf[32];
290   -
291   - snprintf(buf, 32, "%s-%d",
292   - drm_connector_enum_list[connector->connector_type].name,
293   - connector->connector_type_id);
294   - return buf;
  284 + return connector->name;
295 285 }
296 286 EXPORT_SYMBOL(drm_get_connector_name);
297 287  
... ... @@ -824,7 +814,7 @@
824 814  
825 815 ret = drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR);
826 816 if (ret)
827   - goto out;
  817 + goto out_unlock;
828 818  
829 819 connector->base.properties = &connector->properties;
830 820 connector->dev = dev;
831 821  
... ... @@ -834,9 +824,17 @@
834 824 ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
835 825 if (connector->connector_type_id < 0) {
836 826 ret = connector->connector_type_id;
837   - drm_mode_object_put(dev, &connector->base);
838   - goto out;
  827 + goto out_put;
839 828 }
  829 + connector->name =
  830 + kasprintf(GFP_KERNEL, "%s-%d",
  831 + drm_connector_enum_list[connector_type].name,
  832 + connector->connector_type_id);
  833 + if (!connector->name) {
  834 + ret = -ENOMEM;
  835 + goto out_put;
  836 + }
  837 +
840 838 INIT_LIST_HEAD(&connector->probed_modes);
841 839 INIT_LIST_HEAD(&connector->modes);
842 840 connector->edid_blob_ptr = NULL;
... ... @@ -853,7 +851,11 @@
853 851 drm_object_attach_property(&connector->base,
854 852 dev->mode_config.dpms_property, 0);
855 853  
856   - out:
  854 +out_put:
  855 + if (ret)
  856 + drm_mode_object_put(dev, &connector->base);
  857 +
  858 +out_unlock:
857 859 drm_modeset_unlock_all(dev);
858 860  
859 861 return ret;
... ... @@ -881,6 +883,8 @@
881 883 connector->connector_type_id);
882 884  
883 885 drm_mode_object_put(dev, &connector->base);
  886 + kfree(connector->name);
  887 + connector->name = NULL;
884 888 list_del(&connector->head);
885 889 dev->mode_config.num_connector--;
886 890 }
include/drm/drm_crtc.h
... ... @@ -444,6 +444,7 @@
444 444 * @attr: sysfs attributes
445 445 * @head: list management
446 446 * @base: base KMS object
  447 + * @name: connector name
447 448 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
448 449 * @connector_type_id: index into connector type enum
449 450 * @interlace_allowed: can this connector handle interlaced modes?
... ... @@ -482,6 +483,7 @@
482 483  
483 484 struct drm_mode_object base;
484 485  
  486 + char *name;
485 487 int connector_type;
486 488 int connector_type_id;
487 489 bool interlace_allowed;