Skip to contentSkip to conversation

added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4

PATCH In review Jonathan Mayer 3 participants 9 messages Oct 20, 2005 – Oct 21, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4

Greetings, programs.

I would like to submit this patch to the sysdev subsystem. Previously, sysdev show/store methods were only passed pointers to sys_device objects, but not pointers to the actual sysdev_attribute object that the show/store method is operating on. This is bad because:
1. it means you need to have one show and one store method defined
for every attribute
2. it precludes the ability to create sys_device objects whose
attributes are not known at compile time (such as an sysfs representation of the smbios table for some platforms -- which will be my next patch submission).

I also took the liberty of adding a glib-style "void *" pointer to the sysdev_attribute object, enabling us to stuff arbitrary identifying information into that structure. This saves us the trouble of having to do something silly such as identify the attribute by parsing the name string, or comparing against a table of attribute pointers.

I've compiled and tested this on my x86_64 test systems. It's a pretty simple patch, I have high hopes it'll "just work" on all platforms.

Hey, my first kernel patch! Rock! Did I do it right?

- Jonathan Mayer

----->8 snip

diff -ur linux-2.6.13.4.orig/arch/arm/kernel/time.c linux-2.6.13.4.new/arch/arm/kernel/time.c
--- linux-2.6.13.4.orig/arch/arm/kernel/time.c 2005-10-19
10:26:09.000000000 -0700
+++ linux-2.6.13.4.new/arch/arm/kernel/time.c 2005-10-19
10:32:25.000000000 -0700
@@ -143,7 +143,7 @@
{ "red", led_red_on, led_red_off },
};

-static ssize_t leds_store(struct sys_device *dev, const char *buf, size_t size) +static ssize_t leds_store(struct sys_device *dev, struct sysdev_attribute *attr, const char *buf, size_t size)
{
int ret = -EINVAL, len = strcspn(buf, " ");

diff -ur linux-2.6.13.4.orig/arch/ppc64/kernel/sysfs.c linux-2.6.13.4.new/arch/ppc64/kernel/sysfs.c
--- linux-2.6.13.4.orig/arch/ppc64/kernel/sysfs.c 2005-10-19
10:26:10.000000000 -0700
+++ linux-2.6.13.4.new/arch/ppc64/kernel/sysfs.c 2005-10-19
10:32:25.000000000 -0700
@@ -28,8 +28,8 @@
/* default to snooze disabled */ DEFINE_PER_CPU(unsigned long, smt_snooze_delay);

-static ssize_t store_smt_snooze_delay(struct sys_device *dev, const char *buf,
- size_t count)
+static ssize_t store_smt_snooze_delay(struct sys_device *dev, struct sysdev_attribute *attr,
+ const char *buf, size_t count)
{
struct cpu *cpu = container_of(dev, struct cpu, sysdev); ssize_t ret;
@@ -44,7 +44,8 @@
return count;
}

-static ssize_t show_smt_snooze_delay(struct sys_device *dev, char *buf) +static ssize_t show_smt_snooze_delay(struct sys_device *dev, struct sysdev_attribute *attr,
+ char *buf)
{
struct cpu *cpu = container_of(dev, struct cpu, sysdev);

@@ -200,14 +201,14 @@
mtspr(ADDRESS, val); \
return 0; \
} \
-static ssize_t show_##NAME(struct sys_device *dev, char *buf) \
+static ssize_t show_##NAME(struct sys_device *dev, struct sysdev_attribute *attr, char *buf) \
{ \
struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
unsigned long val = run_on_cpu(cpu->sysdev.id, read_##NAME, 0); \
return sprintf(buf, "%lx\n", val); \
} \
static ssize_t __attribute_used__ \
- store_##NAME(struct sys_device *dev, const char *buf, size_t count) \
+ store_##NAME(struct sys_device *dev, struct sysdev_attribute *attr,
const char *buf, size_t count) \
{ \
struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
unsigned long val; \
@@ -367,7 +368,7 @@
#endif

/* Only valid if CPU is present. */
-static ssize_t show_physical_id(struct sys_device *dev, char *buf) +static ssize_t show_physical_id(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
{
struct cpu *cpu = container_of(dev, struct cpu, sysdev);

diff -ur linux-2.6.13.4.orig/arch/sh/drivers/dma/dma-sysfs.c linux-2.6.13.4.new/arch/sh/drivers/dma/dma-sysfs.c
--- linux-2.6.13.4.orig/arch/sh/drivers/dma/dma-sysfs.c 2005-10-19
10:26:11.000000000 -0700
+++ linux-2.6.13.4.new/arch/sh/drivers/dma/dma-sysfs.c 2005-10-19
10:32:25.000000000 -0700
@@ -21,7 +21,7 @@

EXPORT_SYMBOL(dma_sysclass);

-static ssize_t dma_show_devices(struct sys_device *dev, char *buf) +static ssize_t dma_show_devices(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
{
ssize_t len = 0;
int i;
@@ -53,13 +53,13 @@

postcore_initcall(dma_sysclass_init);

-static ssize_t dma_show_dev_id(struct sys_device *dev, char *buf) +static ssize_t dma_show_dev_id(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
{
struct dma_channel *channel = to_dma_channel(dev); return sprintf(buf, "%s\n", channel->dev_id);
}

-static ssize_t dma_store_dev_id(struct sys_device *dev, +static ssize_t dma_store_dev_id(struct sys_device *dev, struct sysdev_attribute *attr,
const char *buf, size_t count)
{
struct dma_channel *channel = to_dma_channel(dev);
@@ -69,7 +69,7 @@

static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id,
dma_store_dev_id);

-static ssize_t dma_store_config(struct sys_device *dev, +static ssize_t dma_store_config(struct sys_device *dev, struct sysdev_attribute *attr,
const char *buf, size_t count)
{
struct dma_channel *channel = to_dma_channel(dev);
@@ -83,13 +83,13 @@

static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);

-static ssize_t dma_show_mode(struct sys_device *dev, char *buf) +static ssize_t dma_show_mode(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
{
struct dma_channel *channel = to_dma_channel(dev); return sprintf(buf, "0x%08x\n", channel->mode);
}

-static ssize_t dma_store_mode(struct sys_device *dev,
+static ssize_t dma_store_mode(struct sys_device *dev, struct sysdev_attribute *attr,
const char *buf, size_t count)
{
struct dma_channel *channel = to_dma_channel(dev);
@@ -100,7 +100,9 @@
static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);

#define dma_ro_attr(field, fmt) \
-static ssize_t dma_show_##field(struct sys_device *dev, char *buf) \
+static ssize_t dma_show_##field(struct sys_device *dev, \
+ struct sysdev_attribute *attr, \
+ char *buf) \
{ \
struct dma_channel *channel = to_dma_channel(dev); \
return sprintf(buf, fmt, channel->field); \
diff -ur linux-2.6.13.4.orig/arch/x86_64/kernel/mce.c linux-2.6.13.4.new/arch/x86_64/kernel/mce.c
--- linux-2.6.13.4.orig/arch/x86_64/kernel/mce.c 2005-10-19
10:26:19.000000000 -0700
+++ linux-2.6.13.4.new/arch/x86_64/kernel/mce.c 2005-10-19
10:32:25.000000000 -0700
@@ -528,10 +528,14 @@

/* Why are there no generic functions for this? */ #define ACCESSOR(name, var, start) \
- static ssize_t show_ ## name(struct sys_device *s, char *buf) { \
+ static ssize_t show_ ## name(struct sys_device *s, \
+ struct sysdev_attribute *attr,

             \

+ char *buf) { \
return sprintf(buf, "%lx\n", (unsigned long)var); \
} \
- static ssize_t set_ ## name(struct sys_device *s,const char
*buf,size_t siz) { \
+ static ssize_t set_ ## name(struct sys_device *s, \
+ struct sysdev_attribute *attr,

             \
+                                    const char *buf,size_t siz) {    
             \

char *end; \
unsigned long new = simple_strtoul(buf, &end, 0); \
if (end == buf) return -EINVAL; \
diff -ur linux-2.6.13.4.orig/drivers/base/cpu.c
linux-2.6.13.4.new/drivers/base/cpu.c

drivers/base/cpu.c +1 -1
@@ -21,15 +21,15 @@
 	return 0;
 }
 
-static ssize_t show_online(struct sys_device *dev, char *buf)
+static ssize_t show_online(struct sys_device *dev, struct

sysdev_attribute *attr, char *buf)
{
struct cpu *cpu = container_of(dev, struct cpu, sysdev);

return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id));
}

-static ssize_t store_online(struct sys_device *dev, const char *buf,
- size_t count)
+static ssize_t store_online(struct sys_device *dev, struct sysdev_attribute *attr,
+ const char *buf, size_t count)
{
struct cpu *cpu = container_of(dev, struct cpu, sysdev); ssize_t ret;
diff -ur linux-2.6.13.4.orig/drivers/base/node.c linux-2.6.13.4.new/drivers/base/node.c

drivers/base/node.c +1 -1
@@ -17,7 +17,7 @@
 };
 
 
-static ssize_t node_read_cpumap(struct sys_device * dev, char * buf)
+static ssize_t node_read_cpumap(struct sys_device * dev, struct

sysdev_attribute *attr, char * buf)
{
struct node *node_dev = to_node(dev); cpumask_t mask = node_to_cpumask(node_dev->sysdev.id);
@@ -34,7 +34,8 @@
static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumap, NULL);

#define K(x) ((x) << (PAGE_SHIFT - 10))
-static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) +static ssize_t node_read_meminfo(struct sys_device * dev, struct sysdev_attribute *attr,
+ char * buf)
{
int n;
int nid = dev->id;
@@ -72,7 +73,8 @@
#undef K
static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);

-static ssize_t node_read_numastat(struct sys_device * dev, char * buf) +static ssize_t node_read_numastat(struct sys_device * dev, struct sysdev_attribute *attr,
+ char * buf)
{
unsigned long numa_hit, numa_miss, interleave_hit, numa_foreign; unsigned long local_node, other_node;
@@ -112,7 +114,8 @@
}
static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);

-static ssize_t node_read_distance(struct sys_device * dev, char * buf) +static ssize_t node_read_distance(struct sys_device * dev, struct sysdev_attribute *attr,
+ char * buf)
{
int nid = dev->id;
int len = 0;
diff -ur linux-2.6.13.4.orig/drivers/base/sys.c linux-2.6.13.4.new/drivers/base/sys.c

drivers/base/sys.c +2 -2
@@ -35,7 +35,7 @@
 	struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr);
 
 	if (sysdev_attr->show)
-		return sysdev_attr->show(sysdev, buffer);
+		return sysdev_attr->show(sysdev, sysdev_attr, buffer);
 	return -EIO;
 }
 
@@ -48,7 +48,7 @@
 	struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr);
 
 	if (sysdev_attr->store)
-		return sysdev_attr->store(sysdev, buffer, count);
+		return sysdev_attr->store(sysdev, sysdev_attr, buffer, count);
 	return -EIO;
 }
 

diff -ur linux-2.6.13.4.orig/include/linux/sysdev.h linux-2.6.13.4.new/include/linux/sysdev.h
--- linux-2.6.13.4.orig/include/linux/sysdev.h 2005-10-19
10:27:19.000000000 -0700
+++ linux-2.6.13.4.new/include/linux/sysdev.h 2005-10-19
10:32:25.000000000 -0700
@@ -74,21 +74,26 @@
extern int sysdev_register(struct sys_device *); extern void sysdev_unregister(struct sys_device *);

-
-struct sysdev_attribute {
+struct sysdev_attribute {
struct attribute attr;
- ssize_t (*show)(struct sys_device *, char *);
- ssize_t (*store)(struct sys_device *, const char *, size_t);
+ ssize_t (*show)(struct sys_device *, struct sysdev_attribute *, char *);
+ ssize_t (*store)(struct sys_device *, struct sysdev_attribute *,
const char *, size_t);
+ void * data;
};

-#define SYSDEV_ATTR(_name,_mode,_show,_store) \
+
+#define SYSDEV_ATTR_WITH_DATA(_name,_mode,_show,_store,_data) \
struct sysdev_attribute attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \
.show = _show, \
.store = _store, \
+ .data = _data, \
};

+#define SYSDEV_ATTR(_name,_mode,_show,_store) \
+ SYSDEV_ATTR_WITH_DATA(_name,_mode,_show,_store,NULL)
+
extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *); extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *);

#1 lore raw
Quoted 5 lines · Jonathan Mayer

2. it precludes the ability to create sys_device objects whose
attributes are not known at compile time (such as an sysfs representation of the smbios table for some platforms -- which will be my next patch submission).

Does this smbios table have to be a system device (does it have to be suspended and resumed with interrupts off) or maybe platform bus suits it better?

--
Dmitry

#2 lore raw

Surely, the organization of sysfs is logical (by grouping relating things) rather than functional (by grouping things that need common back-end interfaces).

Er .. no?

In general, where can I find guidance on where to put things within sysfs? Has anybody written some kind of Plan?

- jm.

Quoted 15 lines · Dmitry Torokhov
Quoted 5 lines · Jonathan Mayer

2. it precludes the ability to create sys_device objects whose
attributes are not known at compile time (such as an sysfs representation of the smbios table for some platforms -- which will be my next patch submission).

Does this smbios table have to be a system device (does it have to be suspended and resumed with interrupts off) or maybe platform bus suits it better?

--
Dmitry

#3 lore raw
Quoted 9 lines · Jonathan Mayer

Surely, the organization of sysfs is logical (by grouping relating things) rather than functional (by grouping things that need common back-end interfaces).

Er .. no?

In general, where can I find guidance on where to put things within sysfs? Has anybody written some kind of Plan?

If it is a device it goes onto corresponding bus. Platform bus is a kind of a kitchen sink for things that do not have a "real" bus - things like keyboard controller, older ISA devices, etc. Only things that necessary to get the box going and have to be suspended last with interrupts off (like IRQ controller) should be implemented as system devices.

--
Dmitry

#4 lore raw
Quoted 6 lines

If it is a device it goes onto corresponding bus. Platform bus is a kind of a kitchen sink for things that do not have a "real" bus - things like keyboard controller, older ISA devices, etc. Only things that necessary to get the box going and have to be suspended last with interrupts off (like IRQ controller) should be implemented as system devices.

I see! Okay, I will make this so. Thanks for the explanation.

Even so, I still think my patch is a good idea (for the sysdev attributes, and all kobject attribute derived thingies in general).

- Jonathan.

#5 lore raw
Quoted 11 lines · Jonathan Mayer
Quoted 6 lines

If it is a device it goes onto corresponding bus. Platform bus is a kind of a kitchen sink for things that do not have a "real" bus - things like keyboard controller, older ISA devices, etc. Only things that necessary to get the box going and have to be suspended last with interrupts off (like IRQ controller) should be implemented as system devices.

I see! Okay, I will make this so. Thanks for the explanation.

Even so, I still think my patch is a good idea (for the sysdev attributes, and all kobject attribute derived thingies in general).

It is a good idea, if someone needs access to that attribute information. But for now, no one does. When they do, I'll be glad to accept the patch.

Oh, and Pat isn't the driver core maintainer anymore...

thanks,

greg k-h

#6 lore raw
Quoted 3 lines

It is a good idea, if someone needs access to that attribute information. But for now, no one does. When they do, I'll be glad to accept the patch.

Hi Greg,

My only concern, then, is that by the time somebody needs this patch, the set of sysdev objects will have grown, requiring a big patch instead of a small one. I would also argue that even existing sysdev objects could be rewritten and cleaned up slightly (remove proliferation of methods) by using the attribute.

If you like, I could try doing that and submit it as part of this patch...

Thanks!

- Jonathan.

#7 lore raw
Quoted 9 lines · Jonathan Mayer
Quoted 3 lines

It is a good idea, if someone needs access to that attribute information. But for now, no one does. When they do, I'll be glad to accept the patch.

Hi Greg,

My only concern, then, is that by the time somebody needs this patch, the set of sysdev objects will have grown, requiring a big patch instead of a small one.

So? That's not a big deal, split it into more pieces. That's what was done when people did the same for the device attributes.

Quoted 3 lines

I would also argue that even existing sysdev objects could be rewritten and cleaned up slightly (remove proliferation of methods) by using the attribute.

Now that would be a justification for accepting the patch, and is why I took it for the device attributes.

Quoted 1 line

If you like, I could try doing that and submit it as part of this patch...

That would be fine.

thanks,

greg k-h

#8 lore raw
In reply to Jonathan Mayer

That was discouraging. My patch got word-wrapped by my editor. Instead, see attachment.

Sorry,
- Jonathan.

arch/arm/kernel/time.c +1 -1
diff -ur linux-2.6.13.4.orig/arch/arm/kernel/time.c linux-2.6.13.4.new/arch/arm/kernel/time.c
@@ -143,7 +143,7 @@
 	{ "red",   led_red_on,   led_red_off   },
 };
 
-static ssize_t leds_store(struct sys_device *dev, const char *buf, size_t size)
+static ssize_t leds_store(struct sys_device *dev, struct sysdev_attribute *attr, const char *buf, size_t size)
 {
 	int ret = -EINVAL, len = strcspn(buf, " ");
 
arch/ppc64/kernel/sysfs.c +7 -6
diff -ur linux-2.6.13.4.orig/arch/ppc64/kernel/sysfs.c linux-2.6.13.4.new/arch/ppc64/kernel/sysfs.c
@@ -28,8 +28,8 @@
 /* default to snooze disabled */
 DEFINE_PER_CPU(unsigned long, smt_snooze_delay);
 
-static ssize_t store_smt_snooze_delay(struct sys_device *dev, const char *buf,
-				      size_t count)
+static ssize_t store_smt_snooze_delay(struct sys_device *dev, struct sysdev_attribute *attr,
+                                      const char *buf, size_t count)
 {
 	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
 	ssize_t ret;
@@ -44,7 +44,8 @@
 	return count;
 }
 
-static ssize_t show_smt_snooze_delay(struct sys_device *dev, char *buf)
+static ssize_t show_smt_snooze_delay(struct sys_device *dev, struct sysdev_attribute *attr,
+                                     char *buf)
 {
 	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
 
@@ -200,14 +201,14 @@
 	mtspr(ADDRESS, val); \
 	return 0; \
 } \
-static ssize_t show_##NAME(struct sys_device *dev, char *buf) \
+static ssize_t show_##NAME(struct sys_device *dev, struct sysdev_attribute *attr, char *buf) \
 { \
 	struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
 	unsigned long val = run_on_cpu(cpu->sysdev.id, read_##NAME, 0); \
 	return sprintf(buf, "%lx\n", val); \
 } \
 static ssize_t __attribute_used__ \
-	store_##NAME(struct sys_device *dev, const char *buf, size_t count) \
+	store_##NAME(struct sys_device *dev, struct sysdev_attribute *attr, const char *buf, size_t count) \
 { \
 	struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
 	unsigned long val; \
@@ -367,7 +368,7 @@
 #endif
 
 /* Only valid if CPU is present. */
-static ssize_t show_physical_id(struct sys_device *dev, char *buf)
+static ssize_t show_physical_id(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
 {
 	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
 
arch/sh/drivers/dma/dma-sysfs.c +9 -7
diff -ur linux-2.6.13.4.orig/arch/sh/drivers/dma/dma-sysfs.c linux-2.6.13.4.new/arch/sh/drivers/dma/dma-sysfs.c
@@ -21,7 +21,7 @@
 
 EXPORT_SYMBOL(dma_sysclass);
 
-static ssize_t dma_show_devices(struct sys_device *dev, char *buf)
+static ssize_t dma_show_devices(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
 {
 	ssize_t len = 0;
 	int i;
@@ -53,13 +53,13 @@
 
 postcore_initcall(dma_sysclass_init);
 
-static ssize_t dma_show_dev_id(struct sys_device *dev, char *buf)
+static ssize_t dma_show_dev_id(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
 {
 	struct dma_channel *channel = to_dma_channel(dev);
 	return sprintf(buf, "%s\n", channel->dev_id);
 }
 
-static ssize_t dma_store_dev_id(struct sys_device *dev,
+static ssize_t dma_store_dev_id(struct sys_device *dev, struct sysdev_attribute *attr,
 				const char *buf, size_t count)
 {
 	struct dma_channel *channel = to_dma_channel(dev);
@@ -69,7 +69,7 @@
 
 static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
 
-static ssize_t dma_store_config(struct sys_device *dev,
+static ssize_t dma_store_config(struct sys_device *dev, struct sysdev_attribute *attr,
 				const char *buf, size_t count)
 {
 	struct dma_channel *channel = to_dma_channel(dev);
@@ -83,13 +83,13 @@
 
 static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
 
-static ssize_t dma_show_mode(struct sys_device *dev, char *buf)
+static ssize_t dma_show_mode(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
 {
 	struct dma_channel *channel = to_dma_channel(dev);
 	return sprintf(buf, "0x%08x\n", channel->mode);
 }
 
-static ssize_t dma_store_mode(struct sys_device *dev,
+static ssize_t dma_store_mode(struct sys_device *dev, struct sysdev_attribute *attr,
 			      const char *buf, size_t count)
 {
 	struct dma_channel *channel = to_dma_channel(dev);
@@ -100,7 +100,9 @@
 static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
 
 #define dma_ro_attr(field, fmt)						\
-static ssize_t dma_show_##field(struct sys_device *dev, char *buf)	\
+static ssize_t dma_show_##field(struct sys_device *dev,                 \
+                                struct sysdev_attribute *attr,          \
+                                char *buf)	                        \
 {									\
 	struct dma_channel *channel = to_dma_channel(dev);		\
 	return sprintf(buf, fmt, channel->field);			\
arch/x86_64/kernel/mce.c +6 -2
diff -ur linux-2.6.13.4.orig/arch/x86_64/kernel/mce.c linux-2.6.13.4.new/arch/x86_64/kernel/mce.c
@@ -528,10 +528,14 @@
 
 /* Why are there no generic functions for this? */
 #define ACCESSOR(name, var, start) \
-	static ssize_t show_ ## name(struct sys_device *s, char *buf) { 	   	   \
+	static ssize_t show_ ## name(struct sys_device *s,                         \
+                                     struct sysdev_attribute *attr,                \
+                                     char *buf) { 	   	                   \
 		return sprintf(buf, "%lx\n", (unsigned long)var);		   \
 	} 									   \
-	static ssize_t set_ ## name(struct sys_device *s,const char *buf,size_t siz) { \
+	static ssize_t set_ ## name(struct sys_device *s,                          \
+                                    struct sysdev_attribute *attr,                 \
+                                    const char *buf,size_t siz) {                  \
 		char *end; 							   \
 		unsigned long new = simple_strtoul(buf, &end, 0); 		   \
 		if (end == buf) return -EINVAL;					   \
drivers/base/cpu.c +3 -3
diff -ur linux-2.6.13.4.orig/drivers/base/cpu.c linux-2.6.13.4.new/drivers/base/cpu.c
@@ -21,15 +21,15 @@
 	return 0;
 }
 
-static ssize_t show_online(struct sys_device *dev, char *buf)
+static ssize_t show_online(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
 {
 	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
 
 	return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id));
 }
 
-static ssize_t store_online(struct sys_device *dev, const char *buf,
-			    size_t count)
+static ssize_t store_online(struct sys_device *dev, struct sysdev_attribute *attr, 
+                            const char *buf, size_t count)
 {
 	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
 	ssize_t ret;
drivers/base/node.c +7 -4
diff -ur linux-2.6.13.4.orig/drivers/base/node.c linux-2.6.13.4.new/drivers/base/node.c
@@ -17,7 +17,7 @@
 };
 
 
-static ssize_t node_read_cpumap(struct sys_device * dev, char * buf)
+static ssize_t node_read_cpumap(struct sys_device * dev, struct sysdev_attribute *attr, char * buf)
 {
 	struct node *node_dev = to_node(dev);
 	cpumask_t mask = node_to_cpumask(node_dev->sysdev.id);
@@ -34,7 +34,8 @@
 static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumap, NULL);
 
 #define K(x) ((x) << (PAGE_SHIFT - 10))
-static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
+static ssize_t node_read_meminfo(struct sys_device * dev, struct sysdev_attribute *attr,
+                                 char * buf)
 {
 	int n;
 	int nid = dev->id;
@@ -72,7 +73,8 @@
 #undef K
 static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
 
-static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
+static ssize_t node_read_numastat(struct sys_device * dev, struct sysdev_attribute *attr,
+                                  char * buf)
 {
 	unsigned long numa_hit, numa_miss, interleave_hit, numa_foreign;
 	unsigned long local_node, other_node;
@@ -112,7 +114,8 @@
 }
 static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
 
-static ssize_t node_read_distance(struct sys_device * dev, char * buf)
+static ssize_t node_read_distance(struct sys_device * dev, struct sysdev_attribute *attr,
+                                  char * buf)
 {
 	int nid = dev->id;
 	int len = 0;
drivers/base/sys.c +2 -2
diff -ur linux-2.6.13.4.orig/drivers/base/sys.c linux-2.6.13.4.new/drivers/base/sys.c
@@ -35,7 +35,7 @@
 	struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr);
 
 	if (sysdev_attr->show)
-		return sysdev_attr->show(sysdev, buffer);
+		return sysdev_attr->show(sysdev, sysdev_attr, buffer);
 	return -EIO;
 }
 
@@ -48,7 +48,7 @@
 	struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr);
 
 	if (sysdev_attr->store)
-		return sysdev_attr->store(sysdev, buffer, count);
+		return sysdev_attr->store(sysdev, sysdev_attr, buffer, count);
 	return -EIO;
 }
 
include/linux/sysdev.h +10 -5
diff -ur linux-2.6.13.4.orig/include/linux/sysdev.h linux-2.6.13.4.new/include/linux/sysdev.h
@@ -74,21 +74,26 @@
 extern int sysdev_register(struct sys_device *);
 extern void sysdev_unregister(struct sys_device *);
 
-
-struct sysdev_attribute { 
+struct sysdev_attribute {
 	struct attribute	attr;
-	ssize_t (*show)(struct sys_device *, char *);
-	ssize_t (*store)(struct sys_device *, const char *, size_t);
+	ssize_t (*show)(struct sys_device *, struct sysdev_attribute *, char *);
+	ssize_t (*store)(struct sys_device *, struct sysdev_attribute *, const char *, size_t);
+        void * data;
 };
 
 
-#define SYSDEV_ATTR(_name,_mode,_show,_store) 		\
+
+#define SYSDEV_ATTR_WITH_DATA(_name,_mode,_show,_store,_data) 		\
 struct sysdev_attribute attr_##_name = { 			\
 	.attr = {.name = __stringify(_name), .mode = _mode },	\
 	.show	= _show,					\
 	.store	= _store,					\
+        .data   = _data,                                        \
 };
 
+#define SYSDEV_ATTR(_name,_mode,_show,_store) 		\
+  SYSDEV_ATTR_WITH_DATA(_name,_mode,_show,_store,NULL)
+
 extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *);
 extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *);