Skip to content

Commit 7e07fe6

Browse files
committed
xml: Simplify iio_populate_xml_context_helper
Just return an error code and let the caller set errno itself. Signed-off-by: Paul Cercueil <paul@crapouillou.net>
1 parent 94048d4 commit 7e07fe6

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

xml.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,17 @@ static int parse_context_attr(struct iio_context *ctx, xmlNode *n)
369369
static int iio_populate_xml_context_helper(struct iio_context *ctx, xmlNode *root)
370370
{
371371
xmlNode *n;
372-
int err = -ENOMEM;
372+
int err;
373373

374374
for (n = root->children; n; n = n->next) {
375375
struct iio_device *dev;
376376

377377
if (!strcmp((char *) n->name, "context-attribute")) {
378378
err = parse_context_attr(ctx, n);
379379
if (err)
380-
goto err_set_errno;
381-
else
382-
continue;
380+
return err;
381+
382+
continue;
383383
} else if (strcmp((char *) n->name, "device")) {
384384
if (strcmp((char *) n->name, "text"))
385385
IIO_WARNING("Unknown children \'%s\' in "
@@ -391,25 +391,17 @@ static int iio_populate_xml_context_helper(struct iio_context *ctx, xmlNode *roo
391391
if (IS_ERR(dev)) {
392392
err = PTR_TO_ERR(dev);
393393
IIO_ERROR("Unable to create device: %d\n", err);
394-
goto err_set_errno;
394+
return err;
395395
}
396396

397397
err = iio_context_add_device(ctx, dev);
398398
if (err) {
399399
free(dev);
400-
goto err_set_errno;
400+
return err;
401401
}
402402
}
403403

404-
err = iio_context_init(ctx);
405-
if (err)
406-
goto err_set_errno;
407-
408-
return 0;
409-
410-
err_set_errno:
411-
errno = -err;
412-
return err;
404+
return iio_context_init(ctx);
413405
}
414406

415407
static struct iio_context * iio_create_xml_context_helper(xmlDoc *doc)
@@ -418,6 +410,7 @@ static struct iio_context * iio_create_xml_context_helper(xmlDoc *doc)
418410
struct iio_context *ctx;
419411
xmlNode *root;
420412
xmlAttr *attr;
413+
int err;
421414

422415
root = xmlDocGetRootElement(doc);
423416
if (strcmp((char *) root->name, "context")) {
@@ -438,8 +431,10 @@ static struct iio_context * iio_create_xml_context_helper(xmlDoc *doc)
438431
if (!ctx)
439432
return NULL;
440433

441-
if (iio_populate_xml_context_helper(ctx, root)) {
434+
err = iio_populate_xml_context_helper(ctx, root);
435+
if (err) {
442436
iio_context_destroy(ctx);
437+
errno = -err;
443438
return NULL;
444439
}
445440

0 commit comments

Comments
 (0)