Skip to content

Commit 1ad45a9

Browse files
JasonYanHwshligit
authored andcommitted
md/raid5-cache: fix payload endianness problem in raid5-cache
The payload->header.type and payload->size are little-endian, so just convert them to the right byte order. Signed-off-by: Jason Yan <yanaijie@huawei.com> Cc: <stable@vger.kernel.org> #v4.10+ Signed-off-by: Shaohua Li <shli@fb.com>
1 parent 41743c1 commit 1ad45a9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/md/raid5-cache.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,12 +2002,12 @@ r5l_recovery_verify_data_checksum_for_mb(struct r5l_log *log,
20022002
payload = (void *)mb + mb_offset;
20032003
payload_flush = (void *)mb + mb_offset;
20042004

2005-
if (payload->header.type == R5LOG_PAYLOAD_DATA) {
2005+
if (le16_to_cpu(payload->header.type) == R5LOG_PAYLOAD_DATA) {
20062006
if (r5l_recovery_verify_data_checksum(
20072007
log, ctx, page, log_offset,
20082008
payload->checksum[0]) < 0)
20092009
goto mismatch;
2010-
} else if (payload->header.type == R5LOG_PAYLOAD_PARITY) {
2010+
} else if (le16_to_cpu(payload->header.type) == R5LOG_PAYLOAD_PARITY) {
20112011
if (r5l_recovery_verify_data_checksum(
20122012
log, ctx, page, log_offset,
20132013
payload->checksum[0]) < 0)
@@ -2019,12 +2019,12 @@ r5l_recovery_verify_data_checksum_for_mb(struct r5l_log *log,
20192019
BLOCK_SECTORS),
20202020
payload->checksum[1]) < 0)
20212021
goto mismatch;
2022-
} else if (payload->header.type == R5LOG_PAYLOAD_FLUSH) {
2022+
} else if (le16_to_cpu(payload->header.type) == R5LOG_PAYLOAD_FLUSH) {
20232023
/* nothing to do for R5LOG_PAYLOAD_FLUSH here */
20242024
} else /* not R5LOG_PAYLOAD_DATA/PARITY/FLUSH */
20252025
goto mismatch;
20262026

2027-
if (payload->header.type == R5LOG_PAYLOAD_FLUSH) {
2027+
if (le16_to_cpu(payload->header.type) == R5LOG_PAYLOAD_FLUSH) {
20282028
mb_offset += sizeof(struct r5l_payload_flush) +
20292029
le32_to_cpu(payload_flush->size);
20302030
} else {
@@ -2091,7 +2091,7 @@ r5c_recovery_analyze_meta_block(struct r5l_log *log,
20912091
payload = (void *)mb + mb_offset;
20922092
payload_flush = (void *)mb + mb_offset;
20932093

2094-
if (payload->header.type == R5LOG_PAYLOAD_FLUSH) {
2094+
if (le16_to_cpu(payload->header.type) == R5LOG_PAYLOAD_FLUSH) {
20952095
int i, count;
20962096

20972097
count = le32_to_cpu(payload_flush->size) / sizeof(__le64);
@@ -2113,7 +2113,7 @@ r5c_recovery_analyze_meta_block(struct r5l_log *log,
21132113
}
21142114

21152115
/* DATA or PARITY payload */
2116-
stripe_sect = (payload->header.type == R5LOG_PAYLOAD_DATA) ?
2116+
stripe_sect = (le16_to_cpu(payload->header.type) == R5LOG_PAYLOAD_DATA) ?
21172117
raid5_compute_sector(
21182118
conf, le64_to_cpu(payload->location), 0, &dd,
21192119
NULL)
@@ -2151,15 +2151,15 @@ r5c_recovery_analyze_meta_block(struct r5l_log *log,
21512151
list_add_tail(&sh->lru, cached_stripe_list);
21522152
}
21532153

2154-
if (payload->header.type == R5LOG_PAYLOAD_DATA) {
2154+
if (le16_to_cpu(payload->header.type) == R5LOG_PAYLOAD_DATA) {
21552155
if (!test_bit(STRIPE_R5C_CACHING, &sh->state) &&
21562156
test_bit(R5_Wantwrite, &sh->dev[sh->pd_idx].flags)) {
21572157
r5l_recovery_replay_one_stripe(conf, sh, ctx);
21582158
list_move_tail(&sh->lru, cached_stripe_list);
21592159
}
21602160
r5l_recovery_load_data(log, sh, ctx, payload,
21612161
log_offset);
2162-
} else if (payload->header.type == R5LOG_PAYLOAD_PARITY)
2162+
} else if (le16_to_cpu(payload->header.type) == R5LOG_PAYLOAD_PARITY)
21632163
r5l_recovery_load_parity(log, sh, ctx, payload,
21642164
log_offset);
21652165
else
@@ -2361,7 +2361,7 @@ r5c_recovery_rewrite_data_only_stripes(struct r5l_log *log,
23612361
payload = (void *)mb + offset;
23622362
payload->header.type = cpu_to_le16(
23632363
R5LOG_PAYLOAD_DATA);
2364-
payload->size = BLOCK_SECTORS;
2364+
payload->size = cpu_to_le32(BLOCK_SECTORS);
23652365
payload->location = cpu_to_le64(
23662366
raid5_compute_blocknr(sh, i, 0));
23672367
addr = kmap_atomic(dev->page);

0 commit comments

Comments
 (0)