chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Remove libidn checks/support
[elogind.git]
/
src
/
shared
/
efivars.c
diff --git
a/src/shared/efivars.c
b/src/shared/efivars.c
index 2599a1aba1d91e2e0398732732dead4f3f04f459..20067c601adb41d205c2a4eda7c8e7fbfbc7c333 100644
(file)
--- 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;
uint32_t a;
ssize_t n;
struct stat st;
-
void *r
;
+
_cleanup_free_ void *buf = NULL
;
assert(name);
assert(value);
assert(name);
assert(value);
@@
-133,25
+133,22
@@
int efi_get_variable(
if (n != sizeof(a))
return -EIO;
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;
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;
return -errno;
- }
- if (n != (ssize_t) st.st_size - 4) {
- free(r);
+ if (n != (ssize_t) st.st_size - 4)
return -EIO;
return -EIO;
- }
/* Always NUL terminate (2 bytes, to protect UTF-16) */
/* 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 = (size_t) st.st_size - 4;
if (attribute)
@@
-339,7
+336,7
@@
int efi_get_boot_option(
p = NULL;
}
if (active)
p = NULL;
}
if (active)
- *active = !!
header->attr & LOAD_OPTION_ACTIVE
;
+ *active = !!
(header->attr & LOAD_OPTION_ACTIVE)
;
return 0;
}
return 0;
}
@@
-458,7
+455,7
@@
int efi_remove_boot_option(uint16_t id) {
}
int efi_get_boot_order(uint16_t **order) {
}
int efi_get_boot_order(uint16_t **order) {
-
void *buf
;
+
_cleanup_free_ void *buf = NULL
;
size_t l;
int r;
size_t l;
int r;
@@
-466,18
+463,15
@@
int efi_get_boot_order(uint16_t **order) {
if (r < 0)
return r;
if (r < 0)
return r;
- if (l <= 0) {
- free(buf);
+ if (l <= 0)
return -ENOENT;
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;
return -EINVAL;
- }
*order = buf;
*order = buf;
+ buf = NULL;
return (int) (l / sizeof(uint16_t));
}
return (int) (l / sizeof(uint16_t));
}
@@
-510,6
+504,7
@@
int efi_get_boot_options(uint16_t **options) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *de;
_cleanup_free_ uint16_t *list = NULL;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *de;
_cleanup_free_ uint16_t *list = NULL;
+ size_t alloc = 0;
int count = 0;
assert(options);
int count = 0;
assert(options);
@@
-520,7
+515,6
@@
int efi_get_boot_options(uint16_t **options) {
FOREACH_DIRENT(de, dir, return -errno) {
int id;
FOREACH_DIRENT(de, dir, return -errno) {
int id;
- uint16_t *t;
if (strncmp(de->d_name, "Boot", 4) != 0)
continue;
if (strncmp(de->d_name, "Boot", 4) != 0)
continue;
@@
-535,12
+529,10
@@
int efi_get_boot_options(uint16_t **options) {
if (id < 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;
return -ENOMEM;
- list = t;
- list[count ++] = id;
+ list[count++] = id;
}
qsort_safe(list, count, sizeof(uint16_t), cmp_uint16);
}
qsort_safe(list, count, sizeof(uint16_t), cmp_uint16);