]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
[SCSI] scsi_debug: fix resp_xdwriteread() return value when running out of memory
authorAkinobu Mita <akinobu.mita@gmail.com>
Wed, 26 Feb 2014 13:57:01 +0000 (22:57 +0900)
committerJames Bottomley <JBottomley@Parallels.com>
Wed, 19 Mar 2014 19:15:03 +0000 (12:15 -0700)
When resp_xdwriteread() can't allocate temporary buffer, it returns -1.
But the return value is used as scsi status code and -1 is not
interpreted as correct code.

target_core_mod has similar xdwriteread emulation code. So this mimics
what target_core_mod does for xdwriteread when running out of memory.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Reviewed-by: Douglas Gilbert <dgilbert@interlog.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/scsi_debug.c

index 1a4288032110ee332db5f2eac4ac5e94a0f1d8ea..a1025190887535612218de61f0375a503a7f23d3 100644 (file)
@@ -64,6 +64,7 @@ static const char * scsi_debug_version_date = "20100324";
 /* Additional Sense Code (ASC) */
 #define NO_ADDITIONAL_SENSE 0x0
 #define LOGICAL_UNIT_NOT_READY 0x4
+#define LOGICAL_UNIT_COMMUNICATION_FAILURE 0x8
 #define UNRECOVERED_READ_ERR 0x11
 #define PARAMETER_LIST_LENGTH_ERR 0x1a
 #define INVALID_OPCODE 0x20
@@ -2318,8 +2319,11 @@ static int resp_xdwriteread(struct scsi_cmnd *scp, unsigned long long lba,
 
        /* better not to use temporary buffer. */
        buf = kmalloc(scsi_bufflen(scp), GFP_ATOMIC);
-       if (!buf)
-               return ret;
+       if (!buf) {
+               mk_sense_buffer(devip, NOT_READY,
+                               LOGICAL_UNIT_COMMUNICATION_FAILURE, 0);
+               return check_condition_result;
+       }
 
        scsi_sg_copy_to_buffer(scp, buf, scsi_bufflen(scp));