diff options
author | Hannes Reinecke <hare@suse.de> | 2014-03-15 04:51:48 -0400 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2014-03-27 11:23:12 -0400 |
commit | bc8945df3c27e8edaa6a6de47cb20df7d12b80c8 (patch) | |
tree | dddd0617c03ee44eb98a8823d25820308e7aea5d /drivers/scsi/scsi.c | |
parent | 276b20d09be7a1c260f0a94880d33e0850efe200 (diff) |
[SCSI] Return VPD page length in scsi_vpd_inquiry()
We should be returning the number of bytes of the
requested VPD page in scsi_vpd_inquiry.
This makes it easier for the caller to verify the
required space.
[jejb: fix up mm warning spotted by Sergey]
Tested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi/scsi.c')
-rw-r--r-- | drivers/scsi/scsi.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 2b12983d2b2d..b2526ad7b9a1 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c | |||
@@ -942,7 +942,7 @@ EXPORT_SYMBOL(scsi_track_queue_full); | |||
942 | * This is an internal helper function. You probably want to use | 942 | * This is an internal helper function. You probably want to use |
943 | * scsi_get_vpd_page instead. | 943 | * scsi_get_vpd_page instead. |
944 | * | 944 | * |
945 | * Returns 0 on success or a negative error number. | 945 | * Returns size of the vpd page on success or a negative error number. |
946 | */ | 946 | */ |
947 | static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer, | 947 | static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer, |
948 | u8 page, unsigned len) | 948 | u8 page, unsigned len) |
@@ -950,6 +950,9 @@ static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer, | |||
950 | int result; | 950 | int result; |
951 | unsigned char cmd[16]; | 951 | unsigned char cmd[16]; |
952 | 952 | ||
953 | if (len < 4) | ||
954 | return -EINVAL; | ||
955 | |||
953 | cmd[0] = INQUIRY; | 956 | cmd[0] = INQUIRY; |
954 | cmd[1] = 1; /* EVPD */ | 957 | cmd[1] = 1; /* EVPD */ |
955 | cmd[2] = page; | 958 | cmd[2] = page; |
@@ -964,13 +967,13 @@ static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer, | |||
964 | result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buffer, | 967 | result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buffer, |
965 | len, NULL, 30 * HZ, 3, NULL); | 968 | len, NULL, 30 * HZ, 3, NULL); |
966 | if (result) | 969 | if (result) |
967 | return result; | 970 | return -EIO; |
968 | 971 | ||
969 | /* Sanity check that we got the page back that we asked for */ | 972 | /* Sanity check that we got the page back that we asked for */ |
970 | if (buffer[1] != page) | 973 | if (buffer[1] != page) |
971 | return -EIO; | 974 | return -EIO; |
972 | 975 | ||
973 | return 0; | 976 | return get_unaligned_be16(&buffer[2]) + 4; |
974 | } | 977 | } |
975 | 978 | ||
976 | /** | 979 | /** |
@@ -997,18 +1000,18 @@ int scsi_get_vpd_page(struct scsi_device *sdev, u8 page, unsigned char *buf, | |||
997 | 1000 | ||
998 | /* Ask for all the pages supported by this device */ | 1001 | /* Ask for all the pages supported by this device */ |
999 | result = scsi_vpd_inquiry(sdev, buf, 0, buf_len); | 1002 | result = scsi_vpd_inquiry(sdev, buf, 0, buf_len); |
1000 | if (result) | 1003 | if (result < 4) |
1001 | goto fail; | 1004 | goto fail; |
1002 | 1005 | ||
1003 | /* If the user actually wanted this page, we can skip the rest */ | 1006 | /* If the user actually wanted this page, we can skip the rest */ |
1004 | if (page == 0) | 1007 | if (page == 0) |
1005 | return 0; | 1008 | return 0; |
1006 | 1009 | ||
1007 | for (i = 0; i < min((int)buf[3], buf_len - 4); i++) | 1010 | for (i = 4; i < min(result, buf_len); i++) |
1008 | if (buf[i + 4] == page) | 1011 | if (buf[i] == page) |
1009 | goto found; | 1012 | goto found; |
1010 | 1013 | ||
1011 | if (i < buf[3] && i >= buf_len - 4) | 1014 | if (i < result && i >= buf_len) |
1012 | /* ran off the end of the buffer, give us benefit of doubt */ | 1015 | /* ran off the end of the buffer, give us benefit of doubt */ |
1013 | goto found; | 1016 | goto found; |
1014 | /* The device claims it doesn't support the requested page */ | 1017 | /* The device claims it doesn't support the requested page */ |
@@ -1016,7 +1019,7 @@ int scsi_get_vpd_page(struct scsi_device *sdev, u8 page, unsigned char *buf, | |||
1016 | 1019 | ||
1017 | found: | 1020 | found: |
1018 | result = scsi_vpd_inquiry(sdev, buf, page, buf_len); | 1021 | result = scsi_vpd_inquiry(sdev, buf, page, buf_len); |
1019 | if (result) | 1022 | if (result < 0) |
1020 | goto fail; | 1023 | goto fail; |
1021 | 1024 | ||
1022 | return 0; | 1025 | return 0; |