All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4
@ 2005-10-20 21:47 Jonathan Mayer
  2005-10-20 21:59 ` Dmitry Torokhov
  2005-10-20 22:00 ` Jonathan Mayer
  0 siblings, 2 replies; 9+ messages in thread
From: Jonathan Mayer @ 2005-10-20 21:47 UTC (permalink / raw)
  To: Patrick Mochel, linux-kernel

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
--- linux-2.6.13.4.orig/drivers/base/cpu.c	2005-10-19 10:26:20.000000000 -0700
+++ linux-2.6.13.4.new/drivers/base/cpu.c	2005-10-19 10:34:23.000000000 -0700
@@ -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
--- linux-2.6.13.4.orig/drivers/base/node.c	2005-10-19 10:26:20.000000000 -0700
+++ linux-2.6.13.4.new/drivers/base/node.c	2005-10-19 10:32:25.000000000 -0700
@@ -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
--- linux-2.6.13.4.orig/drivers/base/sys.c	2005-10-19 10:26:20.000000000 -0700
+++ linux-2.6.13.4.new/drivers/base/sys.c	2005-10-19 10:35:33.000000000 -0700
@@ -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 *);

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

* Re: [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4
  2005-10-20 21:47 [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4 Jonathan Mayer
@ 2005-10-20 21:59 ` Dmitry Torokhov
  2005-10-20 22:03   ` Jonathan Mayer
  2005-10-20 22:00 ` Jonathan Mayer
  1 sibling, 1 reply; 9+ messages in thread
From: Dmitry Torokhov @ 2005-10-20 21:59 UTC (permalink / raw)
  To: Jonathan Mayer; +Cc: Patrick Mochel, linux-kernel

On 10/20/05, Jonathan Mayer <jonmayer@google.com> wrote:

>  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

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

* Re: [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4
  2005-10-20 21:47 [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4 Jonathan Mayer
  2005-10-20 21:59 ` Dmitry Torokhov
@ 2005-10-20 22:00 ` Jonathan Mayer
  1 sibling, 0 replies; 9+ messages in thread
From: Jonathan Mayer @ 2005-10-20 22:00 UTC (permalink / raw)
  To: Patrick Mochel, linux-kernel

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

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

Sorry,
 - Jonathan.

[-- Attachment #2: sysdev_showstore.patch.txt --]
[-- Type: text/plain, Size: 11115 bytes --]

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
--- linux-2.6.13.4.orig/drivers/base/cpu.c	2005-10-19 10:26:20.000000000 -0700
+++ linux-2.6.13.4.new/drivers/base/cpu.c	2005-10-19 10:34:23.000000000 -0700
@@ -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
--- linux-2.6.13.4.orig/drivers/base/node.c	2005-10-19 10:26:20.000000000 -0700
+++ linux-2.6.13.4.new/drivers/base/node.c	2005-10-19 10:32:25.000000000 -0700
@@ -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
--- linux-2.6.13.4.orig/drivers/base/sys.c	2005-10-19 10:26:20.000000000 -0700
+++ linux-2.6.13.4.new/drivers/base/sys.c	2005-10-19 10:35:33.000000000 -0700
@@ -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 *);
 

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

* Re: [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4
  2005-10-20 21:59 ` Dmitry Torokhov
@ 2005-10-20 22:03   ` Jonathan Mayer
  2005-10-20 23:03     ` Dmitry Torokhov
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Mayer @ 2005-10-20 22:03 UTC (permalink / raw)
  To: dtor_core; +Cc: Patrick Mochel, linux-kernel

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.

On 10/20/05, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> On 10/20/05, Jonathan Mayer <jonmayer@google.com> wrote:
>
> >  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
>

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

* Re: [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4
  2005-10-20 22:03   ` Jonathan Mayer
@ 2005-10-20 23:03     ` Dmitry Torokhov
  2005-10-20 23:07       ` Jonathan Mayer
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry Torokhov @ 2005-10-20 23:03 UTC (permalink / raw)
  To: Jonathan Mayer; +Cc: Patrick Mochel, linux-kernel

On 10/20/05, Jonathan Mayer <jonmayer@google.com> wrote:
> 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

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

* Re: [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4
  2005-10-20 23:03     ` Dmitry Torokhov
@ 2005-10-20 23:07       ` Jonathan Mayer
  2005-10-21  0:26         ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Mayer @ 2005-10-20 23:07 UTC (permalink / raw)
  To: dtor_core; +Cc: linux-kernel, Patrick Mochel

> 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.

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

* Re: [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4
  2005-10-20 23:07       ` Jonathan Mayer
@ 2005-10-21  0:26         ` Greg KH
  2005-10-21  0:42           ` Jonathan Mayer
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2005-10-21  0:26 UTC (permalink / raw)
  To: Jonathan Mayer; +Cc: dtor_core, linux-kernel, Patrick Mochel

On Thu, Oct 20, 2005 at 04:07:59PM -0700, Jonathan Mayer wrote:
> > 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

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

* Re: [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4
  2005-10-21  0:26         ` Greg KH
@ 2005-10-21  0:42           ` Jonathan Mayer
  2005-10-21  4:07             ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Mayer @ 2005-10-21  0:42 UTC (permalink / raw)
  To: Greg KH; +Cc: dtor_core, linux-kernel, Patrick Mochel

> 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.

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

* Re: [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4
  2005-10-21  0:42           ` Jonathan Mayer
@ 2005-10-21  4:07             ` Greg KH
  0 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2005-10-21  4:07 UTC (permalink / raw)
  To: Jonathan Mayer; +Cc: dtor_core, linux-kernel, Patrick Mochel

On Thu, Oct 20, 2005 at 05:42:50PM -0700, Jonathan Mayer wrote:
> > 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.

> 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.

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

That would be fine.

thanks,

greg k-h

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

end of thread, other threads:[~2005-10-21  4:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-20 21:47 [PATCH] added sysdev attribute to sysdev show/store methods - for linux-2.6.13.4 Jonathan Mayer
2005-10-20 21:59 ` Dmitry Torokhov
2005-10-20 22:03   ` Jonathan Mayer
2005-10-20 23:03     ` Dmitry Torokhov
2005-10-20 23:07       ` Jonathan Mayer
2005-10-21  0:26         ` Greg KH
2005-10-21  0:42           ` Jonathan Mayer
2005-10-21  4:07             ` Greg KH
2005-10-20 22:00 ` Jonathan Mayer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.