diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-20 23:40:44 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-22 10:54:38 +0100 |
commit | baaa35ad706419ae5aacc11d2bece5bd8b73ee42 (patch) | |
tree | bb4b9c576fc56b3237d59e959ded7c245917fcd7 /src/udev | |
parent | basic/log: add concept of "synthethic errnos" (diff) | |
download | systemd-baaa35ad706419ae5aacc11d2bece5bd8b73ee42.tar.xz systemd-baaa35ad706419ae5aacc11d2bece5bd8b73ee42.zip |
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.
Diffstat (limited to 'src/udev')
-rw-r--r-- | src/udev/mtd_probe/probe_smartmedia.c | 28 | ||||
-rw-r--r-- | src/udev/udev-builtin-kmod.c | 7 | ||||
-rw-r--r-- | src/udev/udev-event.c | 7 | ||||
-rw-r--r-- | src/udev/udev-rules.c | 8 | ||||
-rw-r--r-- | src/udev/udevadm-hwdb.c | 7 | ||||
-rw-r--r-- | src/udev/udevadm-settle.c | 5 | ||||
-rw-r--r-- | src/udev/udevadm-test-builtin.c | 14 | ||||
-rw-r--r-- | src/udev/udevadm-test.c | 14 |
8 files changed, 40 insertions, 50 deletions
diff --git a/src/udev/mtd_probe/probe_smartmedia.c b/src/udev/mtd_probe/probe_smartmedia.c index 099809da1b..f8e1b140f5 100644 --- a/src/udev/mtd_probe/probe_smartmedia.c +++ b/src/udev/mtd_probe/probe_smartmedia.c @@ -49,19 +49,17 @@ int probe_smart_media(int mtd_fd, mtd_info_t* info) { if (!cis_buffer) return log_oom(); - if (info->type != MTD_NANDFLASH) { - log_debug("Not marked MTD_NANDFLASH."); - return -EINVAL; - } + if (info->type != MTD_NANDFLASH) + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "Not marked MTD_NANDFLASH."); sector_size = info->writesize; block_size = info->erasesize; size_in_megs = info->size / (1024 * 1024); - if (!IN_SET(sector_size, SM_SECTOR_SIZE, SM_SMALL_PAGE)) { - log_debug("Unexpected sector size: %i", sector_size); - return -EINVAL; - } + if (!IN_SET(sector_size, SM_SECTOR_SIZE, SM_SMALL_PAGE)) + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "Unexpected sector size: %i", sector_size); switch(size_in_megs) { case 1: @@ -85,16 +83,14 @@ int probe_smart_media(int mtd_fd, mtd_info_t* info) { } } - if (!cis_found) { - log_debug("CIS not found"); - return -EINVAL; - } + if (!cis_found) + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "CIS not found"); if (memcmp(cis_buffer, cis_signature, sizeof(cis_signature)) != 0 && - memcmp(cis_buffer + SM_SMALL_PAGE, cis_signature, sizeof(cis_signature)) != 0) { - log_debug("CIS signature didn't match"); - return -EINVAL; - } + memcmp(cis_buffer + SM_SMALL_PAGE, cis_signature, sizeof(cis_signature)) != 0) + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "CIS signature didn't match"); printf("MTD_FTL=smartmedia\n"); return 0; diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c index d8575b72bd..ce52149b1d 100644 --- a/src/udev/udev-builtin-kmod.c +++ b/src/udev/udev-builtin-kmod.c @@ -27,10 +27,9 @@ static int builtin_kmod(sd_device *dev, int argc, char *argv[], bool test) { if (!ctx) return 0; - if (argc < 3 || !streq(argv[1], "load")) { - log_error("%s: expected: load <module>", argv[0]); - return -EINVAL; - } + if (argc < 3 || !streq(argv[1], "load")) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "%s: expected: load <module>", argv[0]); for (i = 2; argv[i]; i++) (void) module_load_and_warn(ctx, argv[i], false); diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index f69458ef9b..c60c02e7fe 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -625,10 +625,9 @@ int udev_event_spawn(struct udev_event *event, if (!argv) return log_oom(); - if (isempty(argv[0])) { - log_error("Invalid command '%s'", cmd); - return -EINVAL; - } + if (isempty(argv[0])) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid command '%s'", cmd); /* allow programs in /usr/lib/udev/ to be called without the path */ if (!path_is_absolute(argv[0])) { diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 4f3dffad49..da1dee6e13 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -605,10 +605,10 @@ static int import_property_from_string(sd_device *dev, char *line) { /* unquote */ if (IN_SET(val[0], '"', '\'')) { - if (len == 1 || val[len-1] != val[0]) { - log_debug("inconsistent quoting: '%s', skip", line); - return -EINVAL; - } + if (len == 1 || val[len-1] != val[0]) + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "inconsistent quoting: '%s', skip", + line); val[len-1] = '\0'; val++; } diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index e9a1af65fc..7f8960f549 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -84,10 +84,9 @@ int hwdb_main(int argc, char *argv[], void *userdata) { if (r <= 0) return r; - if (!arg_update && !arg_test) { - log_error("Either --update or --test must be used."); - return -EINVAL; - } + if (!arg_update && !arg_test) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Either --update or --test must be used."); if (arg_update) { r = hwdb_update(arg_root, arg_hwdb_bin_dir, arg_strict, true); diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index a2a8893870..4ae237d430 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -65,8 +65,9 @@ static int parse_argv(int argc, char *argv[]) { case 's': case 'e': case 'q': - log_info("Option -%c no longer supported.", c); - return -EINVAL; + return log_info_errno(SYNTHETIC_ERRNO(EINVAL), + "Option -%c no longer supported.", + c); case '?': return -EINVAL; default: diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 7bf7b08a44..22c3184a01 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -49,16 +49,14 @@ static int parse_argv(int argc, char *argv[]) { } arg_command = argv[optind++]; - if (!arg_command) { - log_error("Command missing."); - return -EINVAL; - } + if (!arg_command) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Command missing."); arg_syspath = argv[optind++]; - if (!arg_syspath) { - log_error("syspath missing."); - return -EINVAL; - } + if (!arg_syspath) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "syspath missing."); return 1; } diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index 2ee78da51b..a5f05ea836 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -58,10 +58,9 @@ static int parse_argv(int argc, char *argv[]) { break; case 'N': arg_resolve_name_timing = resolve_name_timing_from_string(optarg); - if (arg_resolve_name_timing < 0) { - log_error("--resolve-names= must be early, late or never"); - return -EINVAL; - } + if (arg_resolve_name_timing < 0) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "--resolve-names= must be early, late or never"); break; case 'V': return print_version(); @@ -73,10 +72,9 @@ static int parse_argv(int argc, char *argv[]) { assert_not_reached("Unknown option"); } - if (!argv[optind]) { - log_error("syspath parameter missing."); - return -EINVAL; - } + if (!argv[optind]) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "syspath parameter missing."); /* add /sys if needed */ if (!startswith(argv[optind], "/sys")) |