summaryrefslogtreecommitdiff
path: root/src/shared/bootspec.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-06 14:44:05 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-08 17:57:57 +0200
commita847b539de828bf7e877cf0f8a014a8360d32a79 (patch)
tree4fec75f2e69e2439cc593ab484329b74572c55a8 /src/shared/bootspec.c
parent5ba1550fd8a80466693275e62e4b1e152e477cf8 (diff)
downloadsystemd-a847b539de828bf7e877cf0f8a014a8360d32a79.tar.gz
shared/bootspec: also export boot_config_load_type1()
The reallocation of memory and counter incrementation is moved from the only caller to the function. This way the callers can remain oblivious of the BootConfig internals.
Diffstat (limited to 'src/shared/bootspec.c')
-rw-r--r--src/shared/bootspec.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c
index 7215c9fc14..50875021d4 100644
--- a/src/shared/bootspec.c
+++ b/src/shared/bootspec.c
@@ -168,6 +168,31 @@ static int boot_entry_load_type1(
return 0;
}
+int boot_config_load_type1(
+ BootConfig *config,
+ FILE *f,
+ const char *root,
+ const char *dir,
+ const char *id) {
+ int r;
+
+ assert(config);
+ assert(f);
+ assert(root);
+ assert(dir);
+ assert(id);
+
+ if (!GREEDY_REALLOC0(config->entries, config->n_entries + 1))
+ return log_oom();
+
+ r = boot_entry_load_type1(f, root, dir, id, config->entries + config->n_entries);
+ if (r < 0)
+ return r;
+
+ config->n_entries++;
+ return 0;
+}
+
void boot_config_free(BootConfig *config) {
assert(config);
@@ -397,14 +422,9 @@ static int boot_entries_find_type1(
if (r == 0) /* inode already seen or otherwise not relevant */
continue;
- if (!GREEDY_REALLOC0(config->entries, config->n_entries + 1))
- return log_oom();
-
- r = boot_entry_load_type1(f, root, dir, de->d_name, config->entries + config->n_entries);
- if (r < 0)
- continue;
-
- config->n_entries++;
+ r = boot_config_load_type1(config, f, root, dir, de->d_name);
+ if (r == -ENOMEM)
+ return r;
}
return 0;