coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any option in coccinelle for this, so instead, I edited the patch text using search&replace to remove the braces. Unfortunately this is not fully automatic, in particular it didn't deal well with if-else-if-else blocks and ifdefs, so there is an increased likelikehood be some bugs in such spots. I also removed part of the patch that coccinelle generated for udev, where we returns -1 for failure. This should be fixed independently.
This commit is contained in:
+26
-28
@@ -121,10 +121,10 @@ static int parse_counter(
|
||||
e++;
|
||||
|
||||
k = strspn(e, DIGITS);
|
||||
if (k == 0) {
|
||||
log_error("Can't parse empty 'tries left' counter from LoaderBootCountPath: %s", path);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (k == 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Can't parse empty 'tries left' counter from LoaderBootCountPath: %s",
|
||||
path);
|
||||
|
||||
z = strndupa(e, k);
|
||||
r = safe_atou64(z, &left);
|
||||
@@ -137,10 +137,10 @@ static int parse_counter(
|
||||
e++;
|
||||
|
||||
k = strspn(e, DIGITS);
|
||||
if (k == 0) { /* If there's a "-" there also needs to be at least one digit */
|
||||
log_error("Can't parse empty 'tries done' counter from LoaderBootCountPath: %s", path);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (k == 0) /* If there's a "-" there also needs to be at least one digit */
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Can't parse empty 'tries done' counter from LoaderBootCountPath: %s",
|
||||
path);
|
||||
|
||||
z = strndupa(e, k);
|
||||
r = safe_atou64(z, &done);
|
||||
@@ -185,22 +185,22 @@ static int acquire_boot_count_path(
|
||||
|
||||
efi_tilt_backslashes(path);
|
||||
|
||||
if (!path_is_normalized(path)) {
|
||||
log_error("Path read from LoaderBootCountPath is not normalized, refusing: %s", path);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!path_is_normalized(path))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Path read from LoaderBootCountPath is not normalized, refusing: %s",
|
||||
path);
|
||||
|
||||
if (!path_is_absolute(path)) {
|
||||
log_error("Path read from LoaderBootCountPath is not absolute, refusing: %s", path);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!path_is_absolute(path))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Path read from LoaderBootCountPath is not absolute, refusing: %s",
|
||||
path);
|
||||
|
||||
last = last_path_component(path);
|
||||
e = strrchr(last, '+');
|
||||
if (!e) {
|
||||
log_error("Path read from LoaderBootCountPath does not contain a counter, refusing: %s", path);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!e)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Path read from LoaderBootCountPath does not contain a counter, refusing: %s",
|
||||
path);
|
||||
|
||||
if (ret_prefix) {
|
||||
prefix = strndup(path, e - path);
|
||||
@@ -458,15 +458,13 @@ static int run(int argc, char *argv[]) {
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
if (detect_container() > 0) {
|
||||
log_error("Marking a boot is not supported in containers.");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
if (detect_container() > 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"Marking a boot is not supported in containers.");
|
||||
|
||||
if (!is_efi_boot()) {
|
||||
log_error("Marking a boot is only supported on EFI systems.");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
if (!is_efi_boot())
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"Marking a boot is only supported on EFI systems.");
|
||||
|
||||
return dispatch_verb(argc, argv, verbs, NULL);
|
||||
}
|
||||
|
||||
+19
-20
@@ -372,18 +372,18 @@ static int version_check(int fd_from, const char *from, int fd_to, const char *t
|
||||
r = get_file_version(fd_from, &a);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0) {
|
||||
log_error("Source file \"%s\" does not carry version information!", from);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (r == 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Source file \"%s\" does not carry version information!",
|
||||
from);
|
||||
|
||||
r = get_file_version(fd_to, &b);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0 || compare_product(a, b) != 0) {
|
||||
log_notice("Skipping \"%s\", since it's owned by another boot loader.", to);
|
||||
return -EEXIST;
|
||||
}
|
||||
if (r == 0 || compare_product(a, b) != 0)
|
||||
return log_notice_errno(SYNTHETIC_ERRNO(EEXIST),
|
||||
"Skipping \"%s\", since it's owned by another boot loader.",
|
||||
to);
|
||||
|
||||
if (compare_version(a, b) < 0) {
|
||||
log_warning("Skipping \"%s\", since a newer boot loader version exists already.", to);
|
||||
@@ -1193,10 +1193,9 @@ static int verb_set_default(int argc, char *argv[], void *userdata) {
|
||||
const char *name;
|
||||
int r;
|
||||
|
||||
if (!is_efi_boot()) {
|
||||
log_error("Not booted with UEFI.");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
if (!is_efi_boot())
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"Not booted with UEFI.");
|
||||
|
||||
if (access("/sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f", F_OK) < 0) {
|
||||
if (errno == ENOENT) {
|
||||
@@ -1207,15 +1206,15 @@ static int verb_set_default(int argc, char *argv[], void *userdata) {
|
||||
return log_error_errno(errno, "Failed to detect whether boot loader supports '%s' operation: %m", argv[0]);
|
||||
}
|
||||
|
||||
if (detect_container() > 0) {
|
||||
log_error("'%s' operation not supported in a container.", argv[0]);
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
if (detect_container() > 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"'%s' operation not supported in a container.",
|
||||
argv[0]);
|
||||
|
||||
if (!arg_touch_variables) {
|
||||
log_error("'%s' operation cannot be combined with --touch-variables=no.", argv[0]);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!arg_touch_variables)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"'%s' operation cannot be combined with --touch-variables=no.",
|
||||
argv[0]);
|
||||
|
||||
name = streq(argv[0], "set-default") ? "LoaderEntryDefault" : "LoaderEntryOneShot";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user