All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Dean Hildebrand <seattleplus@gmail.com>
Cc: linux-nfs@vger.kernel.org, Dean Hildebrand <dhildeb@us.ibm.com>
Subject: Re: [PATCH 2/2] NFS: Cleanup decode_attr_fs_locations function.
Date: Fri, 17 Oct 2008 14:55:36 -0400	[thread overview]
Message-ID: <20081017185536.GC13791@fieldses.org> (raw)
In-Reply-To: <1224267468-775-2-git-send-email-dhildeb@us.ibm.com>

On Fri, Oct 17, 2008 at 11:17:48AM -0700, Dean Hildebrand wrote:
> a) Reduce nesting level of loops.
> b) Use correct data types.
> c) Use nloc and nserv instead of n and m variable names.
> d) Try to clean up formatting of debugging statements.
> e) Move while loops to for loops.

Does this also fix a possible infinite loop in the inner loop?

--b.

> 
> Signed-off-by: Dean Hildebrand <dhildeb@us.ibm.com>
> ---
>  fs/nfs/nfs4xdr.c |   71 +++++++++++++++++++++++++++++-------------------------
>  1 files changed, 38 insertions(+), 33 deletions(-)
> 
> diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
> index 5e59481..0e78fbd 100644
> --- a/fs/nfs/nfs4xdr.c
> +++ b/fs/nfs/nfs4xdr.c
> @@ -2560,7 +2560,8 @@ out_eio:
>  
>  static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
>  {
> -	int n;
> +	u32 nloc;
> +	unsigned int i;
>  	__be32 *p;
>  	int status = -EIO;
>  
> @@ -2574,53 +2575,57 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
>  	if (unlikely(status != 0))
>  		goto out;
>  	READ_BUF(4);
> -	READ32(n);
> -	if (n <= 0)
> +	READ32(nloc);
> +	if (nloc <= 0)
>  		goto out_eio;
> -
> -	if (n > NFS4_FS_LOCATIONS_MAXENTRIES) {
> -		dprintk("%s: using first %u of %d fs locations\n",
> -			__func__, NFS4_FS_LOCATIONS_MAXENTRIES, n);
> -		n = NFS4_FS_LOCATIONS_MAXENTRIES;
> +	if (nloc > NFS4_FS_LOCATIONS_MAXENTRIES) {
> +		dprintk("%s: using first %u of %u fs locations\n",
> +			__func__, NFS4_FS_LOCATIONS_MAXENTRIES, nloc);
> +		nloc = NFS4_FS_LOCATIONS_MAXENTRIES;
>  	} else {
> -		dprintk("%s: using %d fs locations\n",
> -			__func__, n);
> +		dprintk("%s: using %u fs locations\n",
> +			__func__, nloc);
>  	}
>  
>  	res->nlocations = 0;
> -	while (res->nlocations < n) {
> -		u32 m;
> -		struct nfs4_fs_location *loc = &res->locations[res->nlocations];
> +	for (i = 0; i < nloc; i++) {
> +		u32 nserv;
> +		unsigned int totalserv, j;
> +		struct nfs4_fs_location *loc = &res->locations[i];
>  
>  		READ_BUF(4);
> -		READ32(m);
> +		READ32(nserv);
> +
> +		totalserv = nserv;
> +		if (nserv >  NFS4_FS_LOCATION_MAXSERVERS) {
> +			dprintk("%s: Using first %u of %u servers "
> +				"returned for location %u\n",
> +				__func__, NFS4_FS_LOCATION_MAXSERVERS,
> +				nserv, i);
> +			nserv = NFS4_FS_LOCATION_MAXSERVERS;
> +		}
>  
>  		loc->nservers = 0;
> -		dprintk("%s: servers ", __func__);
> -		while (loc->nservers < m) {
> +		dprintk("%s: Servers ", __func__);
> +		for (j = 0; j < nserv; j++) {
>  			struct nfs4_string *server = &loc->servers[loc->nservers];
>  			status = decode_opaque_inline(xdr, &server->len, &server->data);
>  			if (unlikely(status != 0))
>  				goto out_eio;
>  			dprintk("%s ", server->data);
> -			if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
> -				loc->nservers++;
> -			else {
> -				unsigned int i;
> -				dprintk("%s: using first %u of %u servers "
> -					"returned for location %u\n",
> -						__func__,
> -						NFS4_FS_LOCATION_MAXSERVERS,
> -						m, res->nlocations);
> -				for (i = loc->nservers; i < m; i++) {
> -					unsigned int len;
> -					char *data;
> -					status = decode_opaque_inline(xdr, &len, &data);
> -					if (unlikely(status != 0))
> -						goto out_eio;
> -				}
> -			}
> +			loc->nservers++;
> +		}
> +		dprintk("\n");
> +
> +		/* Decode and ignore overflow servers */
> +		for (j = loc->nservers; j < totalserv; j++) {
> +			unsigned int len;
> +			char *data;
> +			status = decode_opaque_inline(xdr, &len, &data);
> +			if (unlikely(status != 0))
> +				goto out_eio;
>  		}
> +
>  		status = decode_pathname(xdr, &loc->rootpath);
>  		if (unlikely(status != 0))
>  			goto out_eio;
> -- 
> 1.5.3.3
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2008-10-17 18:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-17 18:17 [PATCH 1/2] NFS:Prevent infinite loop in decode_attr_fs_locations Dean Hildebrand
2008-10-17 18:17 ` [PATCH 2/2] NFS: Cleanup decode_attr_fs_locations function Dean Hildebrand
2008-10-17 18:55   ` J. Bruce Fields [this message]
2008-10-17 22:01     ` Dean Hildebrand
2008-10-17 18:53 ` [PATCH 1/2] NFS:Prevent infinite loop in decode_attr_fs_locations J. Bruce Fields
  -- strict thread matches above, loose matches on Subject: below --
2008-10-17 22:52 Dean Hildebrand
2008-10-17 22:52 ` [PATCH 2/2] NFS: Cleanup decode_attr_fs_locations function Dean Hildebrand
2008-10-19 10:38   ` Benny Halevy
2008-10-24 17:09     ` Dean Hildebrand
2008-10-28 17:32 Dean Hildebrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081017185536.GC13791@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=dhildeb@us.ibm.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=seattleplus@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.