
From: Mikael Pettersson <mikpe@csd.uu.se>

Perfctr sysfs update:
- Simplify perfctr sysfs code.

Signed-off-by: Mikael Pettersson <mikpe@csd.uu.se>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/drivers/perfctr/init.c |   58 +++++++++++++++--------------------------
 1 files changed, 22 insertions(+), 36 deletions(-)

diff -puN drivers/perfctr/init.c~perfctr-sysfs-update drivers/perfctr/init.c
--- 25/drivers/perfctr/init.c~perfctr-sysfs-update	2004-12-03 02:00:30.591235768 -0800
+++ 25-akpm/drivers/perfctr/init.c	2004-12-03 02:00:30.596235008 -0800
@@ -22,81 +22,67 @@ struct perfctr_info perfctr_info = {
 	.driver_version = VERSION,
 };
 
-static struct class perfctr_class = {
-	.name		= "perfctr",
-};
-
 static ssize_t
-perfctr_show_driver_version(struct class *class, char *buf)
+driver_version_show(struct class *class, char *buf)
 {
 	return sprintf(buf, "%s\n", perfctr_info.driver_version);
 }
-static CLASS_ATTR(driver_version,0444,perfctr_show_driver_version,NULL);
 
 static ssize_t
-perfctr_show_cpu_type(struct class *class, char *buf)
+cpu_type_show(struct class *class, char *buf)
 {
 	return sprintf(buf, "%#x\n", perfctr_info.cpu_type);
 }
-static CLASS_ATTR(cpu_type,0444,perfctr_show_cpu_type,NULL);
 
 static ssize_t
-perfctr_show_cpu_features(struct class *class, char *buf)
+cpu_features_show(struct class *class, char *buf)
 {
 	return sprintf(buf, "%#x\n", perfctr_info.cpu_features);
 }
-static CLASS_ATTR(cpu_features,0444,perfctr_show_cpu_features,NULL);
 
 static ssize_t
-perfctr_show_cpu_khz(struct class *class, char *buf)
+cpu_khz_show(struct class *class, char *buf)
 {
 	return sprintf(buf, "%u\n", perfctr_info.cpu_khz);
 }
-static CLASS_ATTR(cpu_khz,0444,perfctr_show_cpu_khz,NULL);
 
 static ssize_t
-perfctr_show_tsc_to_cpu_mult(struct class *class, char *buf)
+tsc_to_cpu_mult_show(struct class *class, char *buf)
 {
 	return sprintf(buf, "%u\n", perfctr_info.tsc_to_cpu_mult);
 }
-static CLASS_ATTR(tsc_to_cpu_mult,0444,perfctr_show_tsc_to_cpu_mult,NULL);
 
 static ssize_t
-perfctr_show_cpus_online(struct class *class, char *buf)
+cpus_online_show(struct class *class, char *buf)
 {
 	int ret = cpumask_scnprintf(buf, PAGE_SIZE-1, cpu_online_map);
 	buf[ret++] = '\n';
 	return ret;
 }
-static CLASS_ATTR(cpus_online,0444,perfctr_show_cpus_online,NULL);
 
 static ssize_t
-perfctr_show_cpus_forbidden(struct class *class, char *buf)
+cpus_forbidden_show(struct class *class, char *buf)
 {
 	int ret = cpumask_scnprintf(buf, PAGE_SIZE-1, perfctr_cpus_forbidden_mask);
 	buf[ret++] = '\n';
 	return ret;
 }
-static CLASS_ATTR(cpus_forbidden,0444,perfctr_show_cpus_forbidden,NULL);
 
-static int __init perfctr_class_init(void)
-{
-	int ret;
+static struct class_attribute perfctr_class_attrs[] = {
+	__ATTR_RO(driver_version),
+	__ATTR_RO(cpu_type),
+	__ATTR_RO(cpu_features),
+	__ATTR_RO(cpu_khz),
+	__ATTR_RO(tsc_to_cpu_mult),
+	__ATTR_RO(cpus_online),
+	__ATTR_RO(cpus_forbidden),
+	__ATTR_NULL
+};
 
-	ret = class_register(&perfctr_class);
-	if (ret)
-		return ret;
-	ret |= class_create_file(&perfctr_class, &class_attr_driver_version);
-	ret |= class_create_file(&perfctr_class, &class_attr_cpu_type);
-	ret |= class_create_file(&perfctr_class, &class_attr_cpu_features);
-	ret |= class_create_file(&perfctr_class, &class_attr_cpu_khz);
-	ret |= class_create_file(&perfctr_class, &class_attr_tsc_to_cpu_mult);
-	ret |= class_create_file(&perfctr_class, &class_attr_cpus_online);
-	ret |= class_create_file(&perfctr_class, &class_attr_cpus_forbidden);
-	if (ret)
-		class_unregister(&perfctr_class);
-	return ret;
-}
+static struct class perfctr_class = {
+	.name		= "perfctr",
+	.class_attrs	= perfctr_class_attrs,
+};
 
 char *perfctr_cpu_name __initdata;
 
@@ -112,7 +98,7 @@ static int __init perfctr_init(void)
 	err = vperfctr_init();
 	if (err)
 		return err;
-	err = perfctr_class_init();
+	err = class_register(&perfctr_class);
 	if (err) {
 		printk(KERN_ERR "perfctr: class initialisation failed\n");
 		return err;
_
