Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: add support for binary attributes

When a IIO device is registered, the IIO core creates an attribute group on
its own, where it puts the channel attributes, and where it copies the
attributes in indio_dev->info->attrs.

Unfortunately it doesn't take care of binary attributes (i.e. it only
consider indio_dev->info->attrs->attrs, and it ignores
indio_dev->info->attrs->bin_attrs).

Fix this by making the IIO layer take care also of the binary attributes.

Note that while it is necessary to copy the non-binary attributes because
the IIO layer needs more room to add the channels attribute, it should be
enough to assign the bin_attrs pointer to the binary attributes pointed by
indio_dev->info->attrs->bin_attrs.

Signed-off-by: Andrea Merello <andrea.merello@iit.it>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220907132205.28021-8-andrea.merello@iit.it
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Andrea Merello and committed by
Jonathan Cameron
e0d27ea3 ab9d343d

+3 -1
+3 -1
drivers/iio/industrialio-core.c
··· 1576 1576 ret = -ENOMEM; 1577 1577 goto error_clear_attrs; 1578 1578 } 1579 - /* Copy across original attributes */ 1579 + /* Copy across original attributes, and point to original binary attributes */ 1580 1580 if (indio_dev->info->attrs) { 1581 1581 memcpy(iio_dev_opaque->chan_attr_group.attrs, 1582 1582 indio_dev->info->attrs->attrs, ··· 1584 1584 *attrcount_orig); 1585 1585 iio_dev_opaque->chan_attr_group.is_visible = 1586 1586 indio_dev->info->attrs->is_visible; 1587 + iio_dev_opaque->chan_attr_group.bin_attrs = 1588 + indio_dev->info->attrs->bin_attrs; 1587 1589 } 1588 1590 attrn = attrcount_orig; 1589 1591 /* Add all elements from the list. */