Skip to contentSkip to conversation

Fixup vpd page length calculation

PATCH In review Hannes Reinecke 2 participants 2 messages Mar 20, 2014 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fixup vpd page length calculation

The VPD page length parameter is not only used for the length, but also to hold any error code. So it needs to be moved to an integer.
And we should be resetting the default VPD page length after each iteration so that we do not allocate overly large buffers.

---
 drivers/scsi/scsi.c        | 4 +++-
 include/scsi/scsi_device.h | 7 +++++--
 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/scsi/scsi.c +3 -1
index ae780ef..81ab805 100644
@@ -1041,7 +1041,7 @@ EXPORT_SYMBOL_GPL(scsi_get_vpd_page);
 void scsi_attach_vpd(struct scsi_device *sdev)
 {
 	int result, i;
-	int vpd_len = 255;
+	int vpd_len = SCSI_VPD_PG_LEN;
 	int pg80_supported = 0;
 	int pg83_supported = 0;
 	unsigned char *vpd_buf, *tmp_pg;
@@ -1073,6 +1073,7 @@ retry_pg0:
 			pg83_supported = 1;
 	}
 	kfree(vpd_buf);
+	vpd_len = SCSI_VPD_PG_LEN;
 
 retry_pg80:
 	if (pg80_supported) {
@@ -1106,6 +1107,7 @@ retry_pg80:
 			sdev->vpd_pg80_len = result;
 			spin_unlock(&sdev->reconfig_lock);
 		}
+		vpd_len = SCSI_VPD_PG_LEN;
 	} else {
 		spin_lock(&sdev->reconfig_lock);
 		tmp_pg = sdev->vpd_pg80;
include/scsi/scsi_device.h +5 -2
index 3ea6220..d51c41d 100644
@@ -113,10 +113,13 @@ struct scsi_device {
 	const char * vendor;		/* [back_compat] point into 'inquiry' ... */
 	const char * model;		/* ... after scan; point to static string */
 	const char * rev;		/* ... "nullnullnullnull" before scan */
-	unsigned char vpd_pg83_len;
+
+#define SCSI_VPD_PG_LEN		255
+	int vpd_pg83_len;
 	unsigned char *vpd_pg83;
-	unsigned char vpd_pg80_len;
+	int vpd_pg80_len;
 	unsigned char *vpd_pg80;
+
 	spinlock_t reconfig_lock;
 	unsigned char current_tag;	/* current tag */
 	struct scsi_target      *sdev_target;   /* used only for single_lun */
Signature · 1 line
1.7.12.4
#1 lore raw
Quoted 5 lines · Hannes Reinecke

The VPD page length parameter is not only used for the length, but also to hold any error code. So it needs to be moved to an integer.
And we should be resetting the default VPD page length after each iteration so that we do not allocate overly large buffers.

This is pretty difficult to apply, since three patches are affected. I think I got it right (please check), but next time, I'd prefer the fixed patches.

Thanks,

James