summaryrefslogtreecommitdiff
path: root/src/shared/efivars.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-09 16:04:42 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-09 16:45:27 -0400
commit0797f2329ceeb989147416bdb368de4c21bad608 (patch)
tree62fb7dfaebde8b756b7aa692f8ca1ffb225e2025 /src/shared/efivars.c
parent0aa3b7830fd59d8b4ca275e9a9c4e79f8a23ff6d (diff)
efivars: use more _cleanup_
Also rename r to buf, since r is customarily reserved for the return value.
Diffstat (limited to 'src/shared/efivars.c')
-rw-r--r--src/shared/efivars.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/shared/efivars.c b/src/shared/efivars.c
index 6908f23e38..8b2b6af4bc 100644
--- a/src/shared/efivars.c
+++ b/src/shared/efivars.c
@@ -105,7 +105,7 @@ int efi_get_variable(
uint32_t a;
ssize_t n;
struct stat st;
- void *r;
+ _cleanup_free_ void *buf;
assert(name);
assert(value);
@@ -133,25 +133,22 @@ int efi_get_variable(
if (n != sizeof(a))
return -EIO;
- r = malloc(st.st_size - 4 + 2);
- if (!r)
+ buf = malloc(st.st_size - 4 + 2);
+ if (!buf)
return -ENOMEM;
- n = read(fd, r, (size_t) st.st_size - 4);
- if (n < 0) {
- free(r);
+ n = read(fd, buf, (size_t) st.st_size - 4);
+ if (n < 0)
return -errno;
- }
- if (n != (ssize_t) st.st_size - 4) {
- free(r);
+ if (n != (ssize_t) st.st_size - 4)
return -EIO;
- }
/* Always NUL terminate (2 bytes, to protect UTF-16) */
- ((char*) r)[st.st_size - 4] = 0;
- ((char*) r)[st.st_size - 4 + 1] = 0;
+ ((char*) buf)[st.st_size - 4] = 0;
+ ((char*) buf)[st.st_size - 4 + 1] = 0;
- *value = r;
+ *value = buf;
+ buf = NULL;
*size = (size_t) st.st_size - 4;
if (attribute)
@@ -458,7 +455,7 @@ int efi_remove_boot_option(uint16_t id) {
}
int efi_get_boot_order(uint16_t **order) {
- void *buf;
+ _cleanup_free_ void *buf = NULL;
size_t l;
int r;
@@ -466,18 +463,15 @@ int efi_get_boot_order(uint16_t **order) {
if (r < 0)
return r;
- if (l <= 0) {
- free(buf);
+ if (l <= 0)
return -ENOENT;
- }
- if ((l % sizeof(uint16_t) > 0) ||
- (l / sizeof(uint16_t) > INT_MAX)) {
- free(buf);
+ if (l % sizeof(uint16_t) > 0 ||
+ l / sizeof(uint16_t) > INT_MAX)
return -EINVAL;
- }
*order = buf;
+ buf = NULL;
return (int) (l / sizeof(uint16_t));
}