[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <742068374.13487420.1406313769169.JavaMail.zimbra@redhat.com>
Date: Fri, 25 Jul 2014 14:42:49 -0400 (EDT)
From: Bob Peterson <rpeterso@...hat.com>
To: Abhi Das <adas@...hat.com>
Cc: linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
cluster-devel@...hat.com
Subject: Re: [Cluster-devel] [RFC PATCH 3/5] gfs2: Add a dynamic buffer
backed by a vector of pages
----- Original Message -----
> +static int vp_alloc_pages(struct vp_ctx *vpx, int start, int end)
> +{
> + int i;
> +
> + for (i = start; i < end; i++) {
> + vpx->vp_pages[i] = alloc_page(GFP_KERNEL | GFP_NOFS);
> + if (vpx->vp_pages[i] == NULL)
> + goto free;
> + }
> + return 0;
> +free:
> + for (i = start; i < end; i++)
> + if (vpx->vp_pages[i]) {
> + __free_page(vpx->vp_pages[i]);
> + vpx->vp_pages[i] = NULL;
> + }
> + return -ENOMEM;
> +}
I'm concerned that if we have a value for vpx->vp_pages[i] that is
nonzero (uninitialized) _after_ an element in which we couldn't
allocate a page, we could try to free the nonzero value. For that
reason, I always prefer to do something like this instead:
free:
while (i > start) {
i--;
__free_page(vpx->vp_pages[i]);
vpx->vp_pages[i] = NULL;
}
return -ENOMEM;
(snip)
> +struct vp_ctx* vp_get_vpx(struct vbuf *vb)
> +{
> + struct vp_ctx *vpx = NULL;
> +
> + if (!vb || !vb->v_opaque)
> + goto out;
> +
> + vpx = vb->v_opaque;
> + if (vpx->vp_magic != VP_MAGIC) {
> + vpx = NULL;
> + goto out;
This goto is unnecessary, and if you eliminate it, you don't need the brackets.
> + }
> +out:
> + return vpx;
> +}
Regards,
Bob Peterson
Red Hat File Systems
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists