drm/sysfs: Grab lock for edid/modes_show

We chase pointers/lists without taking the locks protecting them,
which isn't that good.

Fix it.

v2: Actually unlock properly, spotted by Julia.

v3: Put the label _before_ the mutex_unlock (Emil)

Cc: Emil Velikov <emil.l.velikov@gmail.com>
Cc: Julia Lawall <julia.lawall@lip6.fr>
Link: http://patchwork.freedesktop.org/patch/msgid/1443783662-23066-1-git-send-email-daniel.vetter@ffwll.ch
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Daniel Vetter 2015-10-02 13:01:02 +02:00
Родитель f980a71a2b
Коммит a48a62bc92
1 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -256,23 +256,29 @@ static ssize_t edid_show(struct file *filp, struct kobject *kobj,
struct drm_connector *connector = to_drm_connector(connector_dev); struct drm_connector *connector = to_drm_connector(connector_dev);
unsigned char *edid; unsigned char *edid;
size_t size; size_t size;
ssize_t ret = 0;
mutex_lock(&connector->dev->mode_config.mutex);
if (!connector->edid_blob_ptr) if (!connector->edid_blob_ptr)
return 0; goto unlock;
edid = connector->edid_blob_ptr->data; edid = connector->edid_blob_ptr->data;
size = connector->edid_blob_ptr->length; size = connector->edid_blob_ptr->length;
if (!edid) if (!edid)
return 0; goto unlock;
if (off >= size) if (off >= size)
return 0; goto unlock;
if (off + count > size) if (off + count > size)
count = size - off; count = size - off;
memcpy(buf, edid + off, count); memcpy(buf, edid + off, count);
return count; ret = count;
unlock:
mutex_unlock(&connector->dev->mode_config.mutex);
return ret;
} }
static ssize_t modes_show(struct device *device, static ssize_t modes_show(struct device *device,
@ -283,10 +289,12 @@ static ssize_t modes_show(struct device *device,
struct drm_display_mode *mode; struct drm_display_mode *mode;
int written = 0; int written = 0;
mutex_lock(&connector->dev->mode_config.mutex);
list_for_each_entry(mode, &connector->modes, head) { list_for_each_entry(mode, &connector->modes, head) {
written += snprintf(buf + written, PAGE_SIZE - written, "%s\n", written += snprintf(buf + written, PAGE_SIZE - written, "%s\n",
mode->name); mode->name);
} }
mutex_unlock(&connector->dev->mode_config.mutex);
return written; return written;
} }