From 7ef90bca7260e968a2dd18a905414c4908fc3a63 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Thu, 1 Apr 2021 16:11:00 +0100 Subject: [PATCH] local: Init device label when found When the "label" device attribute is found, initialize the device's label to its value. Signed-off-by: Paul Cercueil --- local.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/local.c b/local.c index 7e877030f..518e031ff 100644 --- a/local.c +++ b/local.c @@ -1221,6 +1221,22 @@ static int read_device_name(struct iio_device *dev) return 0; } +static int read_device_label(struct iio_device *dev) +{ + char buf[1024]; + ssize_t ret = iio_device_attr_read(dev, "label", buf, sizeof(buf)); + if (ret < 0) + return ret; + else if (ret == 0) + return -EIO; + + dev->label = iio_strdup(buf); + if (!dev->label) + return -ENOMEM; + else + return 0; +} + static int add_attr_to_device(struct iio_device *dev, const char *attr) { unsigned int i; @@ -1231,6 +1247,8 @@ static int add_attr_to_device(struct iio_device *dev, const char *attr) if (!strcmp(attr, "name")) return read_device_name(dev); + if (!strcmp(attr, "label")) + return read_device_label(dev); return add_iio_dev_attr(&dev->attrs, attr, " ", dev->id); }