mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kexec: Delete an unnecessary comparison
@ 2020-08-13 12:45 Youling Tang
  2020-08-14  5:51 ` Dave Young
  2020-08-14  6:07 ` Joe Perches
  0 siblings, 2 replies; 4+ messages in thread
From: Youling Tang @ 2020-08-13 12:45 UTC (permalink / raw)
  To: Eric Biederman, Vivek Goyal; +Cc: kexec, linux-kernel

Regardless of whether the ret value is zero or non-zero, the trajectory
of the program execution is the same, so there is no need to compare.

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
---
 kernel/kexec_file.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index 78c0837..3ad0ae2 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -800,8 +800,6 @@ static int kexec_calculate_store_digests(struct kimage *image)
 
 		ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest",
 						     digest, SHA256_DIGEST_SIZE, 0);
-		if (ret)
-			goto out_free_digest;
 	}
 
 out_free_digest:
-- 
2.1.0


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

* Re: [PATCH] kexec: Delete an unnecessary comparison
  2020-08-13 12:45 [PATCH] kexec: Delete an unnecessary comparison Youling Tang
@ 2020-08-14  5:51 ` Dave Young
  2020-08-14  6:07 ` Joe Perches
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Young @ 2020-08-14  5:51 UTC (permalink / raw)
  To: Youling Tang; +Cc: Eric Biederman, Vivek Goyal, kexec, linux-kernel, akpm

On 08/13/20 at 08:45pm, Youling Tang wrote:
> Regardless of whether the ret value is zero or non-zero, the trajectory
> of the program execution is the same, so there is no need to compare.
> 
> Signed-off-by: Youling Tang <tangyouling@loongson.cn>
> ---
>  kernel/kexec_file.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> index 78c0837..3ad0ae2 100644
> --- a/kernel/kexec_file.c
> +++ b/kernel/kexec_file.c
> @@ -800,8 +800,6 @@ static int kexec_calculate_store_digests(struct kimage *image)
>  
>  		ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest",
>  						     digest, SHA256_DIGEST_SIZE, 0);
> -		if (ret)
> -			goto out_free_digest;
>  	}
>  
>  out_free_digest:
> -- 
> 2.1.0
> 

Acked-by: Dave Young <dyoung@redhat.com>

Thanks
Dave


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

* Re: [PATCH] kexec: Delete an unnecessary comparison
  2020-08-13 12:45 [PATCH] kexec: Delete an unnecessary comparison Youling Tang
  2020-08-14  5:51 ` Dave Young
@ 2020-08-14  6:07 ` Joe Perches
  2020-08-14 10:11   ` Youling Tang
  1 sibling, 1 reply; 4+ messages in thread
From: Joe Perches @ 2020-08-14  6:07 UTC (permalink / raw)
  To: Youling Tang, Eric Biederman, Vivek Goyal; +Cc: kexec, linux-kernel

On Thu, 2020-08-13 at 20:45 +0800, Youling Tang wrote:
> Regardless of whether the ret value is zero or non-zero, the trajectory
> of the program execution is the same, so there is no need to compare.
> 
> Signed-off-by: Youling Tang <tangyouling@loongson.cn>
> ---
>  kernel/kexec_file.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> index 78c0837..3ad0ae2 100644
> --- a/kernel/kexec_file.c
> +++ b/kernel/kexec_file.c
> @@ -800,8 +800,6 @@ static int kexec_calculate_store_digests(struct kimage *image)
>  
>  		ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest",
>  						     digest, SHA256_DIGEST_SIZE, 0);
> -		if (ret)
> -			goto out_free_digest;
>  	}
>  
>  out_free_digest:

If you really want to change the function, then
you could change a couple of breaks to gotos,
remove multiple unnecessary tests, and unindent
a block of code too.

---
 kernel/kexec_file.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index ca40bef75a61..34a025e85887 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -763,7 +763,7 @@ static int kexec_calculate_store_digests(struct kimage *image)
 		ret = crypto_shash_update(desc, ksegment->kbuf,
 					  ksegment->bufsz);
 		if (ret)
-			break;
+			goto out_free_digest;
 
 		/*
 		 * Assume rest of the buffer is filled with zero and
@@ -777,32 +777,26 @@ static int kexec_calculate_store_digests(struct kimage *image)
 				bytes = zero_buf_sz;
 			ret = crypto_shash_update(desc, zero_buf, bytes);
 			if (ret)
-				break;
+				goto out_free_digest;
 			nullsz -= bytes;
 		}
 
-		if (ret)
-			break;
-
 		sha_regions[j].start = ksegment->mem;
 		sha_regions[j].len = ksegment->memsz;
 		j++;
 	}
 
-	if (!ret) {
-		ret = crypto_shash_final(desc, digest);
-		if (ret)
-			goto out_free_digest;
-		ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha_regions",
-						     sha_regions, sha_region_sz, 0);
-		if (ret)
-			goto out_free_digest;
+	ret = crypto_shash_final(desc, digest);
+	if (ret)
+		goto out_free_digest;
 
-		ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest",
-						     digest, SHA256_DIGEST_SIZE, 0);
-		if (ret)
-			goto out_free_digest;
-	}
+	ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha_regions",
+					     sha_regions, sha_region_sz, 0);
+	if (ret)
+		goto out_free_digest;
+
+	ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest",
+					     digest, SHA256_DIGEST_SIZE, 0);
 
 out_free_digest:
 	kfree(digest);



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

* Re: [PATCH] kexec: Delete an unnecessary comparison
  2020-08-14  6:07 ` Joe Perches
@ 2020-08-14 10:11   ` Youling Tang
  0 siblings, 0 replies; 4+ messages in thread
From: Youling Tang @ 2020-08-14 10:11 UTC (permalink / raw)
  To: Joe Perches, Eric Biederman, Vivek Goyal; +Cc: kexec, linux-kernel



On 08/14/2020 02:07 PM, Joe Perches wrote:
> On Thu, 2020-08-13 at 20:45 +0800, Youling Tang wrote:
>> Regardless of whether the ret value is zero or non-zero, the trajectory
>> of the program execution is the same, so there is no need to compare.
>>
>> Signed-off-by: Youling Tang <tangyouling@loongson.cn>
>> ---
>>   kernel/kexec_file.c | 2 --
>>   1 file changed, 2 deletions(-)
>>
>> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
>> index 78c0837..3ad0ae2 100644
>> --- a/kernel/kexec_file.c
>> +++ b/kernel/kexec_file.c
>> @@ -800,8 +800,6 @@ static int kexec_calculate_store_digests(struct kimage *image)
>>   
>>   		ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest",
>>   						     digest, SHA256_DIGEST_SIZE, 0);
>> -		if (ret)
>> -			goto out_free_digest;
>>   	}
>>   
>>   out_free_digest:
> If you really want to change the function, then
> you could change a couple of breaks to gotos,
> remove multiple unnecessary tests, and unindent
> a block of code too.
>
> ---
>   kernel/kexec_file.c | 30 ++++++++++++------------------
>   1 file changed, 12 insertions(+), 18 deletions(-)
>
> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> index ca40bef75a61..34a025e85887 100644
> --- a/kernel/kexec_file.c
> +++ b/kernel/kexec_file.c
> @@ -763,7 +763,7 @@ static int kexec_calculate_store_digests(struct kimage *image)
>   		ret = crypto_shash_update(desc, ksegment->kbuf,
>   					  ksegment->bufsz);
>   		if (ret)
> -			break;
> +			goto out_free_digest;
>   
>   		/*
>   		 * Assume rest of the buffer is filled with zero and
> @@ -777,32 +777,26 @@ static int kexec_calculate_store_digests(struct kimage *image)
>   				bytes = zero_buf_sz;
>   			ret = crypto_shash_update(desc, zero_buf, bytes);
>   			if (ret)
> -				break;
> +				goto out_free_digest;
>   			nullsz -= bytes;
>   		}
>   
> -		if (ret)
> -			break;
> -
>   		sha_regions[j].start = ksegment->mem;
>   		sha_regions[j].len = ksegment->memsz;
>   		j++;
>   	}
>   
> -	if (!ret) {
> -		ret = crypto_shash_final(desc, digest);
> -		if (ret)
> -			goto out_free_digest;
> -		ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha_regions",
> -						     sha_regions, sha_region_sz, 0);
> -		if (ret)
> -			goto out_free_digest;
> +	ret = crypto_shash_final(desc, digest);
> +	if (ret)
> +		goto out_free_digest;
>   
> -		ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest",
> -						     digest, SHA256_DIGEST_SIZE, 0);
> -		if (ret)
> -			goto out_free_digest;
> -	}
> +	ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha_regions",
> +					     sha_regions, sha_region_sz, 0);
> +	if (ret)
> +		goto out_free_digest;
> +
> +	ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest",
> +					     digest, SHA256_DIGEST_SIZE, 0);
>   
>   out_free_digest:
>   	kfree(digest);
>
OK, looks good to me, I will send v2.

Thanks,
Youling


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

end of thread, other threads:[~2020-08-14 10:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-13 12:45 [PATCH] kexec: Delete an unnecessary comparison Youling Tang
2020-08-14  5:51 ` Dave Young
2020-08-14  6:07 ` Joe Perches
2020-08-14 10:11   ` Youling Tang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®