[CRIU] [PATCH 2/7] mount: Add braces for safety sake
Pavel Emelyanov
xemul at parallels.com
Fri Sep 4 08:25:23 PDT 2015
On 09/03/2015 01:05 PM, Cyrill Gorcunov wrote:
Please, no :) Single statement if perfectly fine outside of braces.
The only exception I'm ready to merge is stuff like
if (a)
if (b)
foo;
else
bar;
-- Pavel
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
> mount.c | 39 ++++++++++++++++++++++++++-------------
> 1 file changed, 26 insertions(+), 13 deletions(-)
>
> diff --git a/mount.c b/mount.c
> index a4e272341ed2..b7185c1b5175 100644
> --- a/mount.c
> +++ b/mount.c
> @@ -52,9 +52,10 @@ static struct ext_mount *ext_mount_lookup(char *key)
> {
> struct ext_mount *em;
>
> - list_for_each_entry(em, &opts.ext_mounts, list)
> + list_for_each_entry(em, &opts.ext_mounts, list) {
> if (!strcmp(em->key, key))
> return em;
> + }
>
> return NULL;
> }
> @@ -184,9 +185,10 @@ struct mount_info *lookup_overlayfs(char *rpath, unsigned int st_dev,
> struct mount_info *m;
>
> /* If the mnt_id and device number match for some entry, no fixup is needed */
> - for (m = mntinfo; m != NULL; m = m->next)
> + for (m = mntinfo; m != NULL; m = m->next) {
> if (st_dev == m->s_dev && mnt_id == m->mnt_id)
> return NULL;
> + }
>
> return __lookup_overlayfs(mntinfo, rpath, st_dev, st_ino, mnt_id);
> }
> @@ -195,9 +197,10 @@ static struct mount_info *__lookup_mnt_id(struct mount_info *list, int id)
> {
> struct mount_info *m;
>
> - for (m = list; m != NULL; m = m->next)
> + for (m = list; m != NULL; m = m->next) {
> if (m->mnt_id == id)
> return m;
> + }
>
> return NULL;
> }
> @@ -211,9 +214,10 @@ struct mount_info *lookup_mnt_sdev(unsigned int s_dev)
> {
> struct mount_info *m;
>
> - for (m = mntinfo; m != NULL; m = m->next)
> + for (m = mntinfo; m != NULL; m = m->next) {
> if (m->s_dev == s_dev)
> return m;
> + }
>
> return NULL;
> }
> @@ -378,9 +382,10 @@ static int mnt_depth(struct mount_info *m)
> int depth = 0;
> char *c;
>
> - for (c = m->mountpoint; *c != '\0'; c++)
> + for (c = m->mountpoint; *c != '\0'; c++) {
> if (*c == '/')
> depth++;
> + }
>
> return depth;
> }
> @@ -457,9 +462,10 @@ static struct mount_info *get_widest_peer(struct mount_info *m)
> * Try to find a mount, which is wider or equal.
> * A is wider than B, if A->root is a subpath of B->root.
> */
> - list_for_each_entry(p, &m->mnt_share, mnt_share)
> + list_for_each_entry(p, &m->mnt_share, mnt_share) {
> if (issubpath(m->root, p->root))
> return p;
> + }
>
> return NULL;
> }
> @@ -623,11 +629,12 @@ static struct mount_info *find_fsroot_mount_for(struct mount_info *bm)
> {
> struct mount_info *sm;
>
> - list_for_each_entry(sm, &bm->mnt_bind, mnt_bind)
> + list_for_each_entry(sm, &bm->mnt_bind, mnt_bind) {
> if (fsroot_mounted(sm) ||
> (sm->parent == NULL &&
> strstartswith(bm->root, sm->root)))
> return sm;
> + }
>
> return NULL;
> }
> @@ -796,13 +803,14 @@ static struct ns_id *find_ext_ns_id(void)
> int pid = getpid();
> struct ns_id *ns;
>
> - for (ns = ns_ids; ns->next; ns = ns->next)
> + for (ns = ns_ids; ns->next; ns = ns->next) {
> if (ns->pid == pid && ns->nd == &mnt_ns_desc) {
> if (!ns->mnt.mntinfo_list &&
> !collect_mntinfo(ns, true))
> break;
> return ns;
> }
> + }
>
> pr_err("Failed to find criu pid's mount ns!");
> return NULL;
> @@ -1666,9 +1674,10 @@ static int dump_mnt_ns(struct ns_id *ns, struct mount_info *pms)
> if (!img)
> goto err;
>
> - for (pm = pms; pm && pm->nsid == ns; pm = pm->next)
> + for (pm = pms; pm && pm->nsid == ns; pm = pm->next) {
> if (dump_one_mountpoint(pm, img))
> goto err_i;
> + }
>
> ret = 0;
> err_i:
> @@ -2085,16 +2094,19 @@ static bool can_mount_now(struct mount_info *mi)
>
> if (mi->parent->shared_id == mi->shared_id) {
> int rlen = strlen(mi->root);
> - list_for_each_entry(n, &p->mnt_share, mnt_share)
> + list_for_each_entry(n, &p->mnt_share, mnt_share) {
> if (strlen(n->root) < rlen && !n->mounted)
> return false;
> + }
> } else {
> - list_for_each_entry(n, &p->mnt_share, mnt_share)
> + list_for_each_entry(n, &p->mnt_share, mnt_share) {
> if (!n->mounted)
> return false;
> - list_for_each_entry(n, &p->mnt_slave_list, mnt_slave)
> + }
> + list_for_each_entry(n, &p->mnt_slave_list, mnt_slave) {
> if (!n->mounted)
> return false;
> + }
> }
> }
>
> @@ -2462,13 +2474,14 @@ static struct mount_info *read_mnt_ns_img(void)
> if (nsid->nd != &mnt_ns_desc)
> continue;
>
> - if (nsid->id != root_item->ids->mnt_ns_id)
> + if (nsid->id != root_item->ids->mnt_ns_id) {
> /*
> * If we have more than one (root) namespace,
> * then we'll need the roots yard.
> */
> if (create_mnt_roots())
> return NULL;
> + }
>
> if (collect_mnt_from_image(&pms, nsid))
> return NULL;
>
More information about the CRIU
mailing list