diff mbox series

[1/2] Simplify footprint for get_cpiohdr

Message ID 20210907152312.93144-1-sbabic@denx.de
State Accepted
Headers show
Series [1/2] Simplify footprint for get_cpiohdr | expand

Commit Message

Stefano Babic Sept. 7, 2021, 3:23 p.m. UTC
Pass the pointer to the structure instead of the single fields.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/cpio_utils.c       | 13 ++++++-------
 core/stream_interface.c |  2 +-
 include/cpiohdr.h       |  3 +--
 3 files changed, 8 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index 67cc805..d1e2d6d 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -29,12 +29,11 @@ 
 
 #define NPAD_BYTES(o) ((4 - (o % 4)) % 4)
 
-int get_cpiohdr(unsigned char *buf, unsigned long *size,
-			unsigned long *namesize, unsigned long *chksum)
+int get_cpiohdr(unsigned char *buf, struct filehdr *fhdr)
 {
 	struct new_ascii_header *cpiohdr;
 
-	if (!buf)
+	if (!buf || !fhdr)
 		return -EINVAL;
 
 	cpiohdr = (struct new_ascii_header *)buf;
@@ -45,9 +44,9 @@  int get_cpiohdr(unsigned char *buf, unsigned long *size,
 		ERROR("CPIO Format not recognized: magic not found");
 			return -EINVAL;
 	}
-	*size = FROM_HEX(cpiohdr->c_filesize);
-	*namesize = FROM_HEX(cpiohdr->c_namesize);
-	*chksum =  FROM_HEX(cpiohdr->c_chksum);
+	fhdr->size = FROM_HEX(cpiohdr->c_filesize);
+	fhdr->namesize = FROM_HEX(cpiohdr->c_namesize);
+	fhdr->chksum = FROM_HEX(cpiohdr->c_chksum);
 
 	return 0;
 }
@@ -654,7 +653,7 @@  int extract_cpio_header(int fd, struct filehdr *fhdr, unsigned long *offset)
 	unsigned char buf[sizeof(fhdr->filename)];
 	if (fill_buffer(fd, buf, sizeof(struct new_ascii_header), offset, NULL, NULL) < 0)
 		return -EINVAL;
-	if (get_cpiohdr(buf, &fhdr->size, &fhdr->namesize, &fhdr->chksum) < 0) {
+	if (get_cpiohdr(buf, fhdr) < 0) {
 		ERROR("CPIO Header corrupted, cannot be parsed");
 		return -EINVAL;
 	}
diff --git a/core/stream_interface.c b/core/stream_interface.c
index da0c733..32d1da0 100644
--- a/core/stream_interface.c
+++ b/core/stream_interface.c
@@ -401,7 +401,7 @@  static int save_stream(int fdin, struct swupdate_cfg *software)
 		ret = -EFAULT;
 		goto no_copy_output;
 	}
-	if (get_cpiohdr(buf, &fdh.size, &fdh.namesize, &fdh.chksum) < 0) {
+	if (get_cpiohdr(buf, &fdh) < 0) {
 		ERROR("CPIO Header corrupted, cannot be parsed");
 		ret = -EINVAL;
 		goto no_copy_output;
diff --git a/include/cpiohdr.h b/include/cpiohdr.h
index 21b8578..9d4bb92 100644
--- a/include/cpiohdr.h
+++ b/include/cpiohdr.h
@@ -49,8 +49,7 @@  struct filehdr {
 	char filename[MAX_IMAGE_FNAME];
 };
 
-int get_cpiohdr(unsigned char *buf, unsigned long *size,
-			unsigned long *namesize, unsigned long *chksum);
+int get_cpiohdr(unsigned char *buf, struct filehdr *fhdr);
 int extract_cpio_header(int fd, struct filehdr *fhdr, unsigned long *offset);
 int extract_img_from_cpio(int fd, unsigned long offset, struct filehdr *fdh);
 void extract_padding(int fd, unsigned long *offset);