diff mbox

drm/i915/userptr: Keep spin_lock/unlock in the same block

Message ID 1406204924-7370-1-git-send-email-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson July 24, 2014, 12:28 p.m. UTC
Move the code around in order to acquire and release the spinlock in the
same function and in the same block. This keeps static analysers happy
and the reader sane.

Suggested-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Julia Lawall <julia.lawall@lip6.fr>
---
 drivers/gpu/drm/i915/i915_gem_userptr.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

Comments

Julia Lawall July 24, 2014, 1:12 p.m. UTC | #1
All of the NULL tests are a bit complicated but since they are there
anyway, I guess it is reasonable to take advantage of them.

julia

On Thu, 24 Jul 2014, Chris Wilson wrote:

> Move the code around in order to acquire and release the spinlock in the
> same function and in the same block. This keeps static analysers happy
> and the reader sane.
>
> Suggested-by: Julia Lawall <julia.lawall@lip6.fr>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Julia Lawall <julia.lawall@lip6.fr>
> ---
>  drivers/gpu/drm/i915/i915_gem_userptr.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c
> index 12358fd..4ef5a92 100644
> --- a/drivers/gpu/drm/i915/i915_gem_userptr.c
> +++ b/drivers/gpu/drm/i915/i915_gem_userptr.c
> @@ -96,10 +96,10 @@ static unsigned long cancel_userptr(struct drm_i915_gem_object *obj)
>  	return end;
>  }
>
> -static void invalidate_range__linear(struct i915_mmu_notifier *mn,
> -				     struct mm_struct *mm,
> -				     unsigned long start,
> -				     unsigned long end)
> +static void *invalidate_range__linear(struct i915_mmu_notifier *mn,
> +				      struct mm_struct *mm,
> +				      unsigned long start,
> +				      unsigned long end)
>  {
>  	struct i915_mmu_object *mo;
>  	unsigned long serial;
> @@ -123,7 +123,7 @@ restart:
>  			goto restart;
>  	}
>
> -	spin_unlock(&mn->lock);
> +	return NULL;
>  }
>
>  static void i915_gem_userptr_mn_invalidate_range_start(struct mmu_notifier *_mn,
> @@ -138,13 +138,12 @@ static void i915_gem_userptr_mn_invalidate_range_start(struct mmu_notifier *_mn,
>
>  	end--; /* interval ranges are inclusive, but invalidate range is exclusive */
>  	while (next < end) {
> -		struct drm_i915_gem_object *obj;
> +		struct drm_i915_gem_object *obj = NULL;
>
> -		obj = NULL;
>  		spin_lock(&mn->lock);
>  		if (mn->has_linear)
> -			return invalidate_range__linear(mn, mm, start, end);
> -		if (serial == mn->serial)
> +			it = invalidate_range__linear(mn, mm, start, end);
> +		else if (serial == mn->serial)
>  			it = interval_tree_iter_next(it, next, end);
>  		else
>  			it = interval_tree_iter_first(&mn->objects, start, end);
> --
> 1.9.1
>
>
Daniel Vetter July 25, 2014, 7:39 a.m. UTC | #2
On Thu, Jul 24, 2014 at 01:28:44PM +0100, Chris Wilson wrote:
> Move the code around in order to acquire and release the spinlock in the
> same function and in the same block. This keeps static analysers happy
> and the reader sane.
> 
> Suggested-by: Julia Lawall <julia.lawall@lip6.fr>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Julia Lawall <julia.lawall@lip6.fr>

Queued for -next, thanks for the patch.
-Daniel

> ---
>  drivers/gpu/drm/i915/i915_gem_userptr.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c
> index 12358fd..4ef5a92 100644
> --- a/drivers/gpu/drm/i915/i915_gem_userptr.c
> +++ b/drivers/gpu/drm/i915/i915_gem_userptr.c
> @@ -96,10 +96,10 @@ static unsigned long cancel_userptr(struct drm_i915_gem_object *obj)
>  	return end;
>  }
>  
> -static void invalidate_range__linear(struct i915_mmu_notifier *mn,
> -				     struct mm_struct *mm,
> -				     unsigned long start,
> -				     unsigned long end)
> +static void *invalidate_range__linear(struct i915_mmu_notifier *mn,
> +				      struct mm_struct *mm,
> +				      unsigned long start,
> +				      unsigned long end)
>  {
>  	struct i915_mmu_object *mo;
>  	unsigned long serial;
> @@ -123,7 +123,7 @@ restart:
>  			goto restart;
>  	}
>  
> -	spin_unlock(&mn->lock);
> +	return NULL;
>  }
>  
>  static void i915_gem_userptr_mn_invalidate_range_start(struct mmu_notifier *_mn,
> @@ -138,13 +138,12 @@ static void i915_gem_userptr_mn_invalidate_range_start(struct mmu_notifier *_mn,
>  
>  	end--; /* interval ranges are inclusive, but invalidate range is exclusive */
>  	while (next < end) {
> -		struct drm_i915_gem_object *obj;
> +		struct drm_i915_gem_object *obj = NULL;
>  
> -		obj = NULL;
>  		spin_lock(&mn->lock);
>  		if (mn->has_linear)
> -			return invalidate_range__linear(mn, mm, start, end);
> -		if (serial == mn->serial)
> +			it = invalidate_range__linear(mn, mm, start, end);
> +		else if (serial == mn->serial)
>  			it = interval_tree_iter_next(it, next, end);
>  		else
>  			it = interval_tree_iter_first(&mn->objects, start, end);
> -- 
> 1.9.1
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c
index 12358fd..4ef5a92 100644
--- a/drivers/gpu/drm/i915/i915_gem_userptr.c
+++ b/drivers/gpu/drm/i915/i915_gem_userptr.c
@@ -96,10 +96,10 @@  static unsigned long cancel_userptr(struct drm_i915_gem_object *obj)
 	return end;
 }
 
-static void invalidate_range__linear(struct i915_mmu_notifier *mn,
-				     struct mm_struct *mm,
-				     unsigned long start,
-				     unsigned long end)
+static void *invalidate_range__linear(struct i915_mmu_notifier *mn,
+				      struct mm_struct *mm,
+				      unsigned long start,
+				      unsigned long end)
 {
 	struct i915_mmu_object *mo;
 	unsigned long serial;
@@ -123,7 +123,7 @@  restart:
 			goto restart;
 	}
 
-	spin_unlock(&mn->lock);
+	return NULL;
 }
 
 static void i915_gem_userptr_mn_invalidate_range_start(struct mmu_notifier *_mn,
@@ -138,13 +138,12 @@  static void i915_gem_userptr_mn_invalidate_range_start(struct mmu_notifier *_mn,
 
 	end--; /* interval ranges are inclusive, but invalidate range is exclusive */
 	while (next < end) {
-		struct drm_i915_gem_object *obj;
+		struct drm_i915_gem_object *obj = NULL;
 
-		obj = NULL;
 		spin_lock(&mn->lock);
 		if (mn->has_linear)
-			return invalidate_range__linear(mn, mm, start, end);
-		if (serial == mn->serial)
+			it = invalidate_range__linear(mn, mm, start, end);
+		else if (serial == mn->serial)
 			it = interval_tree_iter_next(it, next, end);
 		else
 			it = interval_tree_iter_first(&mn->objects, start, end);