Merge branch 'urgent.2021.05.20a' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / drivers / target / target_core_pscsi.c
index 3cbc074..f2a1141 100644 (file)
@@ -34,8 +34,6 @@
 #include "target_core_internal.h"
 #include "target_core_pscsi.h"
 
-#define ISPRINT(a)  ((a >= ' ') && (a <= '~'))
-
 static inline struct pscsi_dev_virt *PSCSI_DEV(struct se_device *dev)
 {
        return container_of(dev, struct pscsi_dev_virt, dev);
@@ -620,8 +618,9 @@ static void pscsi_complete_cmd(struct se_cmd *cmd, u8 scsi_status,
                        unsigned char *buf;
 
                        buf = transport_kmap_data_sg(cmd);
-                       if (!buf)
+                       if (!buf) {
                                ; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
+                       }
 
                        if (cdb[0] == MODE_SENSE_10) {
                                if (!(buf[3] & 0x80))
@@ -882,7 +881,6 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
                        if (!bio) {
 new_bio:
                                nr_vecs = bio_max_segs(nr_pages);
-                               nr_pages -= nr_vecs;
                                /*
                                 * Calls bio_kmalloc() and sets bio->bi_end_io()
                                 */
@@ -911,7 +909,7 @@ new_bio:
                                        " %d i: %d bio: %p, allocating another"
                                        " bio\n", bio->bi_vcnt, i, bio);
 
-                               rc = blk_rq_append_bio(req, &bio);
+                               rc = blk_rq_append_bio(req, bio);
                                if (rc) {
                                        pr_err("pSCSI: failed to append bio\n");
                                        goto fail;
@@ -930,7 +928,7 @@ new_bio:
        }
 
        if (bio) {
-               rc = blk_rq_append_bio(req, &bio);
+               rc = blk_rq_append_bio(req, bio);
                if (rc) {
                        pr_err("pSCSI: failed to append bio\n");
                        goto fail;
@@ -939,6 +937,14 @@ new_bio:
 
        return 0;
 fail:
+       if (bio)
+               bio_put(bio);
+       while (req->bio) {
+               bio = req->bio;
+               req->bio = bio->bi_next;
+               bio_put(bio);
+       }
+       req->biotail = NULL;
        return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 }
 
@@ -1040,7 +1046,7 @@ static void pscsi_req_done(struct request *req, blk_status_t status)
        int result = scsi_req(req)->result;
        u8 scsi_status = status_byte(result) << 1;
 
-       if (scsi_status) {
+       if (scsi_status != SAM_STAT_GOOD) {
                pr_debug("PSCSI Status Byte exception at cmd: %p CDB:"
                        " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0],
                        result);