All of lore.kernel.org
 help / color / mirror / 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>,
	Daniel Vetter <daniel.vetter@intel.com>
Subject: [PATCH 06/15] drm: Drop modeset_lock_all from the getproperty ioctl
Date: Mon,  3 Apr 2017 10:32:55 +0200	[thread overview]
Message-ID: <20170403083304.9083-7-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <20170403083304.9083-1-daniel.vetter@ffwll.ch>

Properties, i.e. the struct drm_property specifying the type and value
range of a property, not the instantiation on a given object, are
invariant over the lifetime of a driver.

Hence no locking at all is needed, we can just remove it.

While at it give the function some love and simplify it, to get it
under the 80 char limit:
- Straighten the loops to reduce the nesting.
- use u64_to_user_ptr casting helper
- use put_user for fixed u64 copies.

Note there's a small behavioural change in that we now copy parts of
the values to userspace if the arrays are a bit too small. Since
userspace will immediately retry anyway, this doesn't matter.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 drivers/gpu/drm/drm_property.c | 72 +++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index b17959c3e099..3feef0659940 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -442,8 +442,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
 	struct drm_property *property;
 	int enum_count = 0;
 	int value_count = 0;
-	int ret = 0, i;
-	int copied;
+	int i, copied;
 	struct drm_property_enum *prop_enum;
 	struct drm_mode_property_enum __user *enum_ptr;
 	uint64_t __user *values_ptr;
@@ -451,55 +450,43 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
 		return -EINVAL;
 
-	drm_modeset_lock_all(dev);
 	property = drm_property_find(dev, out_resp->prop_id);
-	if (!property) {
-		ret = -ENOENT;
-		goto done;
-	}
-
-	if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) ||
-			drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
-		list_for_each_entry(prop_enum, &property->enum_list, head)
-			enum_count++;
-	}
-
-	value_count = property->num_values;
+	if (!property)
+		return -ENOENT;
 
 	strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN);
 	out_resp->name[DRM_PROP_NAME_LEN-1] = 0;
 	out_resp->flags = property->flags;
 
-	if ((out_resp->count_values >= value_count) && value_count) {
-		values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
-		for (i = 0; i < value_count; i++) {
-			if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
-				ret = -EFAULT;
-				goto done;
-			}
+	value_count = property->num_values;
+	values_ptr = u64_to_user_ptr(out_resp->values_ptr);
+
+	for (i = 0; i < value_count; i++) {
+		if (i < out_resp->count_values &&
+		    put_user(property->values[i], values_ptr + i)) {
+			return -EFAULT;
 		}
 	}
 	out_resp->count_values = value_count;
 
+	copied = 0;
+	enum_ptr = u64_to_user_ptr(out_resp->enum_blob_ptr);
+
 	if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) ||
-			drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
-		if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
-			copied = 0;
-			enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
-			list_for_each_entry(prop_enum, &property->enum_list, head) {
-
-				if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
-					ret = -EFAULT;
-					goto done;
-				}
-
-				if (copy_to_user(&enum_ptr[copied].name,
-						 &prop_enum->name, DRM_PROP_NAME_LEN)) {
-					ret = -EFAULT;
-					goto done;
-				}
-				copied++;
-			}
+	    drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
+		list_for_each_entry(prop_enum, &property->enum_list, head) {
+			enum_count++;
+			if (out_resp->count_enum_blobs <= enum_count)
+				continue;
+
+			if (copy_to_user(&enum_ptr[copied].value,
+					 &prop_enum->value, sizeof(uint64_t)))
+				return -EFAULT;
+
+			if (copy_to_user(&enum_ptr[copied].name,
+					 &prop_enum->name, DRM_PROP_NAME_LEN))
+				return -EFAULT;
+			copied++;
 		}
 		out_resp->count_enum_blobs = enum_count;
 	}
@@ -514,9 +501,8 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
 	 */
 	if (drm_property_type_is(property, DRM_MODE_PROP_BLOB))
 		out_resp->count_enum_blobs = 0;
-done:
-	drm_modeset_unlock_all(dev);
-	return ret;
+
+	return 0;
 }
 
 static void drm_property_free_blob(struct kref *kref)
-- 
2.11.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2017-04-03  8:32 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-03  8:32 [PATCH 00/15] acquire ctx wire-up, part 2 Daniel Vetter
2017-04-03  8:32 ` [PATCH 01/15] drm: Make drm_modeset_lock_crtc internal Daniel Vetter
2017-04-03 22:00   ` kbuild test robot
2017-04-03  8:32 ` [PATCH 02/15] drm: Remove drm_modeset_(un)lock_crtc Daniel Vetter
2017-04-03 22:13   ` kbuild test robot
2017-04-04  5:39     ` [Intel-gfx] " Daniel Vetter
2017-04-14 16:20       ` Mike Lothian
2017-04-18  6:32         ` [Intel-gfx] " Daniel Vetter
2017-04-03  8:32 ` [PATCH 03/15] drm: Remove drm_modeset_legacy_acquire_ctx and crtc->acquire_ctx Daniel Vetter
2017-04-03  8:32 ` [PATCH 04/15] drm/atomic-helper: remove modeset_lock_all from helper_resume Daniel Vetter
2017-04-05 19:31   ` Alex Deucher
2017-04-03  8:32 ` [PATCH 05/15] drm: drop modeset_lock_all from drm_state_info Daniel Vetter
2017-04-03  8:32 ` Daniel Vetter [this message]
2017-04-13 20:03   ` [PATCH 06/15] drm: Drop modeset_lock_all from the getproperty ioctl Alex Deucher
2017-04-13 20:18     ` [Intel-gfx] " Chris Wilson
2017-04-03  8:32 ` [PATCH 07/15] drm: Only take crtc lock in get_gamma ioctl Daniel Vetter
2017-04-03  8:32 ` [PATCH 08/15] drm/i915: Nuke intel_atomic_legacy_gamma_set Daniel Vetter
2017-04-04 10:44   ` Maarten Lankhorst
2017-04-05 11:16     ` Daniel Vetter
2017-04-03  8:32 ` [PATCH 09/15] drm/msm: Nerf zpos property Daniel Vetter
2017-04-05 13:24   ` Daniel Vetter
2017-04-03  8:32 ` [PATCH 10/15] drm/fb-helper: Give up on kgdb for atomic drivers Daniel Vetter
2017-04-03  8:33 ` [PATCH 11/15] drm: Add explicit acquire ctx handling around ->gamma_set Daniel Vetter
2017-04-03  8:33 ` [PATCH 12/15] drm: Add acquire ctx to ->gamma_set hook Daniel Vetter
2017-04-03 18:28   ` Sinclair Yeh
2017-04-06 16:51   ` Eric Anholt
2017-04-06 18:00     ` Daniel Vetter
2017-04-03  8:33 ` [PATCH 13/15] drm/atomic-helper: Remove legacy backoff hack from gamma_set Daniel Vetter
2017-04-03  8:33 ` [PATCH 14/15] drm: extract legacy framebuffer remove Daniel Vetter
2017-04-03  8:33 ` [PATCH 15/15] drm/fb-helper: Extract _legacy kms functions Daniel Vetter
2017-04-03  9:28 ` ✓ Fi.CI.BAT: success for acquire ctx wire-up, part 2 Patchwork
2017-04-05 19:45 ` [PATCH 00/15] " Alex Deucher
2017-04-06  8:23   ` Daniel Vetter

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=20170403083304.9083-7-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.