[PATCH 1/8] [SCSI] scst: Split sysfs type attribute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The device 'type' sysfs attribute contains two values: the SCSI
peripheral device type as a number and its textual description. Split
this sysfs attribute into two attributes such that both satisfy the
"one value per file" rule. Also, fix a potential out-of-bounds access
of the array scst_dev_handler_types.

Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
Cc: Vladislav Bolkhovitin <vst@xxxxxxxx>
---
 .../ABI/stable/sysfs-devices-scst_tgt_dev          |    8 +++-
 Documentation/ABI/stable/sysfs-driver-scst_tgt_dev |   12 +++--
 drivers/scst/scst_sysfs.c                          |   46 ++++++++++++++-----
 3 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/Documentation/ABI/stable/sysfs-devices-scst_tgt_dev b/Documentation/ABI/stable/sysfs-devices-scst_tgt_dev
index cfa791e..a7d5070 100644
--- a/Documentation/ABI/stable/sysfs-devices-scst_tgt_dev
+++ b/Documentation/ABI/stable/sysfs-devices-scst_tgt_dev
@@ -118,7 +118,13 @@ What:		/sys/bus/scst_tgt_dev/device/*/type
 Date:		December 2010
 Contact:	Bart Van Assche <bvanassche@xxxxxxx>
 Description:
-		SCSI type of this device. Read-only.
+		SCSI type of this device as a number. Read-only.
+
+What:		/sys/bus/scst_tgt_dev/device/*/type_description
+Date:		December 2010
+Contact:	Bart Van Assche <bvanassche@xxxxxxx>
+Description:
+		SCSI type of this device as a textual description. Read-only.
 
 What:		/sys/bus/scst_tgt_dev/device/*/usn
 Date:		December 2010
diff --git a/Documentation/ABI/stable/sysfs-driver-scst_tgt_dev b/Documentation/ABI/stable/sysfs-driver-scst_tgt_dev
index c79aee0..2787c4d 100644
--- a/Documentation/ABI/stable/sysfs-driver-scst_tgt_dev
+++ b/Documentation/ABI/stable/sysfs-driver-scst_tgt_dev
@@ -20,8 +20,12 @@ What:		/sys/bus/scst_tgt_dev/drivers/*/type
 Date:		December 2010
 Contact:	Bart Van Assche <bvanassche@xxxxxxx>
 Description:
-		SCSI type of the devices managed by this driver. Read-only.
-		An example:
+		SCSI type of the devices managed by this driver as a number.
+		Read-only.
 
-		$ cat /sys/bus/scst_tgt_dev/drivers/vcdrom/type
-		5 - CD-ROM device
+What:		/sys/bus/scst_tgt_dev/drivers/*/type_description
+Date:		December 2010
+Contact:	Bart Van Assche <bvanassche@xxxxxxx>
+Description:
+		SCSI type of the devices managed by this driver as a textual
+		description. Read-only.
diff --git a/drivers/scst/scst_sysfs.c b/drivers/scst/scst_sysfs.c
index 3901f20..23cba83 100644
--- a/drivers/scst/scst_sysfs.c
+++ b/drivers/scst/scst_sysfs.c
@@ -1091,16 +1091,22 @@ void scst_tgt_sysfs_put(struct scst_tgt *tgt)
 static ssize_t scst_dev_sysfs_type_show(struct device *device,
 				struct device_attribute *attr, char *buf)
 {
-	int pos;
 	struct scst_device *dev;
 
 	dev = scst_dev_to_dev(device);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", dev->type);
+}
 
-	pos = sprintf(buf, "%d - %s\n", dev->type,
-		(unsigned)dev->type > ARRAY_SIZE(scst_dev_handler_types) ?
-		      "unknown" : scst_dev_handler_types[dev->type]);
+static ssize_t scst_dev_sysfs_type_description_show(struct device *device,
+				struct device_attribute *attr, char *buf)
+{
+	struct scst_device *dev;
+	const char *descr;
 
-	return pos;
+	dev = scst_dev_to_dev(device);
+	descr = (unsigned)dev->type < ARRAY_SIZE(scst_dev_handler_types) ?
+		scst_dev_handler_types[dev->type] : "unknown";
+	return scnprintf(buf, PAGE_SIZE, "%s\n", descr);
 }
 
 static int scst_process_dev_sysfs_threads_data_store(
@@ -1265,8 +1271,13 @@ static const struct device_attribute *dev_thread_attr[] = {
 static const struct device_attribute scst_dev_sysfs_type_attr =
 	__ATTR(type, S_IRUGO, scst_dev_sysfs_type_show, NULL);
 
+static const struct device_attribute scst_dev_sysfs_type_description_attr =
+	__ATTR(type_description, S_IRUGO, scst_dev_sysfs_type_description_show,
+	       NULL);
+
 static const struct device_attribute *scst_devt_dev_attrs[] = {
 	&scst_dev_sysfs_type_attr,
+	&scst_dev_sysfs_type_description_attr,
 	NULL
 };
 
@@ -2852,23 +2863,34 @@ out:
 
 static ssize_t scst_devt_type_show(struct device_driver *drv, char *buf)
 {
-	int pos;
 	struct scst_dev_type *devt;
 
 	devt = scst_drv_to_devt(drv);
-
-	pos = sprintf(buf, "%d - %s\n", devt->type,
-		(unsigned)devt->type > ARRAY_SIZE(scst_dev_handler_types) ?
-			"unknown" : scst_dev_handler_types[devt->type]);
-
-	return pos;
+	return scnprintf(buf, PAGE_SIZE, "%d\n", devt->type);
 }
 
 static const struct driver_attribute scst_devt_type_attr =
 	__ATTR(type, S_IRUGO, scst_devt_type_show, NULL);
 
+static ssize_t scst_devt_type_description_show(struct device_driver *drv,
+					       char *buf)
+{
+	struct scst_dev_type *devt;
+	const char *descr;
+
+	devt = scst_drv_to_devt(drv);
+	descr = (unsigned)devt->type < ARRAY_SIZE(scst_dev_handler_types) ?
+		scst_dev_handler_types[devt->type] : "unknown";
+	return scnprintf(buf, PAGE_SIZE, "%s\n", descr);
+}
+
+static const struct driver_attribute scst_devt_type_description_attr =
+	__ATTR(type_description, S_IRUGO, scst_devt_type_description_show,
+	       NULL);
+
 static const struct driver_attribute *scst_devt_default_attrs[] = {
 	&scst_devt_type_attr,
+	&scst_devt_type_description_attr,
 	NULL
 };
 
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux