[PATCH] drm/i915:Move the code position to reduce the number of judgments

Lv qian posted 1 patch 3 years, 7 months ago
drivers/gpu/drm/i915/i915_gpu_error.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[PATCH] drm/i915:Move the code position to reduce the number of judgments
Posted by Lv qian 3 years, 7 months ago
	If the kmalloc allocation is successful, the if is judged twice, 
	so I move the second judgment in to the first judgment.

Signed-off-by: Lv qian <lvqian@nfschina.com>
---
 drivers/gpu/drm/i915/i915_gpu_error.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
index 32e92651ef7c..c8230a8beadb 100644
--- a/drivers/gpu/drm/i915/i915_gpu_error.c
+++ b/drivers/gpu/drm/i915/i915_gpu_error.c
@@ -112,10 +112,10 @@ static bool __i915_error_grow(struct drm_i915_error_state_buf *e, size_t len)
 	if (!e->buf) {
 		e->size = PAGE_ALIGN(len + 1);
 		e->buf = kmalloc(e->size, GFP_KERNEL);
-	}
-	if (!e->buf) {
-		e->err = -ENOMEM;
-		return false;
+		if (!e->buf) {
+			e->err = -ENOMEM;
+			return false;
+		}
 	}
 
 	return true;
-- 
2.18.2
Re: [PATCH] drm/i915:Move the code position to reduce the number of judgments
Posted by Jani Nikula 3 years, 7 months ago
On Thu, 25 Aug 2022, Lv qian <lvqian@nfschina.com> wrote:
> 	If the kmalloc allocation is successful, the if is judged twice, 
> 	so I move the second judgment in to the first judgment.

The code is fine as it is.

BR,
Jani.

>
> Signed-off-by: Lv qian <lvqian@nfschina.com>
> ---
>  drivers/gpu/drm/i915/i915_gpu_error.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
> index 32e92651ef7c..c8230a8beadb 100644
> --- a/drivers/gpu/drm/i915/i915_gpu_error.c
> +++ b/drivers/gpu/drm/i915/i915_gpu_error.c
> @@ -112,10 +112,10 @@ static bool __i915_error_grow(struct drm_i915_error_state_buf *e, size_t len)
>  	if (!e->buf) {
>  		e->size = PAGE_ALIGN(len + 1);
>  		e->buf = kmalloc(e->size, GFP_KERNEL);
> -	}
> -	if (!e->buf) {
> -		e->err = -ENOMEM;
> -		return false;
> +		if (!e->buf) {
> +			e->err = -ENOMEM;
> +			return false;
> +		}
>  	}
>  
>  	return true;

-- 
Jani Nikula, Intel Open Source Graphics Center