Skip to content

Commit

Permalink
drm: Make drm_connector_register() safe against multiple calls
Browse files Browse the repository at this point in the history
Protect against drivers that may try to register the connector more
than once, or who try to unregister it multiple times.

Signed-off-by: Chris Wilson <[email protected]>
Cc: Dave Airlie <[email protected]>
Cc: [email protected]
Reviewed-by: Daniel Vetter <[email protected]>
Signed-off-by: Daniel Vetter <[email protected]>
Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
ickle authored and danvet committed Jun 17, 2016
1 parent aaf285e commit 40daac6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/gpu/drm/drm_crtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,9 @@ int drm_connector_register(struct drm_connector *connector)
{
int ret;

if (connector->registered)
return 0;

ret = drm_sysfs_connector_add(connector);
if (ret)
return ret;
Expand All @@ -1001,6 +1004,7 @@ int drm_connector_register(struct drm_connector *connector)

drm_mode_object_register(connector->dev, &connector->base);

connector->registered = true;
return 0;

err_debugfs:
Expand All @@ -1019,11 +1023,16 @@ EXPORT_SYMBOL(drm_connector_register);
*/
void drm_connector_unregister(struct drm_connector *connector)
{
if (!connector->registered)
return;

if (connector->funcs->early_unregister)
connector->funcs->early_unregister(connector);

drm_sysfs_connector_remove(connector);
drm_debugfs_connector_remove(connector);

connector->registered = false;
}
EXPORT_SYMBOL(drm_connector_unregister);

Expand Down
2 changes: 2 additions & 0 deletions include/drm/drm_crtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,7 @@ struct drm_encoder {
* @interlace_allowed: can this connector handle interlaced modes?
* @doublescan_allowed: can this connector handle doublescan?
* @stereo_allowed: can this connector handle stereo modes?
* @registered: is this connector exposed (registered) with userspace?
* @modes: modes available on this connector (from fill_modes() + user)
* @status: one of the drm_connector_status enums (connected, not, or unknown)
* @probed_modes: list of modes derived directly from the display
Expand Down Expand Up @@ -1249,6 +1250,7 @@ struct drm_connector {
bool interlace_allowed;
bool doublescan_allowed;
bool stereo_allowed;
bool registered;
struct list_head modes; /* list of modes on this connector */

enum drm_connector_status status;
Expand Down

0 comments on commit 40daac6

Please sign in to comment.