1 /* The industrial I/O core
3 * Copyright (c) 2008 Jonathan Cameron
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * Handling of buffer allocation / resizing.
12 * Things to look at here.
13 * - Better memory allocation techniques?
14 * - Alternative access techniques?
16 #include <linux/kernel.h>
17 #include <linux/export.h>
18 #include <linux/device.h>
20 #include <linux/cdev.h>
21 #include <linux/slab.h>
22 #include <linux/poll.h>
24 #include <linux/iio/iio.h>
26 #include <linux/iio/sysfs.h>
27 #include <linux/iio/buffer.h>
29 static const char * const iio_endian_prefix[] = {
34 static bool iio_buffer_is_active(struct iio_dev *indio_dev,
35 struct iio_buffer *buf)
39 list_for_each(p, &indio_dev->buffer_list)
40 if (p == &buf->buffer_list)
47 * iio_buffer_read_first_n_outer() - chrdev read for buffer access
49 * This function relies on all buffer implementations having an
50 * iio_buffer as their first element.
52 ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
53 size_t n, loff_t *f_ps)
55 struct iio_dev *indio_dev = filp->private_data;
56 struct iio_buffer *rb = indio_dev->buffer;
58 if (!rb || !rb->access->read_first_n)
60 return rb->access->read_first_n(rb, n, buf);
64 * iio_buffer_poll() - poll the buffer to find out if it has data
66 unsigned int iio_buffer_poll(struct file *filp,
67 struct poll_table_struct *wait)
69 struct iio_dev *indio_dev = filp->private_data;
70 struct iio_buffer *rb = indio_dev->buffer;
72 poll_wait(filp, &rb->pollq, wait);
74 return POLLIN | POLLRDNORM;
75 /* need a way of knowing if there may be enough data... */
79 void iio_buffer_init(struct iio_buffer *buffer)
81 INIT_LIST_HEAD(&buffer->demux_list);
82 init_waitqueue_head(&buffer->pollq);
84 EXPORT_SYMBOL(iio_buffer_init);
86 static ssize_t iio_show_scan_index(struct device *dev,
87 struct device_attribute *attr,
90 return sprintf(buf, "%u\n", to_iio_dev_attr(attr)->c->scan_index);
93 static ssize_t iio_show_fixed_type(struct device *dev,
94 struct device_attribute *attr,
97 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
98 u8 type = this_attr->c->scan_type.endianness;
100 if (type == IIO_CPU) {
101 #ifdef __LITTLE_ENDIAN
107 return sprintf(buf, "%s:%c%d/%d>>%u\n",
108 iio_endian_prefix[type],
109 this_attr->c->scan_type.sign,
110 this_attr->c->scan_type.realbits,
111 this_attr->c->scan_type.storagebits,
112 this_attr->c->scan_type.shift);
115 static ssize_t iio_scan_el_show(struct device *dev,
116 struct device_attribute *attr,
120 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
122 ret = test_bit(to_iio_dev_attr(attr)->address,
123 indio_dev->buffer->scan_mask);
125 return sprintf(buf, "%d\n", ret);
128 static int iio_scan_mask_clear(struct iio_buffer *buffer, int bit)
130 clear_bit(bit, buffer->scan_mask);
134 static ssize_t iio_scan_el_store(struct device *dev,
135 struct device_attribute *attr,
141 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
142 struct iio_buffer *buffer = indio_dev->buffer;
143 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
145 ret = strtobool(buf, &state);
148 mutex_lock(&indio_dev->mlock);
149 if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) {
153 ret = iio_scan_mask_query(indio_dev, buffer, this_attr->address);
157 ret = iio_scan_mask_clear(buffer, this_attr->address);
160 } else if (state && !ret) {
161 ret = iio_scan_mask_set(indio_dev, buffer, this_attr->address);
167 mutex_unlock(&indio_dev->mlock);
169 return ret < 0 ? ret : len;
173 static ssize_t iio_scan_el_ts_show(struct device *dev,
174 struct device_attribute *attr,
177 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
178 return sprintf(buf, "%d\n", indio_dev->buffer->scan_timestamp);
181 static ssize_t iio_scan_el_ts_store(struct device *dev,
182 struct device_attribute *attr,
187 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
190 ret = strtobool(buf, &state);
194 mutex_lock(&indio_dev->mlock);
195 if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) {
199 indio_dev->buffer->scan_timestamp = state;
201 mutex_unlock(&indio_dev->mlock);
203 return ret ? ret : len;
206 static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
207 const struct iio_chan_spec *chan)
209 int ret, attrcount = 0;
210 struct iio_buffer *buffer = indio_dev->buffer;
212 ret = __iio_add_chan_devattr("index",
214 &iio_show_scan_index,
219 &buffer->scan_el_dev_attr_list);
223 ret = __iio_add_chan_devattr("type",
225 &iio_show_fixed_type,
230 &buffer->scan_el_dev_attr_list);
234 if (chan->type != IIO_TIMESTAMP)
235 ret = __iio_add_chan_devattr("en",
242 &buffer->scan_el_dev_attr_list);
244 ret = __iio_add_chan_devattr("en",
246 &iio_scan_el_ts_show,
247 &iio_scan_el_ts_store,
251 &buffer->scan_el_dev_attr_list);
258 static void iio_buffer_remove_and_free_scan_dev_attr(struct iio_dev *indio_dev,
259 struct iio_dev_attr *p)
261 kfree(p->dev_attr.attr.name);
265 static void __iio_buffer_attr_cleanup(struct iio_dev *indio_dev)
267 struct iio_dev_attr *p, *n;
268 struct iio_buffer *buffer = indio_dev->buffer;
270 list_for_each_entry_safe(p, n,
271 &buffer->scan_el_dev_attr_list, l)
272 iio_buffer_remove_and_free_scan_dev_attr(indio_dev, p);
275 static const char * const iio_scan_elements_group_name = "scan_elements";
277 int iio_buffer_register(struct iio_dev *indio_dev,
278 const struct iio_chan_spec *channels,
281 struct iio_dev_attr *p;
282 struct attribute **attr;
283 struct iio_buffer *buffer = indio_dev->buffer;
284 int ret, i, attrn, attrcount, attrcount_orig = 0;
287 indio_dev->groups[indio_dev->groupcounter++] = buffer->attrs;
289 if (buffer->scan_el_attrs != NULL) {
290 attr = buffer->scan_el_attrs->attrs;
291 while (*attr++ != NULL)
294 attrcount = attrcount_orig;
295 INIT_LIST_HEAD(&buffer->scan_el_dev_attr_list);
298 for (i = 0; i < num_channels; i++) {
299 if (channels[i].scan_index < 0)
302 /* Establish necessary mask length */
303 if (channels[i].scan_index >
304 (int)indio_dev->masklength - 1)
305 indio_dev->masklength
306 = channels[i].scan_index + 1;
308 ret = iio_buffer_add_channel_sysfs(indio_dev,
311 goto error_cleanup_dynamic;
313 if (channels[i].type == IIO_TIMESTAMP)
314 indio_dev->scan_index_timestamp =
315 channels[i].scan_index;
317 if (indio_dev->masklength && buffer->scan_mask == NULL) {
318 buffer->scan_mask = kcalloc(BITS_TO_LONGS(indio_dev->masklength),
319 sizeof(*buffer->scan_mask),
321 if (buffer->scan_mask == NULL) {
323 goto error_cleanup_dynamic;
328 buffer->scan_el_group.name = iio_scan_elements_group_name;
330 buffer->scan_el_group.attrs = kcalloc(attrcount + 1,
331 sizeof(buffer->scan_el_group.attrs[0]),
333 if (buffer->scan_el_group.attrs == NULL) {
335 goto error_free_scan_mask;
337 if (buffer->scan_el_attrs)
338 memcpy(buffer->scan_el_group.attrs, buffer->scan_el_attrs,
339 sizeof(buffer->scan_el_group.attrs[0])*attrcount_orig);
340 attrn = attrcount_orig;
342 list_for_each_entry(p, &buffer->scan_el_dev_attr_list, l)
343 buffer->scan_el_group.attrs[attrn++] = &p->dev_attr.attr;
344 indio_dev->groups[indio_dev->groupcounter++] = &buffer->scan_el_group;
348 error_free_scan_mask:
349 kfree(buffer->scan_mask);
350 error_cleanup_dynamic:
351 __iio_buffer_attr_cleanup(indio_dev);
355 EXPORT_SYMBOL(iio_buffer_register);
357 void iio_buffer_unregister(struct iio_dev *indio_dev)
359 kfree(indio_dev->buffer->scan_mask);
360 kfree(indio_dev->buffer->scan_el_group.attrs);
361 __iio_buffer_attr_cleanup(indio_dev);
363 EXPORT_SYMBOL(iio_buffer_unregister);
365 ssize_t iio_buffer_read_length(struct device *dev,
366 struct device_attribute *attr,
369 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
370 struct iio_buffer *buffer = indio_dev->buffer;
372 if (buffer->access->get_length)
373 return sprintf(buf, "%d\n",
374 buffer->access->get_length(buffer));
378 EXPORT_SYMBOL(iio_buffer_read_length);
380 ssize_t iio_buffer_write_length(struct device *dev,
381 struct device_attribute *attr,
385 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
386 struct iio_buffer *buffer = indio_dev->buffer;
390 ret = kstrtouint(buf, 10, &val);
394 if (buffer->access->get_length)
395 if (val == buffer->access->get_length(buffer))
398 mutex_lock(&indio_dev->mlock);
399 if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) {
402 if (buffer->access->set_length)
403 buffer->access->set_length(buffer, val);
406 mutex_unlock(&indio_dev->mlock);
408 return ret ? ret : len;
410 EXPORT_SYMBOL(iio_buffer_write_length);
412 ssize_t iio_buffer_show_enable(struct device *dev,
413 struct device_attribute *attr,
416 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
417 return sprintf(buf, "%d\n",
418 iio_buffer_is_active(indio_dev,
421 EXPORT_SYMBOL(iio_buffer_show_enable);
423 /* note NULL used as error indicator as it doesn't make sense. */
424 static const unsigned long *iio_scan_mask_match(const unsigned long *av_masks,
425 unsigned int masklength,
426 const unsigned long *mask)
428 if (bitmap_empty(mask, masklength))
431 if (bitmap_subset(mask, av_masks, masklength))
433 av_masks += BITS_TO_LONGS(masklength);
438 static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask,
441 const struct iio_chan_spec *ch;
445 /* How much space will the demuxed element take? */
446 for_each_set_bit(i, mask,
447 indio_dev->masklength) {
448 ch = iio_find_channel_from_si(indio_dev, i);
449 length = ch->scan_type.storagebits / 8;
450 bytes = ALIGN(bytes, length);
454 ch = iio_find_channel_from_si(indio_dev,
455 indio_dev->scan_index_timestamp);
456 length = ch->scan_type.storagebits / 8;
457 bytes = ALIGN(bytes, length);
463 int iio_update_buffers(struct iio_dev *indio_dev,
464 struct iio_buffer *insert_buffer,
465 struct iio_buffer *remove_buffer)
469 struct iio_buffer *buffer;
470 unsigned long *compound_mask;
471 const unsigned long *old_mask;
473 /* Wind down existing buffers - iff there are any */
474 if (!list_empty(&indio_dev->buffer_list)) {
475 if (indio_dev->setup_ops->predisable) {
476 ret = indio_dev->setup_ops->predisable(indio_dev);
480 indio_dev->currentmode = INDIO_DIRECT_MODE;
481 if (indio_dev->setup_ops->postdisable) {
482 ret = indio_dev->setup_ops->postdisable(indio_dev);
487 /* Keep a copy of current setup to allow roll back */
488 old_mask = indio_dev->active_scan_mask;
489 if (!indio_dev->available_scan_masks)
490 indio_dev->active_scan_mask = NULL;
493 list_del(&remove_buffer->buffer_list);
495 list_add(&insert_buffer->buffer_list, &indio_dev->buffer_list);
497 /* If no buffers in list, we are done */
498 if (list_empty(&indio_dev->buffer_list)) {
499 indio_dev->currentmode = INDIO_DIRECT_MODE;
500 if (indio_dev->available_scan_masks == NULL)
505 /* What scan mask do we actually have ?*/
506 compound_mask = kcalloc(BITS_TO_LONGS(indio_dev->masklength),
507 sizeof(long), GFP_KERNEL);
508 if (compound_mask == NULL) {
509 if (indio_dev->available_scan_masks == NULL)
513 indio_dev->scan_timestamp = 0;
515 list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
516 bitmap_or(compound_mask, compound_mask, buffer->scan_mask,
517 indio_dev->masklength);
518 indio_dev->scan_timestamp |= buffer->scan_timestamp;
520 if (indio_dev->available_scan_masks) {
521 indio_dev->active_scan_mask =
522 iio_scan_mask_match(indio_dev->available_scan_masks,
523 indio_dev->masklength,
525 if (indio_dev->active_scan_mask == NULL) {
528 * Note can only occur when adding a buffer.
530 list_del(&insert_buffer->buffer_list);
531 indio_dev->active_scan_mask = old_mask;
535 indio_dev->active_scan_mask = compound_mask;
538 iio_update_demux(indio_dev);
541 if (indio_dev->setup_ops->preenable) {
542 ret = indio_dev->setup_ops->preenable(indio_dev);
545 "Buffer not started: buffer preenable failed (%d)\n", ret);
546 goto error_remove_inserted;
549 indio_dev->scan_bytes =
550 iio_compute_scan_bytes(indio_dev,
551 indio_dev->active_scan_mask,
552 indio_dev->scan_timestamp);
553 list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list)
554 if (buffer->access->request_update) {
555 ret = buffer->access->request_update(buffer);
558 "Buffer not started: buffer parameter update failed (%d)\n", ret);
559 goto error_run_postdisable;
562 if (indio_dev->info->update_scan_mode) {
563 ret = indio_dev->info
564 ->update_scan_mode(indio_dev,
565 indio_dev->active_scan_mask);
567 printk(KERN_INFO "Buffer not started: update scan mode failed (%d)\n", ret);
568 goto error_run_postdisable;
571 /* Definitely possible for devices to support both of these.*/
572 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) {
573 if (!indio_dev->trig) {
574 printk(KERN_INFO "Buffer not started: no trigger\n");
576 /* Can only occur on first buffer */
577 goto error_run_postdisable;
579 indio_dev->currentmode = INDIO_BUFFER_TRIGGERED;
580 } else if (indio_dev->modes & INDIO_BUFFER_HARDWARE) {
581 indio_dev->currentmode = INDIO_BUFFER_HARDWARE;
582 } else { /* should never be reached */
584 goto error_run_postdisable;
587 if (indio_dev->setup_ops->postenable) {
588 ret = indio_dev->setup_ops->postenable(indio_dev);
591 "Buffer not started: postenable failed (%d)\n", ret);
592 indio_dev->currentmode = INDIO_DIRECT_MODE;
593 if (indio_dev->setup_ops->postdisable)
594 indio_dev->setup_ops->postdisable(indio_dev);
595 goto error_disable_all_buffers;
599 if (indio_dev->available_scan_masks)
600 kfree(compound_mask);
606 error_disable_all_buffers:
607 indio_dev->currentmode = INDIO_DIRECT_MODE;
608 error_run_postdisable:
609 if (indio_dev->setup_ops->postdisable)
610 indio_dev->setup_ops->postdisable(indio_dev);
611 error_remove_inserted:
614 list_del(&insert_buffer->buffer_list);
615 indio_dev->active_scan_mask = old_mask;
616 kfree(compound_mask);
621 EXPORT_SYMBOL_GPL(iio_update_buffers);
623 ssize_t iio_buffer_store_enable(struct device *dev,
624 struct device_attribute *attr,
629 bool requested_state;
630 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
631 struct iio_buffer *pbuf = indio_dev->buffer;
634 ret = strtobool(buf, &requested_state);
638 mutex_lock(&indio_dev->mlock);
640 /* Find out if it is in the list */
641 inlist = iio_buffer_is_active(indio_dev, pbuf);
642 /* Already in desired state */
643 if (inlist == requested_state)
647 ret = iio_update_buffers(indio_dev,
648 indio_dev->buffer, NULL);
650 ret = iio_update_buffers(indio_dev,
651 NULL, indio_dev->buffer);
656 mutex_unlock(&indio_dev->mlock);
657 return (ret < 0) ? ret : len;
659 EXPORT_SYMBOL(iio_buffer_store_enable);
661 int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
663 struct iio_buffer *buffer;
665 dev_dbg(&indio_dev->dev, "%s\n", __func__);
667 list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list)
668 if (buffer->access->set_bytes_per_datum) {
669 bytes = iio_compute_scan_bytes(indio_dev,
671 buffer->scan_timestamp);
673 buffer->access->set_bytes_per_datum(buffer, bytes);
677 EXPORT_SYMBOL(iio_sw_buffer_preenable);
680 * iio_validate_scan_mask_onehot() - Validates that exactly one channel is selected
681 * @indio_dev: the iio device
682 * @mask: scan mask to be checked
684 * Return true if exactly one bit is set in the scan mask, false otherwise. It
685 * can be used for devices where only one channel can be active for sampling at
688 bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,
689 const unsigned long *mask)
691 return bitmap_weight(mask, indio_dev->masklength) == 1;
693 EXPORT_SYMBOL_GPL(iio_validate_scan_mask_onehot);
695 static bool iio_validate_scan_mask(struct iio_dev *indio_dev,
696 const unsigned long *mask)
698 if (!indio_dev->setup_ops->validate_scan_mask)
701 return indio_dev->setup_ops->validate_scan_mask(indio_dev, mask);
705 * iio_scan_mask_set() - set particular bit in the scan mask
706 * @buffer: the buffer whose scan mask we are interested in
707 * @bit: the bit to be set.
709 * Note that at this point we have no way of knowing what other
710 * buffers might request, hence this code only verifies that the
711 * individual buffers request is plausible.
713 int iio_scan_mask_set(struct iio_dev *indio_dev,
714 struct iio_buffer *buffer, int bit)
716 const unsigned long *mask;
717 unsigned long *trialmask;
719 trialmask = kmalloc(sizeof(*trialmask)*
720 BITS_TO_LONGS(indio_dev->masklength),
723 if (trialmask == NULL)
725 if (!indio_dev->masklength) {
726 WARN_ON("trying to set scanmask prior to registering buffer\n");
727 goto err_invalid_mask;
729 bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength);
730 set_bit(bit, trialmask);
732 if (!iio_validate_scan_mask(indio_dev, trialmask))
733 goto err_invalid_mask;
735 if (indio_dev->available_scan_masks) {
736 mask = iio_scan_mask_match(indio_dev->available_scan_masks,
737 indio_dev->masklength,
740 goto err_invalid_mask;
742 bitmap_copy(buffer->scan_mask, trialmask, indio_dev->masklength);
752 EXPORT_SYMBOL_GPL(iio_scan_mask_set);
754 int iio_scan_mask_query(struct iio_dev *indio_dev,
755 struct iio_buffer *buffer, int bit)
757 if (bit > indio_dev->masklength)
760 if (!buffer->scan_mask)
763 return test_bit(bit, buffer->scan_mask);
765 EXPORT_SYMBOL_GPL(iio_scan_mask_query);
768 * struct iio_demux_table() - table describing demux memcpy ops
769 * @from: index to copy from
770 * @to: index to copy to
771 * @length: how many bytes to copy
772 * @l: list head used for management
774 struct iio_demux_table {
781 static unsigned char *iio_demux(struct iio_buffer *buffer,
782 unsigned char *datain)
784 struct iio_demux_table *t;
786 if (list_empty(&buffer->demux_list))
788 list_for_each_entry(t, &buffer->demux_list, l)
789 memcpy(buffer->demux_bounce + t->to,
790 datain + t->from, t->length);
792 return buffer->demux_bounce;
795 static int iio_push_to_buffer(struct iio_buffer *buffer, unsigned char *data)
797 unsigned char *dataout = iio_demux(buffer, data);
799 return buffer->access->store_to(buffer, dataout);
802 static void iio_buffer_demux_free(struct iio_buffer *buffer)
804 struct iio_demux_table *p, *q;
805 list_for_each_entry_safe(p, q, &buffer->demux_list, l) {
812 int iio_push_to_buffers(struct iio_dev *indio_dev, unsigned char *data)
815 struct iio_buffer *buf;
817 list_for_each_entry(buf, &indio_dev->buffer_list, buffer_list) {
818 ret = iio_push_to_buffer(buf, data);
825 EXPORT_SYMBOL_GPL(iio_push_to_buffers);
827 static int iio_buffer_update_demux(struct iio_dev *indio_dev,
828 struct iio_buffer *buffer)
830 const struct iio_chan_spec *ch;
831 int ret, in_ind = -1, out_ind, length;
832 unsigned in_loc = 0, out_loc = 0;
833 struct iio_demux_table *p;
835 /* Clear out any old demux */
836 iio_buffer_demux_free(buffer);
837 kfree(buffer->demux_bounce);
838 buffer->demux_bounce = NULL;
840 /* First work out which scan mode we will actually have */
841 if (bitmap_equal(indio_dev->active_scan_mask,
843 indio_dev->masklength))
846 /* Now we have the two masks, work from least sig and build up sizes */
847 for_each_set_bit(out_ind,
848 indio_dev->active_scan_mask,
849 indio_dev->masklength) {
850 in_ind = find_next_bit(indio_dev->active_scan_mask,
851 indio_dev->masklength,
853 while (in_ind != out_ind) {
854 in_ind = find_next_bit(indio_dev->active_scan_mask,
855 indio_dev->masklength,
857 ch = iio_find_channel_from_si(indio_dev, in_ind);
858 length = ch->scan_type.storagebits/8;
859 /* Make sure we are aligned */
862 in_loc += length - in_loc % length;
864 p = kmalloc(sizeof(*p), GFP_KERNEL);
867 goto error_clear_mux_table;
869 ch = iio_find_channel_from_si(indio_dev, in_ind);
870 length = ch->scan_type.storagebits/8;
871 if (out_loc % length)
872 out_loc += length - out_loc % length;
874 in_loc += length - in_loc % length;
878 list_add_tail(&p->l, &buffer->demux_list);
882 /* Relies on scan_timestamp being last */
883 if (buffer->scan_timestamp) {
884 p = kmalloc(sizeof(*p), GFP_KERNEL);
887 goto error_clear_mux_table;
889 ch = iio_find_channel_from_si(indio_dev,
890 indio_dev->scan_index_timestamp);
891 length = ch->scan_type.storagebits/8;
892 if (out_loc % length)
893 out_loc += length - out_loc % length;
895 in_loc += length - in_loc % length;
899 list_add_tail(&p->l, &buffer->demux_list);
903 buffer->demux_bounce = kzalloc(out_loc, GFP_KERNEL);
904 if (buffer->demux_bounce == NULL) {
906 goto error_clear_mux_table;
910 error_clear_mux_table:
911 iio_buffer_demux_free(buffer);
916 int iio_update_demux(struct iio_dev *indio_dev)
918 struct iio_buffer *buffer;
921 list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
922 ret = iio_buffer_update_demux(indio_dev, buffer);
924 goto error_clear_mux_table;
928 error_clear_mux_table:
929 list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list)
930 iio_buffer_demux_free(buffer);
934 EXPORT_SYMBOL_GPL(iio_update_demux);