tree-wide: update empty-if coccinelle script to cover empty-while and more

Let's also clean up single-line while and for blocks.
This commit is contained in:
Lennart Poettering 2015-09-09 14:23:02 +02:00
parent 94c156cd45
commit 1f6b411372
20 changed files with 76 additions and 63 deletions

View file

@ -1,19 +1,56 @@
@@ @@
expression e, f; expression e, f, g, h, i, j;
statement s, t; statement s, t;
@@ @@
( (
if (e) { if (e) {
if (f) s (
if (h) s
|
if (h) s else t
|
while (h) s
|
for (h; i; j) s
)
} }
| |
if (e) { while (e) {
if (f) s (
else t if (h) s
|
if (h) s else t
|
while (h) s
|
for (h; i; j) s
)
}
|
for (e; f; g) {
(
if (h) s
|
if (h) s else t
|
while (h) s
|
for (h; i; j) s
)
} }
| |
- if (e) { - if (e) {
+ if (e) + if (e)
s s
- } - }
|
- while (e) {
+ while (e)
s
- }
|
- for (e; f; g) {
+ for (e; f; g)
s
- }
) )

View file

@ -67,10 +67,9 @@ EFI_STATUS graphics_mode(BOOLEAN on) {
EFI_STATUS err; EFI_STATUS err;
err = LibLocateProtocol(&ConsoleControlProtocolGuid, (VOID **)&ConsoleControl); err = LibLocateProtocol(&ConsoleControlProtocolGuid, (VOID **)&ConsoleControl);
if (EFI_ERROR(err)) { if (EFI_ERROR(err))
/* console control protocol is nonstandard and might not exist. */ /* console control protocol is nonstandard and might not exist. */
return err == EFI_NOT_FOUND ? EFI_SUCCESS : err; return err == EFI_NOT_FOUND ? EFI_SUCCESS : err;
}
/* check current mode */ /* check current mode */
err = uefi_call_wrapper(ConsoleControl->GetMode, 4, ConsoleControl, &current, &uga_exists, &stdin_locked); err = uefi_call_wrapper(ConsoleControl->GetMode, 4, ConsoleControl, &current, &uga_exists, &stdin_locked);

View file

@ -338,10 +338,9 @@ int main(int argc, char *argv[]) {
* - child logs data * - child logs data
*/ */
if (getpid() == 1) { if (getpid() == 1) {
if (fork()) { if (fork())
/* parent */ /* parent */
execl(arg_init_path, arg_init_path, NULL); execl(arg_init_path, arg_init_path, NULL);
}
} }
argv[0][0] = '@'; argv[0][0] = '@';

View file

@ -1998,9 +1998,8 @@ void exec_context_done(ExecContext *c) {
strv_free(c->environment_files); strv_free(c->environment_files);
c->environment_files = NULL; c->environment_files = NULL;
for (l = 0; l < ELEMENTSOF(c->rlimit); l++) { for (l = 0; l < ELEMENTSOF(c->rlimit); l++)
c->rlimit[l] = mfree(c->rlimit[l]); c->rlimit[l] = mfree(c->rlimit[l]);
}
c->working_directory = mfree(c->working_directory); c->working_directory = mfree(c->working_directory);
c->root_directory = mfree(c->root_directory); c->root_directory = mfree(c->root_directory);

View file

@ -1841,9 +1841,8 @@ finish:
arg_shutdown_watchdog = m->shutdown_watchdog; arg_shutdown_watchdog = m->shutdown_watchdog;
m = manager_free(m); m = manager_free(m);
for (j = 0; j < ELEMENTSOF(arg_default_rlimit); j++) { for (j = 0; j < ELEMENTSOF(arg_default_rlimit); j++)
arg_default_rlimit[j] = mfree(arg_default_rlimit[j]); arg_default_rlimit[j] = mfree(arg_default_rlimit[j]);
}
arg_default_unit = mfree(arg_default_unit); arg_default_unit = mfree(arg_default_unit);

View file

@ -555,10 +555,9 @@ int setup_namespace(
/* Remount / as the desired mode. Not that this will not /* Remount / as the desired mode. Not that this will not
* reestablish propagation from our side to the host, since * reestablish propagation from our side to the host, since
* what's disconnected is disconnected. */ * what's disconnected is disconnected. */
if (mount(NULL, "/", NULL, mount_flags | MS_REC, NULL) < 0) { if (mount(NULL, "/", NULL, mount_flags | MS_REC, NULL) < 0)
/* at this point, we cannot rollback */ /* at this point, we cannot rollback */
return -errno; return -errno;
}
return 0; return 0;

View file

@ -2937,14 +2937,11 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags, FDSet *fds)
} }
/* Interpret WATCHDOG= */ /* Interpret WATCHDOG= */
if (strv_find(tags, "WATCHDOG=1")) { if (strv_find(tags, "WATCHDOG=1"))
service_reset_watchdog(s); service_reset_watchdog(s);
}
/* Add the passed fds to the fd store */ if (strv_find(tags, "FDSTORE=1"))
if (strv_find(tags, "FDSTORE=1")) {
service_add_fd_store_set(s, fds); service_add_fd_store_set(s, fds);
}
/* Notify clients about changed status or main pid */ /* Notify clients about changed status or main pid */
if (notify_dbus) if (notify_dbus)

View file

@ -95,11 +95,10 @@ static int generate_mask_symlinks(void) {
if (!p) if (!p)
return log_oom(); return log_oom();
if (symlink("/dev/null", p) < 0) { if (symlink("/dev/null", p) < 0)
r = log_error_errno(errno, r = log_error_errno(errno,
"Failed to create mask symlink %s: %m", "Failed to create mask symlink %s: %m",
p); p);
}
} }
return r; return r;
@ -125,11 +124,10 @@ static int generate_wants_symlinks(void) {
mkdir_parents_label(p, 0755); mkdir_parents_label(p, 0755);
if (symlink(f, p) < 0) { if (symlink(f, p) < 0)
r = log_error_errno(errno, r = log_error_errno(errno,
"Failed to create wants symlink %s: %m", "Failed to create wants symlink %s: %m",
p); p);
}
} }
return r; return r;

View file

@ -63,9 +63,8 @@ static void context_reset(Context *c) {
assert(c); assert(c);
for (p = 0; p < _PROP_MAX; p++) { for (p = 0; p < _PROP_MAX; p++)
c->data[p] = mfree(c->data[p]); c->data[p] = mfree(c->data[p]);
}
} }
static void context_free(Context *c) { static void context_free(Context *c) {

View file

@ -614,10 +614,9 @@ static int request_handler(
return code; return code;
} else { } else {
r = getnameinfo_pretty(fd, &hostname); r = getnameinfo_pretty(fd, &hostname);
if (r < 0) { if (r < 0)
return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
"Cannot check remote hostname"); "Cannot check remote hostname");
}
} }
assert(hostname); assert(hostname);

View file

@ -184,6 +184,7 @@ void server_process_native_message(
free(identifier); free(identifier);
identifier = t; identifier = t;
} }
} else if (l >= 8 && } else if (l >= 8 &&
startswith(p, "MESSAGE=")) { startswith(p, "MESSAGE=")) {
char *t; char *t;
@ -193,6 +194,7 @@ void server_process_native_message(
free(message); free(message);
message = t; message = t;
} }
} else if (l > strlen("OBJECT_PID=") && } else if (l > strlen("OBJECT_PID=") &&
l < strlen("OBJECT_PID=") + DECIMAL_STR_MAX(pid_t) && l < strlen("OBJECT_PID=") + DECIMAL_STR_MAX(pid_t) &&
startswith(p, "OBJECT_PID=") && startswith(p, "OBJECT_PID=") &&

View file

@ -892,9 +892,8 @@ int sd_netlink_message_rewind(sd_netlink_message *m) {
if (!m->sealed) if (!m->sealed)
rtnl_message_seal(m); rtnl_message_seal(m);
for (i = 1; i <= m->n_containers; i++) { for (i = 1; i <= m->n_containers; i++)
m->containers[i].attributes = mfree(m->containers[i].attributes); m->containers[i].attributes = mfree(m->containers[i].attributes);
}
m->n_containers = 0; m->n_containers = 0;

View file

@ -311,9 +311,8 @@ static int pty_dispatch_read(Pty *pty) {
continue; continue;
return (errno == EAGAIN) ? 0 : -errno; return (errno == EAGAIN) ? 0 : -errno;
} else if (len == 0) { } else if (len == 0)
continue; continue;
}
/* set terminating zero for debugging safety */ /* set terminating zero for debugging safety */
pty->in_buf[len] = 0; pty->in_buf[len] = 0;
@ -356,9 +355,8 @@ static int pty_dispatch_write(Pty *pty) {
continue; continue;
return (errno == EAGAIN) ? 1 : -errno; return (errno == EAGAIN) ? 1 : -errno;
} else if (len == 0) { } else if (len == 0)
continue; continue;
}
ring_pull(&pty->out_buf, (size_t)len); ring_pull(&pty->out_buf, (size_t)len);
} }

View file

@ -27,19 +27,16 @@ static void test_ratelimit_test(void) {
int i; int i;
RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10); RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10);
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++)
assert_se(ratelimit_test(&ratelimit)); assert_se(ratelimit_test(&ratelimit));
}
assert_se(!ratelimit_test(&ratelimit)); assert_se(!ratelimit_test(&ratelimit));
sleep(1); sleep(1);
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++)
assert_se(ratelimit_test(&ratelimit)); assert_se(ratelimit_test(&ratelimit));
}
RATELIMIT_INIT(ratelimit, 0, 10); RATELIMIT_INIT(ratelimit, 0, 10);
for (i = 0; i < 10000; i++) { for (i = 0; i < 10000; i++)
assert_se(ratelimit_test(&ratelimit)); assert_se(ratelimit_test(&ratelimit));
}
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {

View file

@ -565,9 +565,8 @@ static int cd_profiles(struct udev *udev, int fd)
if (len > sizeof(features)) { if (len > sizeof(features)) {
log_debug("can not get features in a single query, truncating"); log_debug("can not get features in a single query, truncating");
len = sizeof(features); len = sizeof(features);
} else if (len <= 8) { } else if (len <= 8)
len = sizeof(features); len = sizeof(features);
}
/* Now get the full feature buffer */ /* Now get the full feature buffer */
scsi_cmd_init(udev, &sc); scsi_cmd_init(udev, &sc);

View file

@ -279,9 +279,9 @@ static int get_file_options(struct udev *udev,
strcpy(buffer, options_in); strcpy(buffer, options_in);
c = argc_count(buffer) + 2; c = argc_count(buffer) + 2;
*newargv = calloc(c, sizeof(**newargv)); *newargv = calloc(c, sizeof(**newargv));
if (!*newargv) { if (!*newargv)
retval = log_oom(); retval = log_oom();
} else { else {
*argc = c; *argc = c;
c = 0; c = 0;
/* /*
@ -537,16 +537,13 @@ static int scsi_id(struct udev *udev, char *maj_min_dev)
if (dev_scsi.wwn_vendor_extension[0] != '\0') { if (dev_scsi.wwn_vendor_extension[0] != '\0') {
printf("ID_WWN_VENDOR_EXTENSION=0x%s\n", dev_scsi.wwn_vendor_extension); printf("ID_WWN_VENDOR_EXTENSION=0x%s\n", dev_scsi.wwn_vendor_extension);
printf("ID_WWN_WITH_EXTENSION=0x%s%s\n", dev_scsi.wwn, dev_scsi.wwn_vendor_extension); printf("ID_WWN_WITH_EXTENSION=0x%s%s\n", dev_scsi.wwn, dev_scsi.wwn_vendor_extension);
} else { } else
printf("ID_WWN_WITH_EXTENSION=0x%s\n", dev_scsi.wwn); printf("ID_WWN_WITH_EXTENSION=0x%s\n", dev_scsi.wwn);
}
} }
if (dev_scsi.tgpt_group[0] != '\0') { if (dev_scsi.tgpt_group[0] != '\0')
printf("ID_TARGET_PORT=%s\n", dev_scsi.tgpt_group); printf("ID_TARGET_PORT=%s\n", dev_scsi.tgpt_group);
} if (dev_scsi.unit_serial_number[0] != '\0')
if (dev_scsi.unit_serial_number[0] != '\0') {
printf("ID_SCSI_SERIAL=%s\n", dev_scsi.unit_serial_number); printf("ID_SCSI_SERIAL=%s\n", dev_scsi.unit_serial_number);
}
goto out; goto out;
} }

View file

@ -135,9 +135,8 @@ static int sg_err_category_new(struct udev *udev,
return SG_ERR_CAT_MEDIA_CHANGED; return SG_ERR_CAT_MEDIA_CHANGED;
if (0x29 == asc) if (0x29 == asc)
return SG_ERR_CAT_RESET; return SG_ERR_CAT_RESET;
} else if (sense_key == ILLEGAL_REQUEST) { } else if (sense_key == ILLEGAL_REQUEST)
return SG_ERR_CAT_NOTSUPPORTED; return SG_ERR_CAT_NOTSUPPORTED;
}
} }
return SG_ERR_CAT_SENSE; return SG_ERR_CAT_SENSE;
} }
@ -490,9 +489,8 @@ static int check_fill_0x83_id(struct udev *udev,
if ((page_83[1] & 0x30) == 0x10) { if ((page_83[1] & 0x30) == 0x10) {
if (id_search->id_type != SCSI_ID_TGTGROUP) if (id_search->id_type != SCSI_ID_TGTGROUP)
return 1; return 1;
} else if ((page_83[1] & 0x30) != 0) { } else if ((page_83[1] & 0x30) != 0)
return 1; return 1;
}
if ((page_83[1] & 0x0f) != id_search->id_type) if ((page_83[1] & 0x0f) != id_search->id_type)
return 1; return 1;

View file

@ -255,9 +255,8 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
} }
override_abs(fd, node, evcode, udev_list_entry_get_value(entry)); override_abs(fd, node, evcode, udev_list_entry_get_value(entry));
} else if (streq(key, "POINTINGSTICK_SENSITIVITY")) { } else if (streq(key, "POINTINGSTICK_SENSITIVITY"))
set_trackpoint_sensitivity(dev, udev_list_entry_get_value(entry)); set_trackpoint_sensitivity(dev, udev_list_entry_get_value(entry));
}
} }
/* install list of force-release codes */ /* install list of force-release codes */

View file

@ -1428,9 +1428,9 @@ static int add_rule(struct udev_rules *rules, char *line,
} else if ((rules->resolve_names > 0) && strchr("$%", value[0]) == NULL) { } else if ((rules->resolve_names > 0) && strchr("$%", value[0]) == NULL) {
uid = add_uid(rules, value); uid = add_uid(rules, value);
rule_add_key(&rule_tmp, TK_A_OWNER_ID, op, NULL, &uid); rule_add_key(&rule_tmp, TK_A_OWNER_ID, op, NULL, &uid);
} else if (rules->resolve_names >= 0) { } else if (rules->resolve_names >= 0)
rule_add_key(&rule_tmp, TK_A_OWNER, op, value, NULL); rule_add_key(&rule_tmp, TK_A_OWNER, op, value, NULL);
}
rule_tmp.rule.rule.can_set_name = true; rule_tmp.rule.rule.can_set_name = true;
continue; continue;
} }
@ -1450,9 +1450,9 @@ static int add_rule(struct udev_rules *rules, char *line,
} else if ((rules->resolve_names > 0) && strchr("$%", value[0]) == NULL) { } else if ((rules->resolve_names > 0) && strchr("$%", value[0]) == NULL) {
gid = add_gid(rules, value); gid = add_gid(rules, value);
rule_add_key(&rule_tmp, TK_A_GROUP_ID, op, NULL, &gid); rule_add_key(&rule_tmp, TK_A_GROUP_ID, op, NULL, &gid);
} else if (rules->resolve_names >= 0) { } else if (rules->resolve_names >= 0)
rule_add_key(&rule_tmp, TK_A_GROUP, op, value, NULL); rule_add_key(&rule_tmp, TK_A_GROUP, op, value, NULL);
}
rule_tmp.rule.rule.can_set_name = true; rule_tmp.rule.rule.can_set_name = true;
continue; continue;
} }

View file

@ -83,9 +83,8 @@ unlink:
closedir(dir); closedir(dir);
rmdir("/run/udev/watch.old"); rmdir("/run/udev/watch.old");
} else if (errno != ENOENT) { } else if (errno != ENOENT)
log_error_errno(errno, "unable to move watches dir /run/udev/watch; old watches will not be restored: %m"); log_error_errno(errno, "unable to move watches dir /run/udev/watch; old watches will not be restored: %m");
}
} }
void udev_watch_begin(struct udev *udev, struct udev_device *dev) { void udev_watch_begin(struct udev *udev, struct udev_device *dev) {
@ -100,7 +99,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev) {
wd = inotify_add_watch(inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE); wd = inotify_add_watch(inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
if (wd < 0) { if (wd < 0) {
log_error_errno(errno, "inotify_add_watch(%d, %s, %o) failed: %m", log_error_errno(errno, "inotify_add_watch(%d, %s, %o) failed: %m",
inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE); inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
return; return;
} }