diff --git a/context.c b/context.c index a202e80e9..d9d7c83cc 100644 --- a/context.c +++ b/context.c @@ -564,8 +564,8 @@ struct iio_device * iio_context_add_device(struct iio_context *ctx, devs[ctx->nb_devices++] = dev; ctx->devices = devs; - ctx_dbg(ctx, "Added device \'%s\' to context \'%s\'\n", - dev->id, ctx->name); + ctx_dbg(ctx, "Added device \'%s\' to context \'%s\' with label \'%s\'\n", + dev->id, ctx->name, dev->label); iio_sort_devices(ctx); diff --git a/local.c b/local.c index 0376f8e58..0c677fc2a 100644 --- a/local.c +++ b/local.c @@ -1099,15 +1099,14 @@ static int add_buffer_attr(void *d, const char *path) static int add_attr_or_channel_helper(struct iio_device *dev, const char *path, const char *prefix, - bool dir_is_scan_elements) + bool dir_is_scan_elements, bool is_event) { char buf[1024]; const char *name = strrchr(path, '/') + 1; - if (!dir_is_scan_elements && !is_channel(dev, name, true)) - return add_attr_to_device(dev, name); - iio_snprintf(buf, sizeof(buf), "%s%s", prefix, name); + if (!is_event && !dir_is_scan_elements && !is_channel(dev, name, true)) + return add_attr_to_device(dev, name); return add_channel(dev, name, buf, dir_is_scan_elements); } @@ -1115,19 +1114,19 @@ static int add_attr_or_channel_helper(struct iio_device *dev, static int add_attr_or_channel(void *d, const char *path) { return add_attr_or_channel_helper((struct iio_device *) d, - path, "", false); + path, "", false, false); } static int add_event(void *d, const char *path) { return add_attr_or_channel_helper((struct iio_device *) d, - path, "events/", false); + path, "events/", false, true); } static int add_scan_element(void *d, const char *path) { return add_attr_or_channel_helper((struct iio_device *) d, - path, "scan_elements/", true); + path, "scan_elements/", true, false); } static int foreach_in_dir(const struct iio_context *ctx, @@ -1251,7 +1250,7 @@ static int create_device(void *d, const char *path) ret = (int)local_do_read_dev_attr(id, 0, "label", label, sizeof(label), IIO_ATTR_TYPE_DEVICE); - if (ret < 0) + if (ret > 0) label_ptr = label; dev = iio_context_add_device(ctx, id, name_ptr, label_ptr);