From patchwork Fri Oct 22 11:52:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francisco Jerez X-Patchwork-Id: 273791 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9MBqTlB011235 for ; Fri, 22 Oct 2010 11:52:51 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 23EAE9E982 for ; Fri, 22 Oct 2010 04:52:29 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.riseup.net (mx1.riseup.net [204.13.164.18]) by gabe.freedesktop.org (Postfix) with ESMTP id CFF559E7D1 for ; Fri, 22 Oct 2010 04:52:20 -0700 (PDT) Received: from auk.riseup.net (auk-pn.riseup.net [10.0.1.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Gandi Standard SSL CA" (verified OK)) by mx1.riseup.net (Postfix) with ESMTPS id 7C22625EA42; Fri, 22 Oct 2010 04:52:20 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: currojerez@auk.riseup.net) with ESMTPSA id 072714943 From: Francisco Jerez To: Dave Airlie Subject: [PATCH 1/2] drm/kms: Lock mode_config.mutex consistently from the sysfs handling code. Date: Fri, 22 Oct 2010 13:52:12 +0200 Message-Id: <1287748333-4990-1-git-send-email-currojerez@riseup.net> X-Mailer: git-send-email 1.6.4.4 X-Virus-Scanned: clamav-milter 0.96.3 at mx1 X-Virus-Status: Clean Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 22 Oct 2010 11:52:51 +0000 (UTC) diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c index 85da4c4..25a9d9e 100644 --- a/drivers/gpu/drm/drm_sysfs.c +++ b/drivers/gpu/drm/drm_sysfs.c @@ -157,9 +157,13 @@ static ssize_t status_show(struct device *device, char *buf) { struct drm_connector *connector = to_drm_connector(device); + struct drm_device *dev = connector->dev; enum drm_connector_status status; + mutex_lock(&dev->mode_config.mutex); status = connector->funcs->detect(connector, true); + mutex_unlock(&dev->mode_config.mutex); + return snprintf(buf, PAGE_SIZE, "%s\n", drm_get_connector_status_name(status)); } @@ -173,9 +177,11 @@ static ssize_t dpms_show(struct device *device, uint64_t dpms_status; int ret; + mutex_lock(&dev->mode_config.mutex); ret = drm_connector_property_get_value(connector, dev->mode_config.dpms_property, &dpms_status); + mutex_unlock(&dev->mode_config.mutex); if (ret) return 0; @@ -199,25 +205,27 @@ static ssize_t edid_show(struct file *filp, struct kobject *kobj, { struct device *connector_dev = container_of(kobj, struct device, kobj); struct drm_connector *connector = to_drm_connector(connector_dev); + struct drm_device *dev = connector->dev; unsigned char *edid; - size_t size; + size_t size, n = 0; + mutex_lock(&dev->mode_config.mutex); if (!connector->edid_blob_ptr) - return 0; + goto out; edid = connector->edid_blob_ptr->data; size = connector->edid_blob_ptr->length; if (!edid) - return 0; + goto out; if (off >= size) - return 0; - - if (off + count > size) - count = size - off; - memcpy(buf, edid + off, count); + goto out; - return count; + n = min(count, size - (size_t)off); + memcpy(buf, edid + off, n); +out: + mutex_unlock(&dev->mode_config.mutex); + return n; } static ssize_t modes_show(struct device *device, @@ -225,13 +233,16 @@ static ssize_t modes_show(struct device *device, char *buf) { struct drm_connector *connector = to_drm_connector(device); + struct drm_device *dev = connector->dev; struct drm_display_mode *mode; int written = 0; + mutex_lock(&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(&dev->mode_config.mutex); return written; } @@ -245,7 +256,9 @@ static ssize_t subconnector_show(struct device *device, struct drm_property *prop = NULL; uint64_t subconnector; int is_tv = 0; - int ret; + int ret = 0; + + mutex_lock(&dev->mode_config.mutex); switch (connector->connector_type) { case DRM_MODE_CONNECTOR_DVII: @@ -260,21 +273,24 @@ static ssize_t subconnector_show(struct device *device, break; default: DRM_ERROR("Wrong connector type for this property\n"); - return 0; + goto out; } if (!prop) { DRM_ERROR("Unable to find subconnector property\n"); - return 0; + goto out; } ret = drm_connector_property_get_value(connector, prop, &subconnector); if (ret) - return 0; + goto out; - return snprintf(buf, PAGE_SIZE, "%s", is_tv ? - drm_get_tv_subconnector_name((int)subconnector) : - drm_get_dvi_i_subconnector_name((int)subconnector)); + ret = snprintf(buf, PAGE_SIZE, "%s", is_tv ? + drm_get_tv_subconnector_name((int)subconnector) : + drm_get_dvi_i_subconnector_name((int)subconnector)); +out: + mutex_unlock(&dev->mode_config.mutex); + return ret; } static ssize_t select_subconnector_show(struct device *device, @@ -286,7 +302,9 @@ static ssize_t select_subconnector_show(struct device *device, struct drm_property *prop = NULL; uint64_t subconnector; int is_tv = 0; - int ret; + int ret = 0; + + mutex_lock(&dev->mode_config.mutex); switch (connector->connector_type) { case DRM_MODE_CONNECTOR_DVII: @@ -301,21 +319,24 @@ static ssize_t select_subconnector_show(struct device *device, break; default: DRM_ERROR("Wrong connector type for this property\n"); - return 0; + goto out; } if (!prop) { DRM_ERROR("Unable to find select subconnector property\n"); - return 0; + goto out; } ret = drm_connector_property_get_value(connector, prop, &subconnector); if (ret) - return 0; + goto out; - return snprintf(buf, PAGE_SIZE, "%s", is_tv ? - drm_get_tv_select_name((int)subconnector) : - drm_get_dvi_i_select_name((int)subconnector)); + ret = snprintf(buf, PAGE_SIZE, "%s", is_tv ? + drm_get_tv_select_name((int)subconnector) : + drm_get_dvi_i_select_name((int)subconnector)); +out: + mutex_unlock(&dev->mode_config.mutex); + return ret; } static struct device_attribute connector_attrs[] = {