Commit 1db5df98 authored by Al Viro's avatar Al Viro

ocfs2: kill endianness abuses in blockcheck.c

ocfs2_block_check is for little-endian contents; if we just want to
its fields converted to host-endian in a couple of functions, just
put those values into local u32 and u16...
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent f6a56903
...@@ -422,45 +422,46 @@ int ocfs2_block_check_validate(void *data, size_t blocksize, ...@@ -422,45 +422,46 @@ int ocfs2_block_check_validate(void *data, size_t blocksize,
struct ocfs2_blockcheck_stats *stats) struct ocfs2_blockcheck_stats *stats)
{ {
int rc = 0; int rc = 0;
struct ocfs2_block_check check; u32 bc_crc32e;
u16 bc_ecc;
u32 crc, ecc; u32 crc, ecc;
ocfs2_blockcheck_inc_check(stats); ocfs2_blockcheck_inc_check(stats);
check.bc_crc32e = le32_to_cpu(bc->bc_crc32e); bc_crc32e = le32_to_cpu(bc->bc_crc32e);
check.bc_ecc = le16_to_cpu(bc->bc_ecc); bc_ecc = le16_to_cpu(bc->bc_ecc);
memset(bc, 0, sizeof(struct ocfs2_block_check)); memset(bc, 0, sizeof(struct ocfs2_block_check));
/* Fast path - if the crc32 validates, we're good to go */ /* Fast path - if the crc32 validates, we're good to go */
crc = crc32_le(~0, data, blocksize); crc = crc32_le(~0, data, blocksize);
if (crc == check.bc_crc32e) if (crc == bc_crc32e)
goto out; goto out;
ocfs2_blockcheck_inc_failure(stats); ocfs2_blockcheck_inc_failure(stats);
mlog(ML_ERROR, mlog(ML_ERROR,
"CRC32 failed: stored: 0x%x, computed 0x%x. Applying ECC.\n", "CRC32 failed: stored: 0x%x, computed 0x%x. Applying ECC.\n",
(unsigned int)check.bc_crc32e, (unsigned int)crc); (unsigned int)bc_crc32e, (unsigned int)crc);
/* Ok, try ECC fixups */ /* Ok, try ECC fixups */
ecc = ocfs2_hamming_encode_block(data, blocksize); ecc = ocfs2_hamming_encode_block(data, blocksize);
ocfs2_hamming_fix_block(data, blocksize, ecc ^ check.bc_ecc); ocfs2_hamming_fix_block(data, blocksize, ecc ^ bc_ecc);
/* And check the crc32 again */ /* And check the crc32 again */
crc = crc32_le(~0, data, blocksize); crc = crc32_le(~0, data, blocksize);
if (crc == check.bc_crc32e) { if (crc == bc_crc32e) {
ocfs2_blockcheck_inc_recover(stats); ocfs2_blockcheck_inc_recover(stats);
goto out; goto out;
} }
mlog(ML_ERROR, "Fixed CRC32 failed: stored: 0x%x, computed 0x%x\n", mlog(ML_ERROR, "Fixed CRC32 failed: stored: 0x%x, computed 0x%x\n",
(unsigned int)check.bc_crc32e, (unsigned int)crc); (unsigned int)bc_crc32e, (unsigned int)crc);
rc = -EIO; rc = -EIO;
out: out:
bc->bc_crc32e = cpu_to_le32(check.bc_crc32e); bc->bc_crc32e = cpu_to_le32(bc_crc32e);
bc->bc_ecc = cpu_to_le16(check.bc_ecc); bc->bc_ecc = cpu_to_le16(bc_ecc);
return rc; return rc;
} }
...@@ -528,7 +529,8 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr, ...@@ -528,7 +529,8 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
struct ocfs2_blockcheck_stats *stats) struct ocfs2_blockcheck_stats *stats)
{ {
int i, rc = 0; int i, rc = 0;
struct ocfs2_block_check check; u32 bc_crc32e;
u16 bc_ecc;
u32 crc, ecc, fix; u32 crc, ecc, fix;
BUG_ON(nr < 0); BUG_ON(nr < 0);
...@@ -538,21 +540,21 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr, ...@@ -538,21 +540,21 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
ocfs2_blockcheck_inc_check(stats); ocfs2_blockcheck_inc_check(stats);
check.bc_crc32e = le32_to_cpu(bc->bc_crc32e); bc_crc32e = le32_to_cpu(bc->bc_crc32e);
check.bc_ecc = le16_to_cpu(bc->bc_ecc); bc_ecc = le16_to_cpu(bc->bc_ecc);
memset(bc, 0, sizeof(struct ocfs2_block_check)); memset(bc, 0, sizeof(struct ocfs2_block_check));
/* Fast path - if the crc32 validates, we're good to go */ /* Fast path - if the crc32 validates, we're good to go */
for (i = 0, crc = ~0; i < nr; i++) for (i = 0, crc = ~0; i < nr; i++)
crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size);
if (crc == check.bc_crc32e) if (crc == bc_crc32e)
goto out; goto out;
ocfs2_blockcheck_inc_failure(stats); ocfs2_blockcheck_inc_failure(stats);
mlog(ML_ERROR, mlog(ML_ERROR,
"CRC32 failed: stored: %u, computed %u. Applying ECC.\n", "CRC32 failed: stored: %u, computed %u. Applying ECC.\n",
(unsigned int)check.bc_crc32e, (unsigned int)crc); (unsigned int)bc_crc32e, (unsigned int)crc);
/* Ok, try ECC fixups */ /* Ok, try ECC fixups */
for (i = 0, ecc = 0; i < nr; i++) { for (i = 0, ecc = 0; i < nr; i++) {
...@@ -565,7 +567,7 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr, ...@@ -565,7 +567,7 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
bhs[i]->b_size * 8, bhs[i]->b_size * 8,
bhs[i]->b_size * 8 * i); bhs[i]->b_size * 8 * i);
} }
fix = ecc ^ check.bc_ecc; fix = ecc ^ bc_ecc;
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
/* /*
* Try the fix against each buffer. It will only affect * Try the fix against each buffer. It will only affect
...@@ -578,19 +580,19 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr, ...@@ -578,19 +580,19 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
/* And check the crc32 again */ /* And check the crc32 again */
for (i = 0, crc = ~0; i < nr; i++) for (i = 0, crc = ~0; i < nr; i++)
crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size);
if (crc == check.bc_crc32e) { if (crc == bc_crc32e) {
ocfs2_blockcheck_inc_recover(stats); ocfs2_blockcheck_inc_recover(stats);
goto out; goto out;
} }
mlog(ML_ERROR, "Fixed CRC32 failed: stored: %u, computed %u\n", mlog(ML_ERROR, "Fixed CRC32 failed: stored: %u, computed %u\n",
(unsigned int)check.bc_crc32e, (unsigned int)crc); (unsigned int)bc_crc32e, (unsigned int)crc);
rc = -EIO; rc = -EIO;
out: out:
bc->bc_crc32e = cpu_to_le32(check.bc_crc32e); bc->bc_crc32e = cpu_to_le32(bc_crc32e);
bc->bc_ecc = cpu_to_le16(check.bc_ecc); bc->bc_ecc = cpu_to_le16(bc_ecc);
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment