From a92cf3cc781783016dce93c2ec152519cc7f7f8e Mon Sep 17 00:00:00 2001 From: Florian Mickler Date: Mon, 6 Apr 2009 13:18:46 +0200 Subject: [PATCH] Fix wrong interpretation of copy_to_user() result. Pavel Emelyanov says in commit 653252c2302cdf2dfbca66a7e177f7db783f9efa ( net: Fix wrong interpretation of some copy_to_user() results. ) : "I found some places, that erroneously return the value obtained from the copy_to_user() call: if some amount of bytes were not able to get to the user (this is what this one returns) the proper behavior is to return the -EFAULT error, not that number itself." This fixes this for i915_gem.c Signed-off-by: Florian Mickler --- drivers/gpu/drm/i915/i915_gem.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 1449b45..6fb6e13 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -3017,15 +3017,15 @@ i915_gem_put_relocs_to_user(struct drm_i915_gem_exec_object *exec_list, struct drm_i915_gem_relocation_entry *relocs) { uint32_t reloc_count = 0, i; - int ret; + int count; for (i = 0; i < buffer_count; i++) { struct drm_i915_gem_relocation_entry __user *user_relocs; user_relocs = (void __user *)(uintptr_t)exec_list[i].relocs_ptr; - if (ret == 0) { - ret = copy_to_user(user_relocs, + if (count == 0) { + count = copy_to_user(user_relocs, &relocs[reloc_count], exec_list[i].relocation_count * sizeof(*relocs)); @@ -3035,8 +3035,11 @@ i915_gem_put_relocs_to_user(struct drm_i915_gem_exec_object *exec_list, } drm_free(relocs, reloc_count * sizeof(*relocs), DRM_MEM_DRIVER); + + if (count != 0) + count = -EFAULT; - return ret; + return count; } int -- 1.6.2