[PATCH 116/117] Change the return type of scsi_mode_select() into union scsi_status

Bart Van Assche
2021-04-20T02:14:48Z

Make it explicit that scsi_mode_select() returns a SCSI status.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: John Garry <john.garry@huawei.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/scsi_lib.c | 18 +++++++++++-------
drivers/scsi/sd.c | 2 +-
include/scsi/scsi_device.h | 9 ++++-----
3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 964462895cbb..6d7144750e1c 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2069,24 +2069,26 @@ void scsi_exit_queue(void)
* status on error
*
*/
-int
+union scsi_status
scsi_mode_select(struct scsi_device *sdev, int pf, int sp, int modepage,
unsigned char *buffer, int len, int timeout, int retries,
struct scsi_mode_data *data, struct scsi_sense_hdr *sshdr)
{
unsigned char cmd[10];
unsigned char *real_buffer;
- int ret;
+ union scsi_status ret;

memset(cmd, 0, sizeof(cmd));
cmd[1] = (pf ? 0x10 : 0) | (sp ? 0x01 : 0);

if (sdev->use_10_for_ms) {
+ ret.combined = -EINVAL;
if (len > 65535)
- return -EINVAL;
+ return ret;
+ ret.combined = -ENOMEM;
real_buffer = kmalloc(8 + len, GFP_KERNEL);
if (!real_buffer)
- return -ENOMEM;
+ return ret;
memcpy(real_buffer + 8, buffer, len);
len += 8;
real_buffer[0] = 0;
@@ -2102,13 +2104,15 @@ scsi_mode_select(struct scsi_device *sdev, int pf, int sp, int modepage,
cmd[7] = len >> 8;
cmd[8] = len;
} else {
+ ret.combined = -EINVAL;
if (len > 255 || data->block_descriptor_length > 255 ||
data->longlba)
- return -EINVAL;
+ return ret;

+ ret.combined = -ENOMEM;
real_buffer = kmalloc(4 + len, GFP_KERNEL);
if (!real_buffer)
- return -ENOMEM;
+ return ret;
memcpy(real_buffer + 4, buffer, len);
len += 4;
real_buffer[0] = 0;
@@ -2121,7 +2125,7 @@ scsi_mode_select(struct scsi_device *sdev, int pf, int sp, int modepage,
}

ret = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, real_buffer, len,
- sshdr, timeout, retries, NULL).combined;
+ sshdr, timeout, retries, NULL);
kfree(real_buffer);
return ret;
}
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 2f423a332bc1..d07c0484f325 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -212,7 +212,7 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
data.device_specific = 0;

if (scsi_mode_select(sdp, 1, sp, 8, buffer_data, len, SD_TIMEOUT,
- sdkp->max_retries, &data, &sshdr)) {
+ sdkp->max_retries, &data, &sshdr).combined) {
if (scsi_sense_valid(&sshdr))
sd_print_sense_hdr(sdkp, &sshdr);
return -EINVAL;
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index de6f5f98d2eb..fd91cf13a257 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -406,11 +406,10 @@ extern union scsi_status scsi_mode_sense(struct scsi_device *sdev, int dbd,
int modepage, unsigned char *buffer, int len,
int timeout, int retries, struct scsi_mode_data *data,
struct scsi_sense_hdr *);
-extern int scsi_mode_select(struct scsi_device *sdev, int pf, int sp,
- int modepage, unsigned char *buffer, int len,
- int timeout, int retries,
- struct scsi_mode_data *data,
- struct scsi_sense_hdr *);
+extern union scsi_status scsi_mode_select(struct scsi_device *sdev, int pf,
+ int sp, int modepage, unsigned char *buffer, int len,
+ int timeout, int retries, struct scsi_mode_data *data,
+ struct scsi_sense_hdr *);
extern union scsi_status scsi_test_unit_ready(struct scsi_device *sdev,
int timeout, int retries, struct scsi_sense_hdr *sshdr);
extern int scsi_get_vpd_page(struct scsi_device *, u8 page, unsigned char *buf,