Skip to content

Commit

Permalink
program: Clean up error handling in program_load
Browse files Browse the repository at this point in the history
Main difference is cleaning up 'doc' in case of errors.
  • Loading branch information
lweiss-fairphone authored and Konrad Dybcio committed May 10, 2024
1 parent 7cc2748 commit 0132a8e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions program.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int program_load(const char *program_file, bool is_nand)
xmlNode *node;
xmlNode *root;
xmlDoc *doc;
int errors;
int errors = 0;

doc = xmlReadFile(program_file, NULL, 0);
if (!doc) {
Expand All @@ -140,8 +140,6 @@ int program_load(const char *program_file, bool is_nand)
if (node->type != XML_ELEMENT_NODE)
continue;

errors = -EINVAL;

if (!xmlStrcmp(node->name, (xmlChar *)"erase"))
errors = load_erase_tag(node, is_nand);
else if (!xmlStrcmp(node->name, (xmlChar *)"program"))
Expand All @@ -152,12 +150,13 @@ int program_load(const char *program_file, bool is_nand)
}

if (errors)
return errors;
goto out;
}

out:
xmlFreeDoc(doc);

return 0;
return errors;
}

int program_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct program *program, int fd),
Expand Down

0 comments on commit 0132a8e

Please sign in to comment.