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

iio: Add iio_read_channel_label to inkern API

It can be convenient for other in-kernel drivers to reuse IIO channel
labels. Export the iio_read_channel_label function to allow this. The
signature is different depending on where we are calling it from, so
the meat is moved to do_iio_read_channel_label.

Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://patch.msgid.link/20240624174601.1527244-2-sean.anderson@linux.dev
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Sean Anderson and committed by
Jonathan Cameron
0214b27f 96419729

+35 -10
+4
drivers/iio/iio_core.h
··· 34 34 struct iio_ioctl_handler *h); 35 35 void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h); 36 36 37 + ssize_t do_iio_read_channel_label(struct iio_dev *indio_dev, 38 + const struct iio_chan_spec *c, 39 + char *buf); 40 + 37 41 int __iio_add_chan_devattr(const char *postfix, 38 42 struct iio_chan_spec const *chan, 39 43 ssize_t (*func)(struct device *dev,
+15 -10
drivers/iio/industrialio-core.c
··· 727 727 } 728 728 EXPORT_SYMBOL_GPL(iio_format_value); 729 729 730 + ssize_t do_iio_read_channel_label(struct iio_dev *indio_dev, 731 + const struct iio_chan_spec *c, 732 + char *buf) 733 + { 734 + if (indio_dev->info->read_label) 735 + return indio_dev->info->read_label(indio_dev, c, buf); 736 + 737 + if (c->extend_name) 738 + return sysfs_emit(buf, "%s\n", c->extend_name); 739 + 740 + return -EINVAL; 741 + } 742 + 730 743 static ssize_t iio_read_channel_label(struct device *dev, 731 744 struct device_attribute *attr, 732 745 char *buf) 733 746 { 734 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 735 - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 736 - 737 - if (indio_dev->info->read_label) 738 - return indio_dev->info->read_label(indio_dev, this_attr->c, buf); 739 - 740 - if (this_attr->c->extend_name) 741 - return sysfs_emit(buf, "%s\n", this_attr->c->extend_name); 742 - 743 - return -EINVAL; 747 + return do_iio_read_channel_label(dev_to_iio_dev(dev), 748 + to_iio_dev_attr(attr)->c, buf); 744 749 } 745 750 746 751 static ssize_t iio_read_channel_info(struct device *dev,
+6
drivers/iio/inkern.c
··· 1010 1010 chan->channel, buf, len); 1011 1011 } 1012 1012 EXPORT_SYMBOL_GPL(iio_write_channel_ext_info); 1013 + 1014 + ssize_t iio_read_channel_label(struct iio_channel *chan, char *buf) 1015 + { 1016 + return do_iio_read_channel_label(chan->indio_dev, chan->channel, buf); 1017 + } 1018 + EXPORT_SYMBOL_GPL(iio_read_channel_label);
+10
include/linux/iio/consumer.h
··· 441 441 ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr, 442 442 const char *buf, size_t len); 443 443 444 + /** 445 + * iio_read_channel_label() - read label for a given channel 446 + * @chan: The channel being queried. 447 + * @buf: Where to store the attribute value. Assumed to hold 448 + * at least PAGE_SIZE bytes. 449 + * 450 + * Returns the number of bytes written to buf, or an error code. 451 + */ 452 + ssize_t iio_read_channel_label(struct iio_channel *chan, char *buf); 453 + 444 454 #endif