Re: [Cluster-devel] [RFC PATCH 3/5] gfs2: Add a dynamic buffer backed by a vector of pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----- 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-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux