Commit 64aaa3dd authored by Hannes Reinecke's avatar Hannes Reinecke Committed by Martin K. Petersen
Browse files

scsi: core: Reshuffle response handling in scsi_mode_sense()

Reshuffle response handling in scsi_mode_sense() to make the code easier to
follow.

[mkp: fix build]

Link: https://lore.kernel.org/r/20210427083046.31620-5-hare@suse.de


Suggested-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarHannes Reinecke <hare@suse.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 8793613d
Loading
Loading
Loading
Loading
+37 −38
Original line number Diff line number Diff line
@@ -2148,21 +2148,28 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
	 * byte as the problem.  MODE_SENSE commands can return
	 * ILLEGAL REQUEST if the code page isn't supported */

	if (use_10_for_ms && !scsi_status_is_good(result) &&
	    driver_byte(result) == DRIVER_SENSE) {
		if (scsi_sense_valid(sshdr)) {
	if (!scsi_status_is_good(result)) {
		if (driver_byte(result) == DRIVER_SENSE &&
		    scsi_sense_valid(sshdr)) {
			if ((sshdr->sense_key == ILLEGAL_REQUEST) &&
			    (sshdr->asc == 0x20) && (sshdr->ascq == 0)) {
				/*
				 * Invalid command operation code
				 */
				if (use_10_for_ms) {
					sdev->use_10_for_ms = 0;
					goto retry;
				}
			}
			if ((status_byte(result) == CHECK_CONDITION) &&
			    sshdr->sense_key == UNIT_ATTENTION &&
			    retry_count) {
				retry_count--;
				goto retry;
			}
		}
		return -EIO;
	}

	if (scsi_status_is_good(result)) {
	if (unlikely(buffer[0] == 0x86 && buffer[1] == 0x0b &&
		     (modepage == 6 || modepage == 8))) {
		/* Initio breakage? */
@@ -2186,16 +2193,8 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
		data->block_descriptor_length = buffer[3];
	}
	data->header_length = header_length;
		result = 0;
	} else if ((status_byte(result) == CHECK_CONDITION) &&
		   scsi_sense_valid(sshdr) &&
		   sshdr->sense_key == UNIT_ATTENTION && retry_count) {
		retry_count--;
		goto retry;
	}
	if (result > 0)
		result = -EIO;
	return result;

	return 0;
}
EXPORT_SYMBOL(scsi_mode_sense);