| .. | .. |
|---|
| 124 | 124 | * Direction r or w? |
|---|
| 125 | 125 | */ |
|---|
| 126 | 126 | arg_name = dm_shift_arg(as); |
|---|
| 127 | | - if (!strcasecmp(arg_name, "w")) |
|---|
| 127 | + if (arg_name && !strcasecmp(arg_name, "w")) |
|---|
| 128 | 128 | fc->corrupt_bio_rw = WRITE; |
|---|
| 129 | | - else if (!strcasecmp(arg_name, "r")) |
|---|
| 129 | + else if (arg_name && !strcasecmp(arg_name, "r")) |
|---|
| 130 | 130 | fc->corrupt_bio_rw = READ; |
|---|
| 131 | 131 | else { |
|---|
| 132 | 132 | ti->error = "Invalid corrupt bio direction (r or w)"; |
|---|
| .. | .. |
|---|
| 301 | 301 | */ |
|---|
| 302 | 302 | bio_for_each_segment(bvec, bio, iter) { |
|---|
| 303 | 303 | if (bio_iter_len(bio, iter) > corrupt_bio_byte) { |
|---|
| 304 | | - char *segment = (page_address(bio_iter_page(bio, iter)) |
|---|
| 305 | | - + bio_iter_offset(bio, iter)); |
|---|
| 304 | + char *segment; |
|---|
| 305 | + struct page *page = bio_iter_page(bio, iter); |
|---|
| 306 | + if (unlikely(page == ZERO_PAGE(0))) |
|---|
| 307 | + break; |
|---|
| 308 | + segment = (page_address(page) + bio_iter_offset(bio, iter)); |
|---|
| 306 | 309 | segment[corrupt_bio_byte] = fc->corrupt_bio_value; |
|---|
| 307 | 310 | DMDEBUG("Corrupting data bio=%p by writing %u to byte %u " |
|---|
| 308 | 311 | "(rw=%c bi_opf=%u bi_sector=%llu size=%u)\n", |
|---|
| .. | .. |
|---|
| 359 | 362 | /* |
|---|
| 360 | 363 | * Corrupt matching writes. |
|---|
| 361 | 364 | */ |
|---|
| 362 | | - if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == WRITE)) { |
|---|
| 363 | | - if (all_corrupt_bio_flags_match(bio, fc)) |
|---|
| 364 | | - corrupt_bio_data(bio, fc); |
|---|
| 365 | + if (fc->corrupt_bio_byte) { |
|---|
| 366 | + if (fc->corrupt_bio_rw == WRITE) { |
|---|
| 367 | + if (all_corrupt_bio_flags_match(bio, fc)) |
|---|
| 368 | + corrupt_bio_data(bio, fc); |
|---|
| 369 | + } |
|---|
| 365 | 370 | goto map_bio; |
|---|
| 366 | 371 | } |
|---|
| 367 | 372 | |
|---|
| .. | .. |
|---|
| 387 | 392 | return DM_ENDIO_DONE; |
|---|
| 388 | 393 | |
|---|
| 389 | 394 | if (!*error && pb->bio_submitted && (bio_data_dir(bio) == READ)) { |
|---|
| 390 | | - if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == READ) && |
|---|
| 391 | | - all_corrupt_bio_flags_match(bio, fc)) { |
|---|
| 392 | | - /* |
|---|
| 393 | | - * Corrupt successful matching READs while in down state. |
|---|
| 394 | | - */ |
|---|
| 395 | | - corrupt_bio_data(bio, fc); |
|---|
| 396 | | - |
|---|
| 395 | + if (fc->corrupt_bio_byte) { |
|---|
| 396 | + if ((fc->corrupt_bio_rw == READ) && |
|---|
| 397 | + all_corrupt_bio_flags_match(bio, fc)) { |
|---|
| 398 | + /* |
|---|
| 399 | + * Corrupt successful matching READs while in down state. |
|---|
| 400 | + */ |
|---|
| 401 | + corrupt_bio_data(bio, fc); |
|---|
| 402 | + } |
|---|
| 397 | 403 | } else if (!test_bit(DROP_WRITES, &fc->flags) && |
|---|
| 398 | 404 | !test_bit(ERROR_WRITES, &fc->flags)) { |
|---|
| 399 | 405 | /* |
|---|