All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] drivers/gpu/drm/i915: Fixed uninitialized variables (warnings).
@ 2012-05-14 23:57 Raphael Carvalho
  2012-05-15  6:19 ` Chris Wilson
  0 siblings, 1 reply; 2+ messages in thread
From: Raphael Carvalho @ 2012-05-14 23:57 UTC (permalink / raw)
  To: keithp, airlied, dri-devel, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2901 bytes --]

>From 1e77059e8f3158fd4844e3f6a5466a063d2f407e Mon Sep 17 00:00:00 2001
From: "Raphael S.Carvalho" <utroz@oakcoders.com>
Date: Mon, 14 May 2012 20:19:24 -0300
Subject: [PATCH 1/1]     drivers/gpu/drm/i915: Fixed uninitialized
 variables (warnings).
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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@utrozpc:~/linux$ make > make_output
    : In function ‘i915_gem_pread_ioctl’:
drivers/gpu/drm/i915/i915_gem.c:455:21: warning: ‘ret’ may be used
uninitialized in this function [-Wuninitialized]
drivers/gpu/drm/i915/i915_gem.c:390:38: note: ‘ret’ was declared here
drivers/gpu/drm/i915/i915_gem.c: In function ‘i915_gem_pwrite_ioctl’:
drivers/gpu/drm/i915/i915_gem.c:871:21: warning: ‘ret’ may be used
uninitialized in this function [-Wuninitialized]
drivers/gpu/drm/i915/i915_gem.c:797:38: note: ‘ret’ was declared here

Signed-off-by: Raphael S.Carvalho <rsc.utroz@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 = (char __user *) (uintptr_t) args->data_ptr;
     remain = args->size;
+    if (remain <= 0) {
+        ret = -EINVAL;
+        goto final;
+    }

     obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);

@@ -451,7 +455,7 @@ out:
     /* Fixup: Kill any reinstated backing storage pages */
     if (obj->madv == __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 = (char __user *) (uintptr_t) args->data_ptr;
     remain = args->size;
+    if (remain <= 0) {
+        ret = -EINVAL;
+        goto final;
+    }

     obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);

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

-- 
1.7.5.4

[-- Attachment #1.2: Type: text/html, Size: 3236 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] drivers/gpu/drm/i915: Fixed uninitialized variables (warnings).
  2012-05-14 23:57 [PATCH 1/1] drivers/gpu/drm/i915: Fixed uninitialized variables (warnings) Raphael Carvalho
@ 2012-05-15  6:19 ` Chris Wilson
  0 siblings, 0 replies; 2+ messages in thread
From: Chris Wilson @ 2012-05-15  6:19 UTC (permalink / raw)
  To: Raphael Carvalho, keithp, airlied, dri-devel, linux-kernel

On Mon, 14 May 2012 20:57:07 -0300, Raphael Carvalho <rsc.utroz@gmail.com> wrote:
> From 1e77059e8f3158fd4844e3f6a5466a063d2f407e Mon Sep 17 00:00:00 2001
> From: "Raphael S.Carvalho" <utroz@oakcoders.com>
> Date: Mon, 14 May 2012 20:19:24 -0300
> Subject: [PATCH 1/1]     drivers/gpu/drm/i915: Fixed uninitialized
>  variables (warnings).
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> 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.

Which is checked for before calling the function. Look harder at what
gcc is trying to tell you, the actual location of gcc's error is inside
an inlined function...
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-05-15  6:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-14 23:57 [PATCH 1/1] drivers/gpu/drm/i915: Fixed uninitialized variables (warnings) Raphael Carvalho
2012-05-15  6:19 ` Chris Wilson

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.