[PATCH firmware-utils 1/2] otrx: avoid unneeded fseek() when calculating CRC32

Rafał Miłecki zajec5 at gmail.com
Thu Nov 25 22:47:49 PST 2021


From: Rafał Miłecki <rafal at milecki.pl>

Just use already read data.

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 src/otrx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/otrx.c b/src/otrx.c
index b5cd70d..aa81c96 100644
--- a/src/otrx.c
+++ b/src/otrx.c
@@ -193,8 +193,8 @@ static int otrx_check(int argc, char **argv) {
 	}
 
 	crc32 = 0xffffffff;
-	fseek(trx, trx_offset + TRX_FLAGS_OFFSET, SEEK_SET);
-	length -= TRX_FLAGS_OFFSET;
+	crc32 = otrx_crc32(crc32, (uint8_t *)&hdr + TRX_FLAGS_OFFSET, sizeof(hdr) - TRX_FLAGS_OFFSET);
+	length -= sizeof(hdr);
 	while ((bytes = fread(buf, 1, otrx_min(sizeof(buf), length), trx)) > 0) {
 		crc32 = otrx_crc32(crc32, buf, bytes);
 		length -= bytes;
-- 
2.31.1




More information about the openwrt-devel mailing list