hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/target/target_core_sbc.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * SCSI Block Commands (SBC) parsing and emulation.
34 *
45 * (c) Copyright 2002-2013 Datera, Inc.
56 *
67 * 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.
218 */
229
2310 #include <linux/kernel.h>
....@@ -360,6 +347,10 @@
360347 unsigned int offset;
361348 sense_reason_t ret = TCM_NO_SENSE;
362349 int i, count;
350
+
351
+ if (!success)
352
+ return 0;
353
+
363354 /*
364355 * From sbc3r22.pdf section 5.48 XDWRITEREAD (10) command
365356 *
....@@ -425,14 +416,8 @@
425416 struct se_device *dev = cmd->se_dev;
426417 sense_reason_t ret = TCM_NO_SENSE;
427418
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
- */
433419 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) {
436421 *post_ret = 1;
437422
438423 if (cmd->scsi_status == SAM_STAT_CHECK_CONDITION)
....@@ -453,7 +438,8 @@
453438 int *post_ret)
454439 {
455440 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;
457443 unsigned char *buf = NULL, *addr;
458444 struct sg_mapping_iter m;
459445 unsigned int offset = 0, len;
....@@ -494,14 +480,12 @@
494480 goto out;
495481 }
496482
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) {
500484 pr_err("Unable to allocate compare_and_write sg\n");
501485 ret = TCM_OUT_OF_RESOURCES;
502486 goto out;
503487 }
504
- sg_init_table(write_sg, cmd->t_data_nents);
488
+ write_sg = write_tbl.sgl;
505489 /*
506490 * Setup verify and write data payloads from total NumberLBAs.
507491 */
....@@ -597,7 +581,7 @@
597581 * sbc_compare_and_write() before the original READ I/O submission.
598582 */
599583 up(&dev->caw_sem);
600
- kfree(write_sg);
584
+ sg_free_table(&write_tbl);
601585 kfree(buf);
602586 return ret;
603587 }
....@@ -749,7 +733,7 @@
749733 }
750734 if (!protect)
751735 return TCM_NO_SENSE;
752
- /* Fallthrough */
736
+ fallthrough;
753737 default:
754738 pr_err("Unable to determine pi_prot_type for CDB: 0x%02x "
755739 "PROTECT: 0x%02x\n", cmd->t_task_cdb[0], protect);
....@@ -1454,7 +1438,7 @@
14541438 if (rc) {
14551439 kunmap_atomic(daddr - dsg->offset);
14561440 kunmap_atomic(paddr - psg->offset);
1457
- cmd->bad_sector = sector;
1441
+ cmd->sense_info = sector;
14581442 return rc;
14591443 }
14601444 next: