public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/nfsd/export.c: Adjust error handling code involving auth_domain_put
@ 2008-07-25 20:08 Julia Lawall
  2008-07-30 17:24 ` J. Bruce Fields
  0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2008-07-25 20:08 UTC (permalink / raw)
  To: bfields, neilb, linux-nfs, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

Once clp is assigned, it never becomes NULL, so we can make a label for it
in the error handling code.  Because the call to path_lookup follows the
call to auth_domain_find, its error handling code should jump to this new
label.

The semantic match that finds this problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@r@
expression x,E;
statement S;
position p1,p2,p3;
@@

(
if ((x = auth_domain_find@p1(...)) == NULL || ...) S
|
x = auth_domain_find@p1(...)
... when != x
if (x == NULL || ...) S
)
<...
if@p3 (...) { ... when != auth_domain_put(x)
                  when != if (x) { ... auth_domain_put(x); ...}
    return@p2 ...;
}
...>
(
return x;
|
return 0;
|
x = E
|
E = x
|
auth_domain_put(x)
)

@exists@
position r.p1,r.p2,r.p3;
expression x;
int ret != 0;
statement S;
@@

* x = auth_domain_find@p1(...)
  <...
* if@p3 (...)
  S
  ...>
* return@p2 \(NULL\|ret\);
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 fs/nfsd/export.c              |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 33bfcf0..9dc036f 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -1023,7 +1023,7 @@ exp_export(struct nfsctl_export *nxp)
 	/* Look up the dentry */
 	err = path_lookup(nxp->ex_path, 0, &nd);
 	if (err)
-		goto out_unlock;
+		goto out_put_clp;
 	err = -EINVAL;
 
 	exp = exp_get_by_name(clp, nd.path.mnt, nd.path.dentry, NULL);
@@ -1090,9 +1090,9 @@ finish:
 		exp_put(exp);
 	if (fsid_key && !IS_ERR(fsid_key))
 		cache_put(&fsid_key->h, &svc_expkey_cache);
-	if (clp)
-		auth_domain_put(clp);
 	path_put(&nd.path);
+out_put_clp:
+	auth_domain_put(clp);
 out_unlock:
 	exp_writeunlock();
 out:

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs/nfsd/export.c: Adjust error handling code involving auth_domain_put
  2008-07-25 20:08 [PATCH] fs/nfsd/export.c: Adjust error handling code involving auth_domain_put Julia Lawall
@ 2008-07-30 17:24 ` J. Bruce Fields
  0 siblings, 0 replies; 2+ messages in thread
From: J. Bruce Fields @ 2008-07-30 17:24 UTC (permalink / raw)
  To: Julia Lawall; +Cc: neilb, linux-nfs, linux-kernel, kernel-janitors

On Fri, Jul 25, 2008 at 10:08:09PM +0200, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> Once clp is assigned, it never becomes NULL, so we can make a label for it
> in the error handling code.  Because the call to path_lookup follows the
> call to auth_domain_find, its error handling code should jump to this new
> label.

Yes, that looks correct to me; thanks!  Applied.--b.

> 
> The semantic match that finds this problem is as follows:
> (http://www.emn.fr/x-info/coccinelle/)
> 
> // <smpl>
> @r@
> expression x,E;
> statement S;
> position p1,p2,p3;
> @@
> 
> (
> if ((x = auth_domain_find@p1(...)) == NULL || ...) S
> |
> x = auth_domain_find@p1(...)
> ... when != x
> if (x == NULL || ...) S
> )
> <...
> if@p3 (...) { ... when != auth_domain_put(x)
>                   when != if (x) { ... auth_domain_put(x); ...}
>     return@p2 ...;
> }
> ...>
> (
> return x;
> |
> return 0;
> |
> x = E
> |
> E = x
> |
> auth_domain_put(x)
> )
> 
> @exists@
> position r.p1,r.p2,r.p3;
> expression x;
> int ret != 0;
> statement S;
> @@
> 
> * x = auth_domain_find@p1(...)
>   <...
> * if@p3 (...)
>   S
>   ...>
> * return@p2 \(NULL\|ret\);
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>
> 
> ---
>  fs/nfsd/export.c              |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
> index 33bfcf0..9dc036f 100644
> --- a/fs/nfsd/export.c
> +++ b/fs/nfsd/export.c
> @@ -1023,7 +1023,7 @@ exp_export(struct nfsctl_export *nxp)
>  	/* Look up the dentry */
>  	err = path_lookup(nxp->ex_path, 0, &nd);
>  	if (err)
> -		goto out_unlock;
> +		goto out_put_clp;
>  	err = -EINVAL;
>  
>  	exp = exp_get_by_name(clp, nd.path.mnt, nd.path.dentry, NULL);
> @@ -1090,9 +1090,9 @@ finish:
>  		exp_put(exp);
>  	if (fsid_key && !IS_ERR(fsid_key))
>  		cache_put(&fsid_key->h, &svc_expkey_cache);
> -	if (clp)
> -		auth_domain_put(clp);
>  	path_put(&nd.path);
> +out_put_clp:
> +	auth_domain_put(clp);
>  out_unlock:
>  	exp_writeunlock();
>  out:

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-07-30 17:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-25 20:08 [PATCH] fs/nfsd/export.c: Adjust error handling code involving auth_domain_put Julia Lawall
2008-07-30 17:24 ` J. Bruce Fields

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox