diff mbox

[1/2] nfs/nfsd: return err directly while malloc failing

Message ID 1386322217-27436-1-git-send-email-rui.xiang@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Rui Xiang Dec. 6, 2013, 9:30 a.m. UTC
while nthreads malloc fails, return err value directory
without kfree.

And the same issue arises in nfs_lookup, so return res
directly without freeing fh and fattr.

Signed-off-by: Rui Xiang <rui.xiang@huawei.com>
---
 fs/nfs/dir.c     | 4 ++--
 fs/nfsd/nfsctl.c | 7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)

Comments

J. Bruce Fields Dec. 6, 2013, 3:36 p.m. UTC | #1
On Fri, Dec 06, 2013 at 05:30:16PM +0800, Rui Xiang wrote:
> while nthreads malloc fails, return err value directory
> without kfree.
> 
> And the same issue arises in nfs_lookup, so return res
> directly without freeing fh and fattr.
> 
> Signed-off-by: Rui Xiang <rui.xiang@huawei.com>
> ---
>  fs/nfs/dir.c     | 4 ++--
>  fs/nfsd/nfsctl.c | 7 ++++---
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
> index 812154a..2518865 100644
> --- a/fs/nfs/dir.c
> +++ b/fs/nfs/dir.c
> @@ -1278,7 +1278,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
>  
>  	res = ERR_PTR(-ENAMETOOLONG);
>  	if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
> -		goto out;
> +		return res;
>  
>  	/*
>  	 * If we're doing an exclusive create, optimize away the lookup
> @@ -1287,7 +1287,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
>  	if (nfs_is_exclusive_create(dir, flags)) {
>  		d_instantiate(dentry, NULL);
>  		res = NULL;
> -		goto out;
> +		return res;
>  	}
>  
>  	res = ERR_PTR(-ENOMEM);
> diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
> index 7f55517..3c5e748 100644
> --- a/fs/nfsd/nfsctl.c
> +++ b/fs/nfsd/nfsctl.c
> @@ -491,9 +491,10 @@ static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
>  	}
>  
>  	nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
> -	rv = -ENOMEM;
> -	if (nthreads == NULL)
> -		goto out_free;
> +	if (nthreads == NULL) {
> +		mutex_unlock(&nfsd_mutex);
> +		return -ENOENT;
> +	}
>  
>  	if (size > 0) {
>  		for (i = 0; i < npools; i++) {
> -- 

Looks fine.  Could you send this last chunk to me as a separate patch?

--b.

> 1.8.2.2
> 
> 
> --
> 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
--
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
Rui Xiang Dec. 9, 2013, 12:33 p.m. UTC | #2
On 2013/12/6 17:30, Rui Xiang wrote:
> while nthreads malloc fails, return err value directory
> without kfree.
> 
> And the same issue arises in nfs_lookup, so return res
> directly without freeing fh and fattr.
> 
> Signed-off-by: Rui Xiang <rui.xiang@huawei.com>
> ---
>  fs/nfs/dir.c     | 4 ++--
>  fs/nfsd/nfsctl.c | 7 ++++---
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
> index 812154a..2518865 100644
> --- a/fs/nfs/dir.c
> +++ b/fs/nfs/dir.c
> @@ -1278,7 +1278,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
>  
>  	res = ERR_PTR(-ENAMETOOLONG);
>  	if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
> -		goto out;
> +		return res;
>  
>  	/*
>  	 * If we're doing an exclusive create, optimize away the lookup
> @@ -1287,7 +1287,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
>  	if (nfs_is_exclusive_create(dir, flags)) {
>  		d_instantiate(dentry, NULL);
>  		res = NULL;
> -		goto out;
> +		return res;
>  	}
>  
>  	res = ERR_PTR(-ENOMEM);
Trond,  and what's your opinion on the chunk above?

Thanks
 Rui

> diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
> index 7f55517..3c5e748 100644
> --- a/fs/nfsd/nfsctl.c
> +++ b/fs/nfsd/nfsctl.c
> @@ -491,9 +491,10 @@ static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
>  	}
>  
>  	nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
> -	rv = -ENOMEM;
> -	if (nthreads == NULL)
> -		goto out_free;
> +	if (nthreads == NULL) {
> +		mutex_unlock(&nfsd_mutex);
> +		return -ENOENT;
> +	}
>  
>  	if (size > 0) {
>  		for (i = 0; i < npools; i++) {
> 


--
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
Trond Myklebust Dec. 10, 2013, 4:24 p.m. UTC | #3
On Mon, 2013-12-09 at 20:33 +0800, Rui Xiang wrote:
> On 2013/12/6 17:30, Rui Xiang wrote:
> > while nthreads malloc fails, return err value directory
> > without kfree.
> > 
> > And the same issue arises in nfs_lookup, so return res
> > directly without freeing fh and fattr.
> > 
> > Signed-off-by: Rui Xiang <rui.xiang@huawei.com>
> > ---
> >  fs/nfs/dir.c     | 4 ++--
> >  fs/nfsd/nfsctl.c | 7 ++++---
> >  2 files changed, 6 insertions(+), 5 deletions(-)
> > 
> > diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
> > index 812154a..2518865 100644
> > --- a/fs/nfs/dir.c
> > +++ b/fs/nfs/dir.c
> > @@ -1278,7 +1278,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
> >  
> >  	res = ERR_PTR(-ENAMETOOLONG);
> >  	if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
> > -		goto out;
> > +		return res;
> >  
> >  	/*
> >  	 * If we're doing an exclusive create, optimize away the lookup
> > @@ -1287,7 +1287,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
> >  	if (nfs_is_exclusive_create(dir, flags)) {
> >  		d_instantiate(dentry, NULL);
> >  		res = NULL;
> > -		goto out;
> > +		return res;
> >  	}
> >  
> >  	res = ERR_PTR(-ENOMEM);
> Trond,  and what's your opinion on the chunk above?

It's a minor optimisation but certainly not something that needs to be
pushed in before the next merge window.

Cheers
  Trond

--
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
diff mbox

Patch

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 812154a..2518865 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1278,7 +1278,7 @@  struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
 
 	res = ERR_PTR(-ENAMETOOLONG);
 	if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
-		goto out;
+		return res;
 
 	/*
 	 * If we're doing an exclusive create, optimize away the lookup
@@ -1287,7 +1287,7 @@  struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
 	if (nfs_is_exclusive_create(dir, flags)) {
 		d_instantiate(dentry, NULL);
 		res = NULL;
-		goto out;
+		return res;
 	}
 
 	res = ERR_PTR(-ENOMEM);
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 7f55517..3c5e748 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -491,9 +491,10 @@  static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
 	}
 
 	nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
-	rv = -ENOMEM;
-	if (nthreads == NULL)
-		goto out_free;
+	if (nthreads == NULL) {
+		mutex_unlock(&nfsd_mutex);
+		return -ENOENT;
+	}
 
 	if (size > 0) {
 		for (i = 0; i < npools; i++) {