public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Add a private_data pointer to struct device_attribute
@ 2007-11-17  0:11 Timur Tabi
  2007-11-17  1:06 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Timur Tabi @ 2007-11-17  0:11 UTC (permalink / raw)
  To: linux-kernel, gregkh; +Cc: Timur Tabi

A private data pointer in struct device_attribute allows the 'show' and 'store'
functions to access instance data.  This handy in situations where the
driver_data and platform_data pointers of 'struct device' are already used
for other purposes.

Signed-off-by: Timur Tabi <timur@freescale.com>
---

Greg, can you tell me if you think this patch is a good idea?  It doesn't
appear to do any harm, and I'm working on an ALSA driver that could benefit
for this patch.  I think 2.6.25 would be a good target.

 include/linux/device.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/linux/device.h b/include/linux/device.h
index 2e15822..10708ee 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -344,6 +344,7 @@ struct device_attribute {
 			char *buf);
 	ssize_t (*store)(struct device *dev, struct device_attribute *attr,
 			 const char *buf, size_t count);
+	void *private_data;
 };
 
 #define DEVICE_ATTR(_name,_mode,_show,_store) \
-- 
1.5.2.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* Re: Add a private_data pointer to struct device_attribute
@ 2007-11-17  1:15 Mikael Pettersson
  2007-11-17 14:02 ` Timur Tabi
  0 siblings, 1 reply; 4+ messages in thread
From: Mikael Pettersson @ 2007-11-17  1:15 UTC (permalink / raw)
  To: gregkh, linux-kernel, timur

On Fri, 16 Nov 2007 18:11:00 -0600, Timur Tabi wrote:
> A private data pointer in struct device_attribute allows the 'show' and 'store'
> functions to access instance data.  This handy in situations where the
> driver_data and platform_data pointers of 'struct device' are already used
> for other purposes.
> 
> Signed-off-by: Timur Tabi <timur@freescale.com>
> ---
> 
> Greg, can you tell me if you think this patch is a good idea?  It doesn't
> appear to do any harm, and I'm working on an ALSA driver that could benefit
> for this patch.  I think 2.6.25 would be a good target.
> 
>  include/linux/device.h |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 2e15822..10708ee 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -344,6 +344,7 @@ struct device_attribute {
>  			char *buf);
>  	ssize_t (*store)(struct device *dev, struct device_attribute *attr,
>  			 const char *buf, size_t count);
> +	void *private_data;
>  };

A common trick is to embed a generic struct inside a specific one
containing add-on data fields, and then to map from the generic
one to the specific one using container_of() in your ops (function
pointers). This is both faster and less wasteful of memory than
adding void *private all over the place.

Any reason that won't work here?

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

end of thread, other threads:[~2007-11-17 14:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-17  0:11 Add a private_data pointer to struct device_attribute Timur Tabi
2007-11-17  1:06 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2007-11-17  1:15 Mikael Pettersson
2007-11-17 14:02 ` Timur Tabi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox