dri-devel Archive on lore.kernel.org
 help / color / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: DRI Development <dri-devel@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Subject: [PATCH 2/3] drm/sysfs: Grab lock for edid/modes_show
Date: Tue, 29 Sep 2015 10:06:32 +0200
Message-ID: <1443513993-5228-2-git-send-email-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <1443513993-5228-1-git-send-email-daniel.vetter@ffwll.ch>

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

Fix it.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/drm_sysfs.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index 7506de0a75b4..d55e0d7a610d 100644
--- a/drivers/gpu/drm/drm_sysfs.c
+++ b/drivers/gpu/drm/drm_sysfs.c
@@ -261,23 +261,29 @@ static ssize_t edid_show(struct file *filp, struct kobject *kobj,
 	struct drm_connector *connector = to_drm_connector(connector_dev);
 	unsigned char *edid;
 	size_t size;
+	ssize_t ret = 0;
 
+	mutex_lock(&connector->dev->mode_config.mutex);
 	if (!connector->edid_blob_ptr)
-		return 0;
+		goto unlock;
 
 	edid = connector->edid_blob_ptr->data;
 	size = connector->edid_blob_ptr->length;
 	if (!edid)
-		return 0;
+		goto unlock;
 
 	if (off >= size)
-		return 0;
+		goto unlock;
 
 	if (off + count > size)
 		count = size - off;
 	memcpy(buf, edid + off, count);
 
-	return count;
+	ret = count;
+	mutex_lock(&connector->dev->mode_config.mutex);
+unlock:
+
+	return ret;
 }
 
 static ssize_t modes_show(struct device *device,
@@ -288,10 +294,12 @@ static ssize_t modes_show(struct device *device,
 	struct drm_display_mode *mode;
 	int written = 0;
 
+	mutex_lock(&connector->dev->mode_config.mutex);
 	list_for_each_entry(mode, &connector->modes, head) {
 		written += snprintf(buf + written, PAGE_SIZE - written, "%s\n",
 				    mode->name);
 	}
+	mutex_unlock(&connector->dev->mode_config.mutex);
 
 	return written;
 }
-- 
2.5.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply index

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29  7:37 [PATCH] drm: Fix locking for sysfs dpms file Daniel Vetter
2015-09-29  7:56 ` Daniel Vetter
2015-09-29 13:30   ` Jani Nikula
2015-09-29 14:37   ` Jens Axboe
2015-09-29  8:06 ` [PATCH 1/3] drm/sysfs: Annote lockless show functions with READ_ONCE Daniel Vetter
2015-09-29  8:06   ` Daniel Vetter [this message]
2015-10-02  8:39     ` [PATCH] drm/sysfs: Grab lock for edid/modes_show Daniel Vetter
2015-10-02 11:01       ` Daniel Vetter
2015-10-02 12:08         ` Emil Velikov
2015-11-19 16:22           ` Daniel Vetter
2015-10-02 15:02       ` Julia Lawall
2015-09-29  8:06   ` [PATCH 3/3] drm/sysfs: Nuke TV/DVI property files Daniel Vetter
     [not found] <201509292218.OqhB7qjW%fengguang.wu@intel.com>
2015-09-29 14:47 ` [PATCH 2/3] drm/sysfs: Grab lock for edid/modes_show Julia Lawall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443513993-5228-2-git-send-email-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

dri-devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dri-devel/0 dri-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dri-devel dri-devel/ https://lore.kernel.org/dri-devel \
		dri-devel@lists.freedesktop.org
	public-inbox-index dri-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.freedesktop.lists.dri-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git