[PATCH 2/4] crypto: crc32: Lindent
Sascha Hauer
s.hauer at pengutronix.de
Mon Sep 4 01:18:23 PDT 2023
Make the code a bit more readable.
Signed-off-by: Sascha Hauer <s.hauer at 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
More information about the barebox
mailing list