mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] uncompress: simplify prototype of uncompress()
@ 2023-11-13 19:00 Uwe Kleine-König
  2023-11-15 13:10 ` Sascha Hauer
  2023-11-16  7:22 ` Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2023-11-13 19:00 UTC (permalink / raw)
  To: barebox

All callers apart from lib/uncompress.c itself only use memory-to-memory
decompression. Simplify the calls accordingly.

Note that two of three callers passed error_fn=NULL. As the uncompress
function calls error_fn() unconditionally on error, this might yield
undefined behaviour and so the new uncompress function uses
uncompress_err_stdout() as error function which isn't worse for sure.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 arch/arm/cpu/start.c    |  2 +-
 arch/riscv/boot/start.c |  2 +-
 defaultenv/defaultenv.c |  4 +---
 include/uncompress.h    |  7 +------
 lib/uncompress.c        | 24 +++++++++++++++---------
 5 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 15f5b2937227..65e1a0cce53b 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -84,7 +84,7 @@ void *barebox_arm_boot_dtb(void)
 		       compressed_dtb->datalen_uncompressed);
 	else
 		ret = uncompress(compressed_dtb->data, compressed_dtb->datalen,
-				 NULL, NULL, dtb, NULL, NULL);
+				 dtb);
 
 	if (ret) {
 		pr_err("uncompressing dtb failed\n");
diff --git a/arch/riscv/boot/start.c b/arch/riscv/boot/start.c
index 92991d0f6a84..526012b9a43b 100644
--- a/arch/riscv/boot/start.c
+++ b/arch/riscv/boot/start.c
@@ -59,7 +59,7 @@ void *barebox_riscv_boot_dtb(void)
 		return NULL;
 
 	ret = uncompress(compressed_dtb->data, compressed_dtb->datalen,
-			 NULL, NULL, dtb, NULL, NULL);
+			 dtb);
 	if (ret) {
 		pr_err("uncompressing dtb failed\n");
 		free(dtb);
diff --git a/defaultenv/defaultenv.c b/defaultenv/defaultenv.c
index 055475eb4756..b1b042d724d7 100644
--- a/defaultenv/defaultenv.c
+++ b/defaultenv/defaultenv.c
@@ -111,9 +111,7 @@ static int defaultenv_load_one(struct defaultenv *df, const char *dir,
 		if (!freep)
 			return -ENOMEM;
 
-		ret = uncompress(df->buf, df->size,
-				NULL, NULL,
-				freep, NULL, uncompress_err_stdout);
+		ret = uncompress(df->buf, df->size, freep)
 		if (ret) {
 			free(freep);
 			pr_err("Failed to uncompress: %s\n", strerror(-ret));
diff --git a/include/uncompress.h b/include/uncompress.h
index 72ba1dfda607..c6ab2abde983 100644
--- a/include/uncompress.h
+++ b/include/uncompress.h
@@ -2,12 +2,7 @@
 #ifndef __UNCOMPRESS_H
 #define __UNCOMPRESS_H
 
-int uncompress(unsigned char *inbuf, int len,
-	   int(*fill)(void*, unsigned int),
-	   int(*flush)(void*, unsigned int),
-	   unsigned char *output,
-	   int *pos,
-	   void(*error_fn)(char *x));
+int uncompress(unsigned char *inbuf, int len, unsigned char *output);
 
 int uncompress_fd_to_fd(int infd, int outfd,
 	   void(*error_fn)(char *x));
diff --git a/lib/uncompress.c b/lib/uncompress.c
index 71ac882b87fe..8f7284ba68c0 100644
--- a/lib/uncompress.c
+++ b/lib/uncompress.c
@@ -60,12 +60,12 @@ static int uncompress_fill(void *buf, unsigned int len)
 	return total;
 }
 
-int uncompress(unsigned char *inbuf, int len,
-	   int(*fill)(void*, unsigned int),
-	   int(*flush)(void*, unsigned int),
-	   unsigned char *output,
-	   int *pos,
-	   void(*error_fn)(char *x))
+static int __uncompress(unsigned char *inbuf, int len,
+			int(*fill)(void*, unsigned int),
+			int(*flush)(void*, unsigned int),
+			unsigned char *output,
+			int *pos,
+			void(*error_fn)(char *x))
 {
 	enum filetype ft;
 	int (*compfn)(unsigned char *inbuf, int len,
@@ -139,6 +139,12 @@ int uncompress(unsigned char *inbuf, int len,
 	return ret;
 }
 
+int uncompress(unsigned char *inbuf, int len,
+	       unsigned char *output)
+{
+	return __uncompress(inbuf, len, NULL, NULL, output, NULL, uncompress_err_stdout);
+}
+
 static int uncompress_infd, uncompress_outfd;
 
 static int fill_fd(void *buf, unsigned int len)
@@ -157,7 +163,7 @@ int uncompress_fd_to_fd(int infd, int outfd,
 	uncompress_infd = infd;
 	uncompress_outfd = outfd;
 
-	return uncompress(NULL, 0,
+	return __uncompress(NULL, 0,
 	   fill_fd,
 	   flush_fd,
 	   NULL,
@@ -170,7 +176,7 @@ int uncompress_fd_to_buf(int infd, void *output,
 {
 	uncompress_infd = infd;
 
-	return uncompress(NULL, 0, fill_fd, NULL, output, NULL, error_fn);
+	return __uncompress(NULL, 0, fill_fd, NULL, output, NULL, error_fn);
 }
 
 int uncompress_buf_to_fd(const void *input, size_t input_len,
@@ -178,7 +184,7 @@ int uncompress_buf_to_fd(const void *input, size_t input_len,
 {
 	uncompress_outfd = outfd;
 
-	return uncompress((void *)input, input_len, NULL, flush_fd,
+	return __uncompress((void *)input, input_len, NULL, flush_fd,
 			  NULL, NULL, error_fn);
 }
 

base-commit: a9120f147631785fec30eb1e18615d8eabd3d087
-- 
2.42.0




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

end of thread, other threads:[~2023-11-16  8:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-13 19:00 [PATCH] uncompress: simplify prototype of uncompress() Uwe Kleine-König
2023-11-15 13:10 ` Sascha Hauer
2023-11-16  7:22 ` Sascha Hauer
2023-11-16  8:01   ` Uwe Kleine-König

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