]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
drm: Warn if plane/crtc/encoder/connector index exceeds our 32bit bitmasks
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Thu, 25 Jan 2018 13:30:20 +0000 (15:30 +0200)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Mon, 29 Jan 2018 16:46:53 +0000 (18:46 +0200)
We use 32bit bitmasks to track planes/crtcs/encoders/connectors.
Naturally we can only do that if the index of those objects stays
below 32. Issue a warning whenever we exceed that limit, hopefully
prompting someone to fix the problem.

For connectors the issue is a bit more complicated as they can
be created/destroyed at runtime due to MST. So the problem is no
longer a purely theoretical programmer error. As the connector
indexes are allocated via ida, we can simply limit the maximum
value the ida is allowed to hand out. The error handling is already
in place.

v2: Return an error to the caller (Harry)
v3: Print a debug message so that we know what happened (Maarten)

Cc: Harry Wentland <harry.wentland@amd.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180125133020.23845-1-ville.syrjala@linux.intel.com
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
drivers/gpu/drm/drm_connector.c
drivers/gpu/drm/drm_crtc.c
drivers/gpu/drm/drm_encoder.c
drivers/gpu/drm/drm_plane.c

index e6a21e69059cdc312a6b079f75b9716345f3f4db..d6a7eba087a0a98faa2cc25f0e0cf6357b5542cc 100644 (file)
@@ -205,9 +205,14 @@ int drm_connector_init(struct drm_device *dev,
        connector->dev = dev;
        connector->funcs = funcs;
 
-       ret = ida_simple_get(&config->connector_ida, 0, 0, GFP_KERNEL);
-       if (ret < 0)
+       /* connector index is used with 32bit bitmasks */
+       ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL);
+       if (ret < 0) {
+               DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
+                             drm_connector_enum_list[connector_type].name,
+                             ret);
                goto out_put;
+       }
        connector->index = ret;
        ret = 0;
 
index f0556e654116760a754dae15ad53b65338ade433..5b4be382a1d7660046945e664f10970aa45c18a0 100644 (file)
@@ -282,6 +282,10 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
        WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY);
        WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR);
 
+       /* crtc index is used with 32bit bitmasks */
+       if (WARN_ON(config->num_crtc >= 32))
+               return -EINVAL;
+
        crtc->dev = dev;
        crtc->funcs = funcs;
 
index 59e0ebe733f8e847994e23e4b53aca484b88edbc..273e1c59c54a0e98d8a0738dfae58e8588f1668e 100644 (file)
@@ -110,6 +110,10 @@ int drm_encoder_init(struct drm_device *dev,
 {
        int ret;
 
+       /* encoder index is used with 32bit bitmasks */
+       if (WARN_ON(dev->mode_config.num_encoder >= 32))
+               return -EINVAL;
+
        ret = drm_mode_object_add(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
        if (ret)
                return ret;
index 2c90519576a3e8b63a4c8361f18672db853ebcec..22b54663b6e7e6aa69f81accda0971ceb698af17 100644 (file)
@@ -173,6 +173,10 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
        unsigned int format_modifier_count = 0;
        int ret;
 
+       /* plane index is used with 32bit bitmasks */
+       if (WARN_ON(config->num_total_plane >= 32))
+               return -EINVAL;
+
        ret = drm_mode_object_add(dev, &plane->base, DRM_MODE_OBJECT_PLANE);
        if (ret)
                return ret;