Skip to content

Commit

Permalink
local: Init device label when found
Browse files Browse the repository at this point in the history
When the "label" device attribute is found, initialize the device's
label to its value.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Apr 9, 2021
1 parent bdd9c45 commit 7ef90bc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit 7ef90bc

Please sign in to comment.