linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI vendor and device strings in sysfs
@ 2003-07-17 10:11 Ananth N Mavinakayanahalli
  2003-07-17 14:55 ` Patrick Mochel
  2003-07-18  2:35 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Ananth N Mavinakayanahalli @ 2003-07-17 10:11 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 814 bytes --]

Hi,

Here is a patch against 2.6.0-test1 to display PCI vendor and
device strings in sysfs.

At present, the PCI "name" attribute has a length restriction
(DEVICE_NAME_SIZE) within which it tries to accomodate the vendor
and device strings, leading to, in most cases, truncation of one
or both strings.

This patch alleviates the issue by creating the vendor_name and
device_name attributes for PCI devices.

Here is an example:

ananth@llm06:/sys/devices/pci0000:00/0000:00:01.0> cat name
Intel Corp. 82810 DC-100 CGC [Ch
ananth@llm06:/sys/devices/pci0000:00/0000:00:01.0> cat vendor_name
Intel Corp.
ananth@llm06:/sys/devices/pci0000:00/0000:00:01.0> cat device_name
82810 DC-100 CGC [Chipset Graphics Controller]

Thanks,
-- 
Ananth Narayan <ananth@in.ibm.com>
Linux Technology Center,
IBM Software Lab, INDIA


[-- Attachment #2: km_pci.patch --]
[-- Type: text/plain, Size: 4920 bytes --]

diff -Naur linux-2.6.0-test1/include/linux/pci.h linux-2.6.0-test1-fix/include/linux/pci.h
--- linux-2.6.0-test1/include/linux/pci.h	2003-07-14 09:04:02.000000000 +0530
+++ linux-2.6.0-test1-fix/include/linux/pci.h	2003-07-17 14:23:05.000000000 +0530
@@ -416,6 +416,10 @@
 
 	char *		slot_name;	/* pointer to dev.bus_id */
 
+	/* pointer to export vendor and device strings to sysfs */
+	char *		vendor_name;
+	char *		device_name;
+
 	/* These fields are used by common fixups */
 	unsigned int	transparent:1;	/* Transparent PCI bridge */
 	unsigned int	multifunction:1;/* Part of multi-function device */

diff -Naur linux-2.6.0-test1/drivers/pci/names.c linux-2.6.0-test1-fix/drivers/pci/names.c
--- linux-2.6.0-test1/drivers/pci/names.c	2003-07-14 09:00:37.000000000 +0530
+++ linux-2.6.0-test1-fix/drivers/pci/names.c	2003-07-17 14:35:10.000000000 +0530
@@ -57,6 +57,8 @@
 	const struct pci_vendor_info *vendor_p = pci_vendor_list;
 	int i = VENDORS;
 	char *name = dev->dev.name;
+	char *vendor_unknown = "Unknown vendor";
+	char *device_unknown = "Unknown device";
 
 	do {
 		if (vendor_p->vendor == dev->vendor)
@@ -66,7 +68,15 @@
 
 	/* Couldn't find either the vendor nor the device */
 	sprintf(name, "PCI device %04x:%04x", dev->vendor, dev->device);
-	return;
+	dev->vendor_name = kmalloc(strlen(vendor_unknown)+1, GFP_KERNEL);
+	if (!dev->vendor_name)
+		goto out;
+	strcpy(dev->vendor_name, vendor_unknown);
+	dev->device_name = kmalloc(strlen(device_unknown)+1, GFP_KERNEL);
+	if (!dev->device_name)
+		goto out;
+	strcpy(dev->device_name, device_unknown);
+	goto out;
 
 	match_vendor: {
 		struct pci_device_info *device_p = vendor_p->devices;
@@ -82,19 +92,39 @@
 		/* Ok, found the vendor, but unknown device */
 		sprintf(name, "PCI device %04x:%04x (%." DEVICE_NAME_HALF "s)",
 				dev->vendor, dev->device, vendor_p->name);
-		return;
+		dev->vendor_name = kmalloc(strlen(vendor_p->name)+1, GFP_KERNEL);
+		if (!dev->vendor_name)
+			goto out;
+		strcpy(dev->vendor_name, vendor_p->name);
+		dev->device_name = kmalloc(strlen(device_unknown)+1, GFP_KERNEL);
+		if (!dev->device_name)
+			goto out;
+		strcpy(dev->device_name, device_unknown);
+		goto out;
 
 		/* Full match */
 		match_device: {
 			char *n = name + sprintf(name, "%." DEVICE_NAME_HALF
 					"s %." DEVICE_NAME_HALF "s",
 					vendor_p->name, device_p->name);
-			int nr = device_p->seen + 1;
-			device_p->seen = nr;
-			if (nr > 1)
-				sprintf(n, " (#%d)", nr);
+
+			dev->vendor_name = kmalloc(strlen(vendor_p->name)+1, GFP_KERNEL);
+			if (!dev->vendor_name)
+				goto update_count;
+			strcpy(dev->vendor_name, vendor_p->name);
+			dev->device_name = kmalloc(strlen(device_p->name)+1, GFP_KERNEL);
+			if (dev->device_name)
+				strcpy(dev->device_name, device_p->name);
+			update_count: {
+				int nr = device_p->seen + 1;
+				device_p->seen = nr;
+				if (nr > 1)
+					sprintf(n, " (#%d)", nr);
+			}
 		}
 	}
+out:
+	return;
 }
 
 /*

diff -Naur linux-2.6.0-test1/drivers/pci/pci-sysfs.c linux-2.6.0-test1-fix/drivers/pci/pci-sysfs.c
--- linux-2.6.0-test1/drivers/pci/pci-sysfs.c	2003-07-14 09:04:40.000000000 +0530
+++ linux-2.6.0-test1-fix/drivers/pci/pci-sysfs.c	2003-07-16 12:03:16.000000000 +0530
@@ -39,6 +39,42 @@
 pci_config_attr(class, "0x%06x\n");
 pci_config_attr(irq, "%u\n");
 
+/* show vendor name */
+static ssize_t
+pci_show_vendor_name(struct device *dev, char *buf)
+{
+	struct pci_dev * pci_dev = to_pci_dev(dev);
+	int len;
+	
+	if (!pci_dev->vendor_name)
+		return 0;
+	strcpy(buf, pci_dev->vendor_name);
+	len = strlen(pci_dev->vendor_name);
+	buf[len] = '\n';
+	buf[len+1] = 0;
+	return len+1;
+}
+
+static DEVICE_ATTR(vendor_name,S_IRUGO,pci_show_vendor_name,NULL);
+	
+/* show device name */
+static ssize_t
+pci_show_device_name(struct device *dev, char *buf)
+{
+	struct pci_dev * pci_dev = to_pci_dev(dev);
+	int len;
+	
+	if (!pci_dev->device_name)
+		return 0;
+	strcpy(buf, pci_dev->device_name);
+	len = strlen(pci_dev->device_name);
+	buf[len] = '\n';
+	buf[len+1] = 0;
+	return len+1;
+}
+
+static DEVICE_ATTR(device_name,S_IRUGO,pci_show_device_name,NULL);
+
 /* show resources */
 static ssize_t
 pci_show_resources(struct device * dev, char * buf)
@@ -176,5 +212,7 @@
 	device_create_file (dev, &dev_attr_class);
 	device_create_file (dev, &dev_attr_irq);
 	device_create_file (dev, &dev_attr_resource);
+	device_create_file (dev, &dev_attr_vendor_name);
+	device_create_file (dev, &dev_attr_device_name);
 	sysfs_create_bin_file(&dev->kobj, &pci_config_attr);
 }

diff -Naur linux-2.6.0-test1/drivers/pci/probe.c linux-2.6.0-test1-fix/drivers/pci/probe.c
--- linux-2.6.0-test1/drivers/pci/probe.c	2003-07-14 09:06:33.000000000 +0530
+++ linux-2.6.0-test1-fix/drivers/pci/probe.c	2003-07-15 17:25:42.000000000 +0530
@@ -478,6 +478,8 @@
 	struct pci_dev *pci_dev;
 
 	pci_dev = to_pci_dev(dev);
+	kfree(pci_dev->vendor_name);
+	kfree(pci_dev->device_name);
 	kfree(pci_dev);
 }
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-07-18  2:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-17 10:11 [PATCH] PCI vendor and device strings in sysfs Ananth N Mavinakayanahalli
2003-07-17 14:55 ` Patrick Mochel
2003-07-18  2:35 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).