| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * SCSI Block Commands (SBC) parsing and emulation. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * (c) Copyright 2002-2013 Datera, Inc. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Nicholas A. Bellinger <nab@kernel.org> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 10 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | | - * (at your option) any later version. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | | - * GNU General Public License for more details. |
|---|
| 17 | | - * |
|---|
| 18 | | - * You should have received a copy of the GNU General Public License |
|---|
| 19 | | - * along with this program; if not, write to the Free Software |
|---|
| 20 | | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 21 | 8 | */ |
|---|
| 22 | 9 | |
|---|
| 23 | 10 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 360 | 347 | unsigned int offset; |
|---|
| 361 | 348 | sense_reason_t ret = TCM_NO_SENSE; |
|---|
| 362 | 349 | int i, count; |
|---|
| 350 | + |
|---|
| 351 | + if (!success) |
|---|
| 352 | + return 0; |
|---|
| 353 | + |
|---|
| 363 | 354 | /* |
|---|
| 364 | 355 | * From sbc3r22.pdf section 5.48 XDWRITEREAD (10) command |
|---|
| 365 | 356 | * |
|---|
| .. | .. |
|---|
| 425 | 416 | struct se_device *dev = cmd->se_dev; |
|---|
| 426 | 417 | sense_reason_t ret = TCM_NO_SENSE; |
|---|
| 427 | 418 | |
|---|
| 428 | | - /* |
|---|
| 429 | | - * Only set SCF_COMPARE_AND_WRITE_POST to force a response fall-through |
|---|
| 430 | | - * within target_complete_ok_work() if the command was successfully |
|---|
| 431 | | - * sent to the backend driver. |
|---|
| 432 | | - */ |
|---|
| 433 | 419 | spin_lock_irq(&cmd->t_state_lock); |
|---|
| 434 | | - if (cmd->transport_state & CMD_T_SENT) { |
|---|
| 435 | | - cmd->se_cmd_flags |= SCF_COMPARE_AND_WRITE_POST; |
|---|
| 420 | + if (success) { |
|---|
| 436 | 421 | *post_ret = 1; |
|---|
| 437 | 422 | |
|---|
| 438 | 423 | if (cmd->scsi_status == SAM_STAT_CHECK_CONDITION) |
|---|
| .. | .. |
|---|
| 453 | 438 | int *post_ret) |
|---|
| 454 | 439 | { |
|---|
| 455 | 440 | struct se_device *dev = cmd->se_dev; |
|---|
| 456 | | - struct scatterlist *write_sg = NULL, *sg; |
|---|
| 441 | + struct sg_table write_tbl = { }; |
|---|
| 442 | + struct scatterlist *write_sg, *sg; |
|---|
| 457 | 443 | unsigned char *buf = NULL, *addr; |
|---|
| 458 | 444 | struct sg_mapping_iter m; |
|---|
| 459 | 445 | unsigned int offset = 0, len; |
|---|
| .. | .. |
|---|
| 494 | 480 | goto out; |
|---|
| 495 | 481 | } |
|---|
| 496 | 482 | |
|---|
| 497 | | - write_sg = kmalloc_array(cmd->t_data_nents, sizeof(*write_sg), |
|---|
| 498 | | - GFP_KERNEL); |
|---|
| 499 | | - if (!write_sg) { |
|---|
| 483 | + if (sg_alloc_table(&write_tbl, cmd->t_data_nents, GFP_KERNEL) < 0) { |
|---|
| 500 | 484 | pr_err("Unable to allocate compare_and_write sg\n"); |
|---|
| 501 | 485 | ret = TCM_OUT_OF_RESOURCES; |
|---|
| 502 | 486 | goto out; |
|---|
| 503 | 487 | } |
|---|
| 504 | | - sg_init_table(write_sg, cmd->t_data_nents); |
|---|
| 488 | + write_sg = write_tbl.sgl; |
|---|
| 505 | 489 | /* |
|---|
| 506 | 490 | * Setup verify and write data payloads from total NumberLBAs. |
|---|
| 507 | 491 | */ |
|---|
| .. | .. |
|---|
| 597 | 581 | * sbc_compare_and_write() before the original READ I/O submission. |
|---|
| 598 | 582 | */ |
|---|
| 599 | 583 | up(&dev->caw_sem); |
|---|
| 600 | | - kfree(write_sg); |
|---|
| 584 | + sg_free_table(&write_tbl); |
|---|
| 601 | 585 | kfree(buf); |
|---|
| 602 | 586 | return ret; |
|---|
| 603 | 587 | } |
|---|
| .. | .. |
|---|
| 749 | 733 | } |
|---|
| 750 | 734 | if (!protect) |
|---|
| 751 | 735 | return TCM_NO_SENSE; |
|---|
| 752 | | - /* Fallthrough */ |
|---|
| 736 | + fallthrough; |
|---|
| 753 | 737 | default: |
|---|
| 754 | 738 | pr_err("Unable to determine pi_prot_type for CDB: 0x%02x " |
|---|
| 755 | 739 | "PROTECT: 0x%02x\n", cmd->t_task_cdb[0], protect); |
|---|