diff --git a/context.c b/context.c index c1feef0ff..3e28e3507 100644 --- a/context.c +++ b/context.c @@ -208,8 +208,12 @@ static void reorder_channels(struct iio_device *dev) qsort(dev->channels, dev->nb_channels, sizeof(struct iio_channel *), iio_channel_compare); - for (i = 0; i < dev->nb_channels; i++) - dev->channels[i]->number = i; + for (i = 0; i < dev->nb_channels; i++) { + struct iio_channel *chn = dev->channels[i]; + chn->number = i; + qsort(chn->attrs, chn->nb_attrs, sizeof(struct iio_channel_attr), + iio_channel_attr_compare); + } } int iio_context_init(struct iio_context *ctx) diff --git a/local.c b/local.c index 7491a4b1b..557d4fd8c 100644 --- a/local.c +++ b/local.c @@ -1767,9 +1767,6 @@ static int create_device(void *d, const char *path) free_protected_attrs(chn); if (ret < 0) goto err_free_scan_elements; - - qsort(chn->attrs, chn->nb_attrs, sizeof(struct iio_channel_attr), - iio_channel_attr_compare); } ret = detect_and_move_global_attrs(dev);