[PATCH 1/1] drivers/gpu/drm/i915: Fixed uninitialized variables (warnings).

Raphael S.Carvalho utroz at oakcoders.com
Mon May 14 16:19:24 PDT 2012


As you see, this modifications were really very important because if the
remain variable receives a value lower or equals than 0 from the args->size
variable, indeed, a bad behavior could ocurrs.

Let me explain:
The variable ret would never be initialized if the function doesn't enter
inside of the loop. So that, the function will return a strange (undefined)
value when it reaches the final.

If you've a better solution or if I commited a mistake in my changes,
please talk me about. I'm sure I'm a newcomer, hehe.

I'm using the GCC: gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)

Warnings received during make operation:
utroz at utrozpc:~/linux$ make > make_output
    : In function =91i915_gem_pread_ioctl=92:
drivers/gpu/drm/i915/i915_gem.c:455:21: warning: =91ret=92 may be used
uninitialized in this function [-Wuninitialized]
drivers/gpu/drm/i915/i915_gem.c:390:38: note: =91ret=92 was declared here
drivers/gpu/drm/i915/i915_gem.c: In function =91i915_gem_pwrite_ioctl=92:
drivers/gpu/drm/i915/i915_gem.c:871:21: warning: =91ret=92 may be used
uninitialized in this function [-Wuninitialized]
drivers/gpu/drm/i915/i915_gem.c:797:38: note: =91ret=92 was declared here

Signed-off-by: Raphael S.Carvalho <rsc.utroz at gmail.com>
---
 drivers/gpu/drm/i915/i915_gem.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c
b/drivers/gpu/drm/i915/i915_gem.c
index 0d1e4b7..b0a0004 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -392,6 +392,10 @@ i915_gem_shmem_pread_slow(struct drm_device *dev,

     user_data =3D (char __user *) (uintptr_t) args->data_ptr;
     remain =3D args->size;
+    if (remain <=3D 0) {
+        ret =3D -EINVAL;
+        goto final;
+    }

     obj_do_bit17_swizzling =3D i915_gem_object_needs_bit17_swizzle(obj);

@@ -451,7 +455,7 @@ out:
     /* Fixup: Kill any reinstated backing storage pages */
     if (obj->madv =3D=3D __I915_MADV_PURGED)
         i915_gem_object_truncate(obj);
-
+final:
     return ret;
 }

@@ -799,6 +803,10 @@ i915_gem_shmem_pwrite_slow(struct drm_device *dev,

     user_data =3D (char __user *) (uintptr_t) args->data_ptr;
     remain =3D args->size;
+    if (remain <=3D 0) {
+        ret =3D -EINVAL;
+        goto final;
+    }

     obj_do_bit17_swizzling =3D i915_gem_object_needs_bit17_swizzle(obj);

@@ -867,7 +875,7 @@ out:
         i915_gem_clflush_object(obj);
         intel_gtt_chipset_flush();
     }
-
+final:
     return ret;
 }

--=20
1.7.5.4

--14dae934064bfe938b04c007d705
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable



More information about the dri-devel mailing list