Skip to contentSkip to conversation

PCI Express Advanced Error Reporting Driver

PATCH In review long 2 participants 2 messages Mar 11, 2005 – Mar 12, 2005 PCI

lore
Share & tools
lore

long

author
#0 lore raw

PATCH 2/6 PCI Express Advanced Error Reporting Driver

This patch includes the source code of sysfs component of PCI Express Advanced Error Reporting driver.

--------------------------------------------------------------------

drivers/pci/pcie/aer/aerdrv_sysfs.c +87 -0
diff -urpN linux-2.6.11-rc5/drivers/pci/pcie/aer/aerdrv_sysfs.c patch-2.6.11-rc5-aerc3-split2/drivers/pci/pcie/aer/aerdrv_sysfs.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2005 Intel
+ * Copyright (C) Tom Long Nguyen ([email protected])
+ *
+ */
+
+#include "aerdrv_sysfs.h"
+                  	
+static ssize_t aer_sysfs_consume_show(struct device_driver *dev, char *buf)
+{
+	return aer_fsprint_record(buf);
+}
+                  	
+static ssize_t aer_sysfs_status_show(struct device_driver *dev, char *buf)
+{
+	return aer_fsprint_devices(buf);
+}
+                  	
+static ssize_t aer_sysfs_verbose_show(struct device_driver *dev, char *buf)
+{
+	return sprintf(buf, "Verbose display set to %d\n", 
+		aer_get_verbose());				
+}
+                  	
+static ssize_t aer_sysfs_verbose_store(struct device_driver *drv, 	
+					const char *buf, size_t count)  
+{                            
+	aer_set_verbose(buf[0] - 0x30);			
+	return count;							
+}
+
+static ssize_t aer_sysfs_auto_show(struct device_driver *dev, char *buf)
+{
+	return sprintf(buf, "Automatic reporting is %s\n", 		
+		(aer_get_auto_mode()) ? "on" : "off");  			
+}
+                  	
+static ssize_t aer_sysfs_auto_store(struct device_driver *drv, 	
+					const char *buf, size_t count)          
+{                            
+	aer_set_auto_mode(buf[0] - 0x30);			
+	return count;							
+}
+
+/*
+ * Define AER Sysfs user interfaces
+ */
+static DRIVER_ATTR(consume, S_IRUGO, aer_sysfs_consume_show, NULL);
+static DRIVER_ATTR(status, S_IRUGO, aer_sysfs_status_show, NULL);
+static DRIVER_ATTR(verbose, S_IWUSR | S_IRUGO, aer_sysfs_verbose_show,
+		   aer_sysfs_verbose_store);
+static DRIVER_ATTR(auto, S_IWUSR | S_IRUGO, aer_sysfs_auto_show,
+		   aer_sysfs_auto_store);
+
+static struct attribute *aer_sysfs_driver_attrs[] = {
+	&driver_attr_status.attr,
+	&driver_attr_verbose.attr,
+	&driver_attr_consume.attr,
+	&driver_attr_auto.attr,
+	NULL
+};
+
+static struct attribute_group aer_sysfs_driver_attr_group = {
+	.attrs = aer_sysfs_driver_attrs,
+};
+
+/**
+ * aer_sysfs_init - AER user interface initialization
+ * @drv: pointer to device_driver data structure of AER service driver
+ *
+ * Invoked when AER service driver is loaded. 
+ **/
+int aer_sysfs_init(struct device_driver *drv)
+{
+	return sysfs_create_group(&drv->kobj, &aer_sysfs_driver_attr_group);
+}
+
+/**
+ * aer_sysfs_cleanup - remove AER user interface
+ * @drv: pointer to device_driver data structure of AER service driver
+ *
+ * Invoked when AER service driver is unloaded. 
+ **/
+void aer_sysfs_cleanup(struct device_driver *drv)
+{
+	sysfs_remove_group(&drv->kobj, &aer_sysfs_driver_attr_group);
+}
drivers/pci/pcie/aer/aerdrv_sysfs.h +19 -0
diff -urpN linux-2.6.11-rc5/drivers/pci/pcie/aer/aerdrv_sysfs.h patch-2.6.11-rc5-aerc3-split2/drivers/pci/pcie/aer/aerdrv_sysfs.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2005 Intel
+ * Copyright (C) Tom Long Nguyen ([email protected])
+ *
+ */
+
+#ifndef	_AERDRV_SYSFS_H_
+#define	_AERDRV_SYSFS_H_
+
+#include <linux/device.h>
+
+extern int aer_fsprint_devices(char *page);
+extern int aer_fsprint_record(char *page);
+extern void aer_set_verbose(int value);
+extern int aer_get_verbose(void);
+extern void aer_set_auto_mode(int value);
+extern int aer_get_auto_mode(void);
+
+#endif	//_AERDRV_SYSFS_H_
#1 lore raw

drivers/pci/pcie/aer/aerdrv_sysfs.c line 18

Quoted 10 lines · long
drivers/pci/pcie/aer/aerdrv_sysfs.c +10 -0
+static ssize_t aer_sysfs_consume_show(struct device_driver *dev, char *buf)
+{
+	return aer_fsprint_record(buf);
+}
+                  	
+static ssize_t aer_sysfs_status_show(struct device_driver *dev, char *buf)
+{
+	return aer_fsprint_devices(buf);
+}
+                  	

Why call wrapper functions that only do one thing? Why have this extra layer of indirection that is not needed from what I can tell?

drivers/pci/pcie/aer/aerdrv_sysfs.c line 23

Quoted 5 lines
drivers/pci/pcie/aer/aerdrv_sysfs.c +5 -0
+static ssize_t aer_sysfs_verbose_show(struct device_driver *dev, char *buf)
+{
+	return sprintf(buf, "Verbose display set to %d\n", 
+		aer_get_verbose());				
+}

Just echo the value, don't print out pretty strings :)

drivers/pci/pcie/aer/aerdrv_sysfs.c line 30

Quoted 6 lines
drivers/pci/pcie/aer/aerdrv_sysfs.c +6 -0
+static ssize_t aer_sysfs_verbose_store(struct device_driver *drv, 	
+					const char *buf, size_t count)  
+{                            
+	aer_set_verbose(buf[0] - 0x30);			
+	return count;							
+}

Oh, that's a problem waiting to happen... Please validate the user provided value before acting on it.

drivers/pci/pcie/aer/aerdrv_sysfs.c line 36

Quoted 5 lines
drivers/pci/pcie/aer/aerdrv_sysfs.c +5 -0
+static ssize_t aer_sysfs_auto_show(struct device_driver *dev, char *buf)
+{
+	return sprintf(buf, "Automatic reporting is %s\n", 		
+		(aer_get_auto_mode()) ? "on" : "off");  			
+}

Again, just print on/off.

drivers/pci/pcie/aer/aerdrv_sysfs.c line 43

Quoted 6 lines
drivers/pci/pcie/aer/aerdrv_sysfs.c +6 -0
+static ssize_t aer_sysfs_auto_store(struct device_driver *drv, 	
+					const char *buf, size_t count)          
+{                            
+	aer_set_auto_mode(buf[0] - 0x30);			
+	return count;							
+}

Also validate this.

thanks,

greg k-h