diff mbox series

[4/4] cpio_utils: cleanup state chaining code

Message ID 20240617072905.2275940-5-dominique.martinet@atmark-techno.com
State Accepted
Headers show
Series misc fixes from chunked stream rework | expand

Commit Message

Dominique Martinet June 17, 2024, 7:29 a.m. UTC
We don't need to nest ifs so much, chain steps as they become required.
The step order (input step, decryption, decompression) is preserved.

There is no intended functional change.

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
 core/cpio_utils.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

Comments

Michael Glembotzki June 18, 2024, 7:34 p.m. UTC | #1
Reviewed-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com>

Dominique Martinet schrieb am Montag, 17. Juni 2024 um 09:29:18 UTC+2:

> We don't need to nest ifs so much, chain steps as they become required.
> The step order (input step, decryption, decompression) is preserved.
>
> There is no intended functional change.
>
> Signed-off-by: Dominique Martinet <dominique...@atmark-techno.com>
> ---
> core/cpio_utils.c | 33 ++++++++++++---------------------
> 1 file changed, 12 insertions(+), 21 deletions(-)
>
> diff --git a/core/cpio_utils.c b/core/cpio_utils.c
> index 6178fedca216..65f301909f0c 100644
> --- a/core/cpio_utils.c
> +++ b/core/cpio_utils.c
> @@ -590,31 +590,22 @@ static int __swupdate_copy(int fdin, unsigned char 
> *inbuf, void *out, size_t nby
> }
> }
>
> + step = &input_step;
> + state = &input_state;
> +
> + if (encrypted) {
> + decrypt_state.upstream_step = step;
> + decrypt_state.upstream_state = state;
> + step = &decrypt_step;
> + state = &decrypt_state;
> + }
> +
> #if defined(CONFIG_GUNZIP) || defined(CONFIG_ZSTD)
> if (compressed) {
> - if (encrypted) {
> - decrypt_state.upstream_step = &input_step;
> - decrypt_state.upstream_state = &input_state;
> - decompress_state.upstream_step = &decrypt_step;
> - decompress_state.upstream_state = &decrypt_state;
> - } else {
> - decompress_state.upstream_step = &input_step;
> - decompress_state.upstream_state = &input_state;
> - }
> + decompress_state.upstream_step = step;
> + decompress_state.upstream_state = state;
> step = decompress_step;
> state = &decompress_state;
> - } else {
> -#endif
> - if (encrypted) {
> - decrypt_state.upstream_step = &input_step;
> - decrypt_state.upstream_state = &input_state;
> - step = &decrypt_step;
> - state = &decrypt_state;
> - } else {
> - step = &input_step;
> - state = &input_state;
> - }
> -#if defined(CONFIG_GUNZIP) || defined(CONFIG_ZSTD)
> }
> #endif
>
> -- 
> 2.39.2
>
>
>
diff mbox series

Patch

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index 6178fedca216..65f301909f0c 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -590,31 +590,22 @@  static int __swupdate_copy(int fdin, unsigned char *inbuf, void *out, size_t nby
 		}
 	}
 
+	step = &input_step;
+	state = &input_state;
+
+	if (encrypted) {
+		decrypt_state.upstream_step = step;
+		decrypt_state.upstream_state = state;
+		step = &decrypt_step;
+		state = &decrypt_state;
+	}
+
 #if defined(CONFIG_GUNZIP) || defined(CONFIG_ZSTD)
 	if (compressed) {
-		if (encrypted) {
-			decrypt_state.upstream_step = &input_step;
-			decrypt_state.upstream_state = &input_state;
-			decompress_state.upstream_step = &decrypt_step;
-			decompress_state.upstream_state = &decrypt_state;
-		} else {
-			decompress_state.upstream_step = &input_step;
-			decompress_state.upstream_state = &input_state;
-		}
+		decompress_state.upstream_step = step;
+		decompress_state.upstream_state = state;
 		step = decompress_step;
 		state = &decompress_state;
-	} else {
-#endif
-		if (encrypted) {
-			decrypt_state.upstream_step = &input_step;
-			decrypt_state.upstream_state = &input_state;
-			step = &decrypt_step;
-			state = &decrypt_state;
-		} else {
-			step = &input_step;
-			state = &input_state;
-		}
-#if defined(CONFIG_GUNZIP) || defined(CONFIG_ZSTD)
 	}
 #endif