uint32_t a;
ssize_t n;
struct stat st;
- void *r;
+ _cleanup_free_ void *buf = NULL;
assert(name);
assert(value);
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)
size_t title_size;
_cleanup_free_ char *s = NULL, *p = NULL;
sd_id128_t p_uuid = SD_ID128_NULL;
- int err;
+ int r;
xsprintf(boot_id, "Boot%04X", id);
- err = efi_get_variable(EFI_VENDOR_GLOBAL, boot_id, NULL, (void **)&buf, &l);
- if (err < 0)
- return err;
+ r = efi_get_variable(EFI_VENDOR_GLOBAL, boot_id, NULL, (void **)&buf, &l);
+ if (r < 0)
+ return r;
if (l < sizeof(struct boot_option))
return -ENOENT;
p = NULL;
}
if (active)
- *active = !!header->attr & LOAD_OPTION_ACTIVE;
+ *active = !!(header->attr & LOAD_OPTION_ACTIVE);
return 0;
}
}
int efi_get_boot_order(uint16_t **order) {
- void *buf;
+ _cleanup_free_ void *buf = NULL;
size_t l;
int r;
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));
}
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *de;
_cleanup_free_ uint16_t *list = NULL;
+ size_t alloc = 0;
int count = 0;
assert(options);
FOREACH_DIRENT(de, dir, return -errno) {
int id;
- uint16_t *t;
if (strncmp(de->d_name, "Boot", 4) != 0)
continue;
if (id < 0)
continue;
- t = realloc(list, (count + 1) * sizeof(uint16_t));
- if (!t)
+ if (!GREEDY_REALLOC(list, alloc, count + 1))
return -ENOMEM;
- list = t;
- list[count ++] = id;
+ list[count++] = id;
}
qsort_safe(list, count, sizeof(uint16_t), cmp_uint16);