mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Johannes Zink <j.zink@pengutronix.de>
Subject: [PATCH 2/4] crypto: crc32: Lindent
Date: Mon,  4 Sep 2023 10:18:23 +0200	[thread overview]
Message-ID: <20230904081825.1997618-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20230904081825.1997618-1-s.hauer@pengutronix.de>

Make the code a bit more readable.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 crypto/crc32.c | 101 +++++++++++++++++++++++++------------------------
 1 file changed, 51 insertions(+), 50 deletions(-)

diff --git a/crypto/crc32.c b/crypto/crc32.c
index ff5c429ad1..39572ff225 100644
--- a/crypto/crc32.c
+++ b/crypto/crc32.c
@@ -8,7 +8,7 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-#ifdef __BAREBOX__	/* Shut down "ANSI does not permit..." warnings */
+#ifdef __BAREBOX__		/* Shut down "ANSI does not permit..." warnings */
 #include <common.h>
 #include <xfuncs.h>
 #include <fs.h>
@@ -50,52 +50,50 @@ static uint32_t *crc_table;
 */
 static void make_crc_table(void)
 {
-  uint32_t c;
-  int n, k;
-  uint32_t poly;            /* polynomial exclusive-or pattern */
-  /* terms of polynomial defining this crc (except x^32): */
-  static const char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
-
-  /* make exclusive-or pattern from polynomial (0xedb88320L) */
-  poly = 0;
-  for (n = 0; n < sizeof(p)/sizeof(char); n++)
-    poly |= 1U << (31 - p[n]);
-
-  crc_table = xmalloc(sizeof(uint32_t) * 256);
-
-  for (n = 0; n < 256; n++)
-  {
-    c = (uint32_t)n;
-    for (k = 0; k < 8; k++)
-      c = c & 1 ? poly ^ (c >> 1) : c >> 1;
-    crc_table[n] = c;
-  }
+	uint32_t c;
+	int n, k;
+	uint32_t poly; /* polynomial exclusive-or pattern */
+	/* terms of polynomial defining this crc (except x^32): */
+	static const char p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
+
+	/* make exclusive-or pattern from polynomial (0xedb88320L) */
+	poly = 0;
+	for (n = 0; n < sizeof(p) / sizeof(char); n++)
+		poly |= 1U << (31 - p[n]);
+
+	crc_table = xmalloc(sizeof(uint32_t) * 256);
+
+	for (n = 0; n < 256; n++) {
+		c = (uint32_t) n;
+		for (k = 0; k < 8; k++)
+			c = c & 1 ? poly ^ (c >> 1) : c >> 1;
+		crc_table[n] = c;
+	}
 }
 
-/* ========================================================================= */
 #define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
 #define DO2(buf)  DO1(buf); DO1(buf);
 #define DO4(buf)  DO2(buf); DO2(buf);
 #define DO8(buf)  DO4(buf); DO4(buf);
 
-/* ========================================================================= */
 STATIC uint32_t crc32(uint32_t crc, const void *_buf, unsigned int len)
 {
-    const unsigned char *buf = _buf;
+	const unsigned char *buf = _buf;
 
 	if (!crc_table)
 		make_crc_table();
-    crc = crc ^ 0xffffffffL;
-    while (len >= 8)
-    {
-      DO8(buf);
-      len -= 8;
-    }
-    if (len) do {
-      DO1(buf);
-    } while (--len);
-    return crc ^ 0xffffffffL;
+	crc = crc ^ 0xffffffffL;
+	while (len >= 8) {
+		DO8(buf);
+		len -= 8;
+	}
+	if (len)
+		do {
+			DO1(buf);
+		} while (--len);
+	return crc ^ 0xffffffffL;
 }
+
 #ifdef __BAREBOX__
 EXPORT_SYMBOL(crc32);
 #endif
@@ -105,36 +103,38 @@ EXPORT_SYMBOL(crc32);
  */
 STATIC uint32_t crc32_no_comp(uint32_t crc, const void *_buf, unsigned int len)
 {
-   const unsigned char *buf = _buf;
+	const unsigned char *buf = _buf;
 
 	if (!crc_table)
 		make_crc_table();
-    while (len >= 8)
-    {
-      DO8(buf);
-      len -= 8;
-    }
-    if (len) do {
-      DO1(buf);
-    } while (--len);
-
-    return crc;
+	while (len >= 8) {
+		DO8(buf);
+		len -= 8;
+	}
+	if (len)
+		do {
+			DO1(buf);
+		} while (--len);
+
+	return crc;
 }
 
 STATIC uint32_t crc32_be(uint32_t crc, const void *_buf, unsigned int len)
 {
 	const unsigned char *buf = _buf;
 	int i;
+
 	while (len--) {
 		crc ^= *buf++ << 24;
 		for (i = 0; i < 8; i++)
-			crc = (crc << 1) ^ ((crc & 0x80000000) ? 0x04c11db7 : 0);
+			crc =
+			    (crc << 1) ^ ((crc & 0x80000000) ? 0x04c11db7 : 0);
 	}
 	return crc;
 }
 
-STATIC int file_crc(char *filename, ulong start, ulong size, ulong *crc,
-		    ulong *total)
+STATIC int file_crc(char *filename, ulong start, ulong size, ulong * crc,
+		    ulong * total)
 {
 	int fd, now;
 	int ret = 0;
@@ -153,7 +153,7 @@ STATIC int file_crc(char *filename, ulong start, ulong size, ulong *crc,
 		off_t lseek_ret;
 		errno = 0;
 		lseek_ret = lseek(fd, start, SEEK_SET);
-		if (lseek_ret == (off_t)-1 && errno) {
+		if (lseek_ret == (off_t) - 1 && errno) {
 			perror("lseek");
 			ret = -1;
 			goto out;
@@ -163,7 +163,7 @@ STATIC int file_crc(char *filename, ulong start, ulong size, ulong *crc,
 	buf = xmalloc(4096);
 
 	while (size) {
-		now = min((ulong)4096, size);
+		now = min((ulong) 4096, size);
 		now = read(fd, buf, now);
 		if (now < 0) {
 			ret = now;
@@ -184,6 +184,7 @@ STATIC int file_crc(char *filename, ulong start, ulong size, ulong *crc,
 
 	return ret;
 }
+
 #ifdef __BAREBOX__
 EXPORT_SYMBOL(file_crc);
 #endif
-- 
2.39.2




  reply	other threads:[~2023-09-04  8:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04  8:18 [PATCH 1/4] crypto: crc32: Drop CONFIG_DYNAMIC_CRC_TABLE option Sascha Hauer
2023-09-04  8:18 ` Sascha Hauer [this message]
2023-09-04  8:18 ` [PATCH 3/4] crypto: crc32: allocate crc_table statically Sascha Hauer
2023-09-04  8:18 ` [PATCH 4/4] crypto: crc32: enable for PBL Sascha Hauer
2023-09-07  5:48 ` [PATCH 1/4] crypto: crc32: Drop CONFIG_DYNAMIC_CRC_TABLE option Johannes Zink

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230904081825.1997618-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=j.zink@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox