diff mbox series

Fix NULL pointer found by static analysis

Message ID 20200923044054.5653-1-steven.t.hampson@intel.com (mailing list archive)
State New, archived
Headers show
Series Fix NULL pointer found by static analysis | expand

Commit Message

Steve Hampson Sept. 23, 2020, 4:40 a.m. UTC
A static analysis tool has reveiled a NULL pointer error in
__i915_gem_object_lock.  This appears to be correct as many calls
pass a NULL into the ww parameter.

Signed-off-by: Steve Hampson <steven.t.hampson@intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_object.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Chris Wilson Sept. 23, 2020, 8:58 a.m. UTC | #1
Quoting Steve Hampson (2020-09-23 05:40:54)
> A static analysis tool has reveiled a NULL pointer error in
> __i915_gem_object_lock.  This appears to be correct as many calls
> pass a NULL into the ww parameter.
> 
> Signed-off-by: Steve Hampson <steven.t.hampson@intel.com>
> ---
>  drivers/gpu/drm/i915/gem/i915_gem_object.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h
> index d46db8d8f38e..9b18ead42991 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
> @@ -126,7 +126,7 @@ static inline int __i915_gem_object_lock(struct drm_i915_gem_object *obj,
>         if (ret == -EALREADY)
>                 ret = 0;
>  
> -       if (ret == -EDEADLK)
> +       if (ret == -EDEADLK && ww)

EDEADLK is predicated by ww already.
-Chris
Jani Nikula Sept. 23, 2020, 9:04 a.m. UTC | #2
On Wed, 23 Sep 2020, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> Quoting Steve Hampson (2020-09-23 05:40:54)
>> A static analysis tool has reveiled a NULL pointer error in
>> __i915_gem_object_lock.  This appears to be correct as many calls
>> pass a NULL into the ww parameter.
>> 
>> Signed-off-by: Steve Hampson <steven.t.hampson@intel.com>
>> ---
>>  drivers/gpu/drm/i915/gem/i915_gem_object.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h
>> index d46db8d8f38e..9b18ead42991 100644
>> --- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
>> +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
>> @@ -126,7 +126,7 @@ static inline int __i915_gem_object_lock(struct drm_i915_gem_object *obj,
>>         if (ret == -EALREADY)
>>                 ret = 0;
>>  
>> -       if (ret == -EDEADLK)
>> +       if (ret == -EDEADLK && ww)
>
> EDEADLK is predicated by ww already.

The hard part is that neither the analyzer nor a human who doesn't know
how dma_resv_lock* work can easily deduce that. :(

BR,
Jani.
Steve Hampson Sept. 23, 2020, 9:23 p.m. UTC | #3
Never mind.  This is a false positive.

-----Original Message-----
From: Intel-gfx <intel-gfx-bounces@lists.freedesktop.org> On Behalf Of Steve Hampson
Sent: Tuesday, September 22, 2020 9:41 PM
To: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH] Fix NULL pointer found by static analysis

A static analysis tool has reveiled a NULL pointer error in __i915_gem_object_lock.  This appears to be correct as many calls pass a NULL into the ww parameter.

Signed-off-by: Steve Hampson <steven.t.hampson@intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_object.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index d46db8d8f38e..9b18ead42991 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -126,7 +126,7 @@ static inline int __i915_gem_object_lock(struct drm_i915_gem_object *obj,
 	if (ret == -EALREADY)
 		ret = 0;
 
-	if (ret == -EDEADLK)
+	if (ret == -EDEADLK && ww)
 		ww->contended = obj;
 
 	return ret;
--
2.21.0
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index d46db8d8f38e..9b18ead42991 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -126,7 +126,7 @@  static inline int __i915_gem_object_lock(struct drm_i915_gem_object *obj,
 	if (ret == -EALREADY)
 		ret = 0;
 
-	if (ret == -EDEADLK)
+	if (ret == -EDEADLK && ww)
 		ww->contended = obj;
 
 	return ret;