iio: core: move channel list & group to private iio device object

This change bit straightforward and simple, since the
'channel_attr_list' & 'chan_attr_group' fields are only used in
'industrialio-core.c'.

This change moves to the private IIO device object

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Alexandru Ardelean 2020-06-30 07:57:06 +03:00 committed by Jonathan Cameron
parent 96fb1b6742
commit 207c2d27a0
3 changed files with 31 additions and 25 deletions

View File

@ -1137,6 +1137,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
enum iio_shared_by shared_by, enum iio_shared_by shared_by,
const long *infomask) const long *infomask)
{ {
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
int i, ret, attrcount = 0; int i, ret, attrcount = 0;
for_each_set_bit(i, infomask, sizeof(*infomask)*8) { for_each_set_bit(i, infomask, sizeof(*infomask)*8) {
@ -1149,7 +1150,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
i, i,
shared_by, shared_by,
&indio_dev->dev, &indio_dev->dev,
&indio_dev->channel_attr_list); &iio_dev_opaque->channel_attr_list);
if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE)) if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
continue; continue;
else if (ret < 0) else if (ret < 0)
@ -1165,6 +1166,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
enum iio_shared_by shared_by, enum iio_shared_by shared_by,
const long *infomask) const long *infomask)
{ {
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
int i, ret, attrcount = 0; int i, ret, attrcount = 0;
char *avail_postfix; char *avail_postfix;
@ -1184,7 +1186,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
i, i,
shared_by, shared_by,
&indio_dev->dev, &indio_dev->dev,
&indio_dev->channel_attr_list); &iio_dev_opaque->channel_attr_list);
kfree(avail_postfix); kfree(avail_postfix);
if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE)) if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
continue; continue;
@ -1199,6 +1201,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev, static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan) struct iio_chan_spec const *chan)
{ {
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
int ret, attrcount = 0; int ret, attrcount = 0;
const struct iio_chan_spec_ext_info *ext_info; const struct iio_chan_spec_ext_info *ext_info;
@ -1274,7 +1277,7 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
i, i,
ext_info->shared, ext_info->shared,
&indio_dev->dev, &indio_dev->dev,
&indio_dev->channel_attr_list); &iio_dev_opaque->channel_attr_list);
i++; i++;
if (ret == -EBUSY && ext_info->shared) if (ret == -EBUSY && ext_info->shared)
continue; continue;
@ -1409,6 +1412,7 @@ static DEVICE_ATTR(current_timestamp_clock, S_IRUGO | S_IWUSR,
static int iio_device_register_sysfs(struct iio_dev *indio_dev) static int iio_device_register_sysfs(struct iio_dev *indio_dev)
{ {
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
int i, ret = 0, attrcount, attrn, attrcount_orig = 0; int i, ret = 0, attrcount, attrn, attrcount_orig = 0;
struct iio_dev_attr *p; struct iio_dev_attr *p;
struct attribute **attr, *clk = NULL; struct attribute **attr, *clk = NULL;
@ -1448,47 +1452,49 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
if (clk) if (clk)
attrcount++; attrcount++;
indio_dev->chan_attr_group.attrs = kcalloc(attrcount + 1, iio_dev_opaque->chan_attr_group.attrs =
sizeof(indio_dev->chan_attr_group.attrs[0]), kcalloc(attrcount + 1,
GFP_KERNEL); sizeof(iio_dev_opaque->chan_attr_group.attrs[0]),
if (indio_dev->chan_attr_group.attrs == NULL) { GFP_KERNEL);
if (iio_dev_opaque->chan_attr_group.attrs == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_clear_attrs; goto error_clear_attrs;
} }
/* Copy across original attributes */ /* Copy across original attributes */
if (indio_dev->info->attrs) if (indio_dev->info->attrs)
memcpy(indio_dev->chan_attr_group.attrs, memcpy(iio_dev_opaque->chan_attr_group.attrs,
indio_dev->info->attrs->attrs, indio_dev->info->attrs->attrs,
sizeof(indio_dev->chan_attr_group.attrs[0]) sizeof(iio_dev_opaque->chan_attr_group.attrs[0])
*attrcount_orig); *attrcount_orig);
attrn = attrcount_orig; attrn = attrcount_orig;
/* Add all elements from the list. */ /* Add all elements from the list. */
list_for_each_entry(p, &indio_dev->channel_attr_list, l) list_for_each_entry(p, &iio_dev_opaque->channel_attr_list, l)
indio_dev->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr; iio_dev_opaque->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr;
if (indio_dev->name) if (indio_dev->name)
indio_dev->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr; iio_dev_opaque->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr;
if (indio_dev->label) if (indio_dev->label)
indio_dev->chan_attr_group.attrs[attrn++] = &dev_attr_label.attr; iio_dev_opaque->chan_attr_group.attrs[attrn++] = &dev_attr_label.attr;
if (clk) if (clk)
indio_dev->chan_attr_group.attrs[attrn++] = clk; iio_dev_opaque->chan_attr_group.attrs[attrn++] = clk;
indio_dev->groups[indio_dev->groupcounter++] = indio_dev->groups[indio_dev->groupcounter++] =
&indio_dev->chan_attr_group; &iio_dev_opaque->chan_attr_group;
return 0; return 0;
error_clear_attrs: error_clear_attrs:
iio_free_chan_devattr_list(&indio_dev->channel_attr_list); iio_free_chan_devattr_list(&iio_dev_opaque->channel_attr_list);
return ret; return ret;
} }
static void iio_device_unregister_sysfs(struct iio_dev *indio_dev) static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
{ {
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
iio_free_chan_devattr_list(&indio_dev->channel_attr_list); iio_free_chan_devattr_list(&iio_dev_opaque->channel_attr_list);
kfree(indio_dev->chan_attr_group.attrs); kfree(iio_dev_opaque->chan_attr_group.attrs);
indio_dev->chan_attr_group.attrs = NULL; iio_dev_opaque->chan_attr_group.attrs = NULL;
} }
static void iio_dev_release(struct device *device) static void iio_dev_release(struct device *device)
@ -1543,7 +1549,7 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
dev_set_drvdata(&dev->dev, (void *)dev); dev_set_drvdata(&dev->dev, (void *)dev);
mutex_init(&dev->mlock); mutex_init(&dev->mlock);
mutex_init(&dev->info_exist_lock); mutex_init(&dev->info_exist_lock);
INIT_LIST_HEAD(&dev->channel_attr_list); INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL); dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
if (dev->id < 0) { if (dev->id < 0) {

View File

@ -6,6 +6,9 @@
/** /**
* struct iio_dev_opaque - industrial I/O device opaque information * struct iio_dev_opaque - industrial I/O device opaque information
* @indio_dev: public industrial I/O device information * @indio_dev: public industrial I/O device information
* @channel_attr_list: keep track of automatically created channel
* attributes
* @chan_attr_group: group for all attrs in base directory
* @debugfs_dentry: device specific debugfs dentry * @debugfs_dentry: device specific debugfs dentry
* @cached_reg_addr: cached register address for debugfs reads * @cached_reg_addr: cached register address for debugfs reads
* @read_buf: read buffer to be used for the initial reg read * @read_buf: read buffer to be used for the initial reg read
@ -13,6 +16,8 @@
*/ */
struct iio_dev_opaque { struct iio_dev_opaque {
struct iio_dev indio_dev; struct iio_dev indio_dev;
struct list_head channel_attr_list;
struct attribute_group chan_attr_group;
#if defined(CONFIG_DEBUG_FS) #if defined(CONFIG_DEBUG_FS)
struct dentry *debugfs_dentry; struct dentry *debugfs_dentry;
unsigned cached_reg_addr; unsigned cached_reg_addr;

View File

@ -506,9 +506,6 @@ struct iio_buffer_setup_ops {
* @pollfunc_event: [DRIVER] function run on events trigger being received * @pollfunc_event: [DRIVER] function run on events trigger being received
* @channels: [DRIVER] channel specification structure table * @channels: [DRIVER] channel specification structure table
* @num_channels: [DRIVER] number of channels specified in @channels. * @num_channels: [DRIVER] number of channels specified in @channels.
* @channel_attr_list: [INTERN] keep track of automatically created channel
* attributes
* @chan_attr_group: [INTERN] group for all attrs in base directory
* @name: [DRIVER] name of the device. * @name: [DRIVER] name of the device.
* @label: [DRIVER] unique name to identify which device this is * @label: [DRIVER] unique name to identify which device this is
* @info: [DRIVER] callbacks and constant info from driver * @info: [DRIVER] callbacks and constant info from driver
@ -551,8 +548,6 @@ struct iio_dev {
struct iio_chan_spec const *channels; struct iio_chan_spec const *channels;
int num_channels; int num_channels;
struct list_head channel_attr_list;
struct attribute_group chan_attr_group;
const char *name; const char *name;
const char *label; const char *label;
const struct iio_info *info; const struct iio_info *info;