From: Jonathan Cameron <jic23@cam.ac.uk>
To: Jonathan Cameron <jic23@cam.ac.uk>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH 53/70] staging:iio: Add core attribute handling for name of device.
Date: Mon, 18 Apr 2011 13:17:23 +0100 [thread overview]
Message-ID: <4DAC2BD3.3030209@cam.ac.uk> (raw)
In-Reply-To: <4DAB4835.4020606@cam.ac.uk>
On 04/17/11 21:06, Jonathan Cameron wrote:
> On 04/17/11 20:06, Jonathan Cameron wrote:
>> Saves on a fair bit of code replication.
> I clearly didn't think this through properly. It can be done much
> more neatly with a single static iio_dev_attr and just explicitly
> adding and removing it. See the trigger equivalent in the
> iio-onwards tree that I have just pushed.
>
The following is how I 'should' have done it.
Subject: [PATCH] staging:iio: Add core attribute handling for name of device.
Saves on a fair bit of code replication.
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
drivers/staging/iio/iio.h | 2 +-
drivers/staging/iio/industrialio-core.c | 23 ++++++++++++++++++++++-
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/iio/iio.h b/drivers/staging/iio/iio.h
index b818f5f..febf20e 100644
--- a/drivers/staging/iio/iio.h
+++ b/drivers/staging/iio/iio.h
@@ -231,7 +231,7 @@ struct iio_dev {
int num_channels;
struct list_head channel_attr_list;
- char *name; /*device name - IMPLEMENT */
+ const char *name;
int (*read_raw)(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c
index 2e2e51d..8ee8f40 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/staging/iio/industrialio-core.c
@@ -611,6 +611,16 @@ static void iio_device_remove_and_free_read_attr(struct iio_dev *dev_info,
kfree(p);
}
+static ssize_t iio_show_dev_name(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ return sprintf(buf, "%s\n", indio_dev->name);
+}
+
+static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL);
+
static int iio_device_register_sysfs(struct iio_dev *dev_info)
{
int i, ret = 0;
@@ -638,8 +648,15 @@ static int iio_device_register_sysfs(struct iio_dev *dev_info)
if (ret < 0)
goto error_clear_attrs;
}
-
+ if (dev_info->name) {
+ ret = sysfs_add_file_to_group(&dev_info->dev.kobj,
+ &dev_attr_name.attr,
+ NULL);
+ if (ret)
+ goto error_clear_attrs;
+ }
return 0;
+
error_clear_attrs:
list_for_each_entry_safe(p, n,
&dev_info->channel_attr_list, l) {
@@ -657,6 +674,10 @@ static void iio_device_unregister_sysfs(struct iio_dev *dev_info)
{
struct iio_dev_attr *p, *n;
+ if (dev_info->name)
+ sysfs_remove_file_from_group(&dev_info->dev.kobj,
+ &dev_attr_name.attr,
+ NULL);
list_for_each_entry_safe(p, n, &dev_info->channel_attr_list, l) {
list_del(&p->l);
iio_device_remove_and_free_read_attr(dev_info, p);
--
1.7.3.4
next prev parent reply other threads:[~2011-04-18 12:17 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-17 19:05 [PATCH 00/70] IIO: Major rework set (review request) Jonathan Cameron
2011-04-17 19:05 ` [PATCH 01/70] staging:iio: allow channels to be set up using a table of iio_channel_spec structures Jonathan Cameron
2011-04-17 19:05 ` [PATCH 02/70] staging:iio:lis3l02dq - move to new channel_spec approach Jonathan Cameron
2011-04-17 19:05 ` [PATCH 03/70] staging:iio:max1363 - move to channel_spec registration Jonathan Cameron
2011-04-17 19:05 ` [PATCH 04/70] staging:iio: remove ability to escalate events Jonathan Cameron
2011-04-17 19:05 ` [PATCH 05/70] staging:iio: Add polling of events on the ring access chrdev Jonathan Cameron
2011-04-17 19:05 ` [PATCH 06/70] staging:iio: remove legacy event chrdev for the buffers Jonathan Cameron
2011-04-17 19:05 ` [PATCH 07/70] staging:iio: Buffer device flattening Jonathan Cameron
2011-04-17 19:05 ` [PATCH 08/70] staging:iio:lis3l02dq: General cleanup Jonathan Cameron
2011-04-17 19:05 ` [PATCH 09/70] staging:iio: Push interrupt setup down into the drivers for event lines Jonathan Cameron
2011-04-17 19:05 ` [PATCH 10/70] staging:iio: lis3l02dq - separate entirely interrupt handling for thesholds from that for the datardy signal Jonathan Cameron
2011-04-17 19:05 ` [PATCH 11/70] staging:iio:sca3000 extract old event handling and move to poll for events from buffer Jonathan Cameron
2011-04-17 19:05 ` [PATCH 12/70] staging:iio:buffering remove unused parameter dead_offset from read_last_n in all buffer implementations Jonathan Cameron
2011-04-17 19:05 ` [PATCH 13/70] staging:iio:light:tsl2563 remove old style event registration Jonathan Cameron
2011-04-17 19:05 ` [PATCH 14/70] staging:iio:dac:ad5504 move from old to new event handling Jonathan Cameron
2011-04-17 19:05 ` [PATCH 15/70] staging:iio:adt7316 get rid of legacy event handling code Jonathan Cameron
2011-04-17 19:05 ` [PATCH 16/70] staging:iio:adc:ad7745 move from old to current event handling Jonathan Cameron
2011-04-17 19:05 ` [PATCH 17/70] staging:iio:adc:ad7816 " Jonathan Cameron
2011-04-17 19:05 ` [PATCH 18/70] staging:iio:adc:ad7150 move from deprecated " Jonathan Cameron
2011-04-17 19:05 ` [PATCH 19/70] staging:iio:adc:ad7152 remove unregister of interrupt line Jonathan Cameron
2011-04-17 19:05 ` [PATCH 20/70] staging:iio:adc:adt75 old to new event handling conversion Jonathan Cameron
2011-04-17 19:05 ` [PATCH 21/70] staging:iio:ad7291 move from old event system to current Jonathan Cameron
2011-04-17 19:05 ` [PATCH 22/70] staging:iio:adc:adt7410 move to current event handling Jonathan Cameron
2011-04-17 19:05 ` [PATCH 23/70] staging:iio:adt7310 " Jonathan Cameron
2011-04-17 19:05 ` [PATCH 24/70] staging:iio:adc:ad7314 remove unmatched unregister of event line Jonathan Cameron
2011-04-17 19:05 ` [PATCH 25/70] staging:iio:ad799x move to new event handling Jonathan Cameron
2011-04-17 19:05 ` [PATCH 26/70] staging:iio: Remove legacy " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 27/70] staging:iio:lis3l02dq make threshold interrupt threaded Jonathan Cameron
2011-04-17 19:06 ` [PATCH 28/70] staging:iio: Add infrastructure for irq_chip based triggers Jonathan Cameron
2011-04-21 16:51 ` Jonathan Cameron
2011-04-26 15:10 ` Jonathan Cameron
2011-04-17 19:06 ` [PATCH 29/70] staging:iio:Documentation generic_buffer.c update to new abi for buffers + misc fixes Jonathan Cameron
2011-04-17 19:06 ` [PATCH 30/70] staging:iio:ring_sw add function needed for threaded irq Jonathan Cameron
2011-04-17 19:06 ` [PATCH 31/70] staging:iio: add generic data ready poll function Jonathan Cameron
2011-04-17 19:06 ` [PATCH 32/70] staging:iio:lis3l02dq move to threaded trigger handling Jonathan Cameron
2011-04-17 19:06 ` [PATCH 33/70] staging:iio:max1363 move to irqchip based threaded irq triggering Jonathan Cameron
2011-04-17 19:06 ` [PATCH 34/70] staging:iio:ad7476 use channel_spec Jonathan Cameron
2011-04-17 19:06 ` [PATCH 35/70] staging:iio:ad7476 move to irqchip based triggering Jonathan Cameron
2011-04-17 19:06 ` [PATCH 36/70] staging:iio:meter:ade7758 move to irqchip based trigger handling Jonathan Cameron
2011-04-17 19:06 ` [PATCH 37/70] staging:iio:adis16400 move to irq based triggers and channel spec channel registration Jonathan Cameron
2011-04-17 19:06 ` [PATCH 38/70] staging:iio:imu:adis16350 etc support into adis16400 driver Jonathan Cameron
2011-04-17 19:06 ` [PATCH 39/70] staging:iio:imu remove old adis16350. Support now in " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 40/70] staging:iio:imu:adis16400 add support for adis16300 Jonathan Cameron
2011-04-17 19:06 ` [PATCH 41/70] staging:iio:imu remove adis16300 driver Jonathan Cameron
2011-04-17 19:06 ` [PATCH 42/70] staging:iio:accel:adis16201 move to irqchip based trigger handling Jonathan Cameron
2011-04-17 19:06 ` [PATCH 43/70] staging:iio:accel:adis16203 " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 44/70] staging:iio:accel:adis16204 " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 45/70] staging:iio:accel:adis16209 " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 46/70] staging:iio:accel:adis16240 " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 47/70] staging:iio:adc:ad7298 " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 48/70] staging:iio:ad7606 conversion to irq_chip based polling Jonathan Cameron
2011-04-18 7:52 ` Hennerich, Michael
2011-04-18 9:57 ` Jonathan Cameron
2011-04-17 19:06 ` [PATCH 49/70] staging:iio:adc:ad7887 move to irqchip based trigger handling Jonathan Cameron
2011-04-17 19:06 ` [PATCH 50/70] staging:iio:adc:ad799x " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 51/70] staging:iio:gyro:adis16260 " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 52/70] staging:iio:trigger remove legacy pollfunc elements Jonathan Cameron
2011-04-17 19:06 ` [PATCH 53/70] staging:iio: Add core attribute handling for name of device Jonathan Cameron
2011-04-17 20:06 ` Jonathan Cameron
2011-04-18 12:17 ` Jonathan Cameron [this message]
2011-04-17 19:06 ` [PATCH 54/70] staging:iio: use the new central name attribute creation code Jonathan Cameron
2011-04-17 19:06 ` [PATCH 55/70] staging:iio:accel:adis16201 move to chan_spec based setup Jonathan Cameron
2011-04-17 19:06 ` [PATCH 56/70] staging:iio:accel:adis16203 " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 57/70] staging:iio:accel:adis16204 " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 58/70] staging:iio:accel:adis16209 " Jonathan Cameron
2011-04-17 19:06 ` [PATCH 59/70] staging:iio:accel: lis3l02dq add writing for calibscale and calibbias Jonathan Cameron
2011-04-17 19:06 ` [PATCH 60/70] staging:iio: Add chan info support for 'peak_raw' attributes Jonathan Cameron
2011-04-17 19:06 ` [PATCH 61/70] staging:iio:accel:adis16240 move to chan_spec based setup Jonathan Cameron
2011-04-17 19:06 ` [PATCH 62/70] staging:iio: Add angl parameters to the chan spec code Jonathan Cameron
2011-04-17 19:06 ` [PATCH 63/70] staging:iio:gyro:adis16260 move to chan_spec based setup Jonathan Cameron
2011-04-17 19:06 ` [PATCH 64/70] staging:iio: rip out scan_el attributes. Now handled as iio_dev_attrs like everything else Jonathan Cameron
2011-04-17 19:06 ` [PATCH 65/70] staging:iio:max1363 trivial removal of unused trig pointer Jonathan Cameron
2011-04-17 19:06 ` [PATCH 66/70] staging:iio:max1363 add new 2 channels parts form maxim, 11644-7 Jonathan Cameron
2011-04-17 19:06 ` [PATCH 67/70] staging:iio:trigger sysfs userspace trigger rework Jonathan Cameron
2011-04-17 19:06 ` [PATCH 68/70] staging:iio:core clean out unused elements Jonathan Cameron
2011-04-17 19:06 ` [PATCH 69/70] staging:iio:buffer - remove unused event code for buffer events Jonathan Cameron
2011-04-17 19:06 ` [PATCH 70/70] staging:iio:lis3l02dq remerge the two interrupt handlers Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DAC2BD3.3030209@cam.ac.uk \
--to=jic23@cam.ac.uk \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.