Skip to content

Commit

Permalink
xml: Properly handle errors in add_attr_to_{channel,device}
Browse files Browse the repository at this point in the history
It would previously ignore some errors (strdup failing) and return
nonsense -1 code which would be interpreted as -EPERM.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Apr 22, 2021
1 parent cb01ccd commit facf0e2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ static int add_attr_to_channel(struct iio_channel *chn, xmlNode *n)
xmlAttr *attr;
char *name = NULL, *filename = NULL;
struct iio_channel_attr *attrs;
int err = -ENOMEM;

for (attr = n->properties; attr; attr = attr->next) {
if (!strcmp((char *) attr->name, "name")) {
name = iio_strdup((char *) attr->children->content);
if (!name)
goto err_free;
} else if (!strcmp((char *) attr->name, "filename")) {
filename = iio_strdup((char *) attr->children->content);
if (!filename)
goto err_free;
} else {
IIO_WARNING("Unknown field \'%s\' in channel %s\n",
attr->name, chn->id);
Expand All @@ -32,6 +37,7 @@ static int add_attr_to_channel(struct iio_channel *chn, xmlNode *n)

if (!name) {
IIO_ERROR("Incomplete attribute in channel %s\n", chn->id);
err = -EINVAL;
goto err_free;
}

Expand All @@ -54,7 +60,7 @@ static int add_attr_to_channel(struct iio_channel *chn, xmlNode *n)
err_free:
free(name);
free(filename);
return -1;
return err;
}

static int add_attr_to_device(struct iio_device *dev, xmlNode *n, enum iio_attr_type type)
Expand All @@ -73,7 +79,7 @@ static int add_attr_to_device(struct iio_device *dev, xmlNode *n, enum iio_attr_

if (!name) {
IIO_ERROR("Incomplete attribute in device %s\n", dev->id);
return -1;
return -EINVAL;
}

switch(type) {
Expand All @@ -84,7 +90,7 @@ static int add_attr_to_device(struct iio_device *dev, xmlNode *n, enum iio_attr_
case IIO_ATTR_TYPE_BUFFER:
return add_iio_dev_attr(&dev->buffer_attrs, name, " buffer", dev->id);
default:
return -1;
return -EINVAL;
}
}

Expand Down

0 comments on commit facf0e2

Please sign in to comment.