From: Tomas Henzl <thenzl@redhat.com>
To: Hannes Reinecke <hare@suse.de>,
James Bottomley <jbottomley@parallels.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH 2/6] scsi: Return VPD page length in scsi_vpd_inquiry()
Date: Wed, 19 Mar 2014 17:38:09 +0100 [thread overview]
Message-ID: <5329C7F1.6080406@redhat.com> (raw)
In-Reply-To: <1394873512-102073-3-git-send-email-hare@suse.de>
On 03/15/2014 09:51 AM, Hannes Reinecke wrote:
> 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.
>
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
> drivers/scsi/scsi.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
> index d8afec8..9e08d3d 100644
> --- a/drivers/scsi/scsi.c
> +++ b/drivers/scsi/scsi.c
> @@ -954,7 +954,7 @@ EXPORT_SYMBOL(scsi_track_queue_full);
> * This is an internal helper function. You probably want to use
> * scsi_get_vpd_page instead.
> *
> - * Returns 0 on success or a negative error number.
> + * Returns size of the vpd page on success or a negative error number.
> */
> static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer,
> u8 page, unsigned len)
> @@ -962,6 +962,9 @@ static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer,
> int result;
> unsigned char cmd[16];
>
> + if (len < 4)
> + return -EINVAL;
> +
> cmd[0] = INQUIRY;
> cmd[1] = 1; /* EVPD */
> cmd[2] = page;
The result of scsi_execute_req should be evaluated, it may return a large positive number
like DRIVER_ERROR << 24.
(resending, my previous mail was rejected by the mailer)
Cheers, Tomas
> @@ -982,7 +985,7 @@ static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer,
> if (buffer[1] != page)
> return -EIO;
>
> - return 0;
> + return get_unaligned_be16(&buffer[2]) + 4;
> }
>
> /**
> @@ -1009,18 +1012,18 @@ int scsi_get_vpd_page(struct scsi_device *sdev, u8 page, unsigned char *buf,
>
> /* Ask for all the pages supported by this device */
> result = scsi_vpd_inquiry(sdev, buf, 0, buf_len);
> - if (result)
> + if (result < 4)
> goto fail;
>
> /* If the user actually wanted this page, we can skip the rest */
> if (page == 0)
> return 0;
>
> - for (i = 0; i < min((int)buf[3], buf_len - 4); i++)
> - if (buf[i + 4] == page)
> + for (i = 4; i < min(result, buf_len); i++)
> + if (buf[i] == page)
> goto found;
>
> - if (i < buf[3] && i >= buf_len - 4)
> + if (i < result && i >= buf_len)
> /* ran off the end of the buffer, give us benefit of doubt */
> goto found;
> /* The device claims it doesn't support the requested page */
> @@ -1028,7 +1031,7 @@ int scsi_get_vpd_page(struct scsi_device *sdev, u8 page, unsigned char *buf,
>
> found:
> result = scsi_vpd_inquiry(sdev, buf, page, buf_len);
> - if (result)
> + if (result < 0)
> goto fail;
>
> return 0;
next prev parent reply other threads:[~2014-03-19 16:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-15 8:51 [PATCHv9 0/6] Display EVPD pages in sysfs Hannes Reinecke
2014-03-15 8:51 ` [PATCH 1/6] scsi_sysfs: Implement 'is_visible' callback Hannes Reinecke
2014-03-15 8:51 ` [PATCH 2/6] scsi: Return VPD page length in scsi_vpd_inquiry() Hannes Reinecke
2014-03-19 16:38 ` Tomas Henzl [this message]
2014-03-15 8:51 ` [PATCH 3/6] Add EVPD page 0x83 to sysfs Hannes Reinecke
2014-03-15 8:51 ` [PATCH 4/6] Add EVPD page 0x80 " Hannes Reinecke
2014-03-15 8:51 ` [PATCH 5/6] ses: Use vpd information from scsi_device Hannes Reinecke
2014-03-15 8:51 ` [PATCH 6/6] Invalidate VPD page data Hannes Reinecke
2014-03-17 22:11 ` Jeremy Linton
2014-03-18 6:52 ` Hannes Reinecke
2014-03-18 13:23 ` James Bottomley
2014-03-18 14:45 ` Elliott, Robert (Server Storage)
2014-03-20 13:37 ` James Bottomley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5329C7F1.6080406@redhat.com \
--to=thenzl@redhat.com \
--cc=hare@suse.de \
--cc=jbottomley@parallels.com \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.