2014-05-30 00:29:31

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH] pNFS: Handle allocation errors correctly in objlayout_alloc_layout_hdr()

Return the NULL pointer when the allocation fails.

Cc: Boaz Harrosh <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/objlayout/objlayout.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/objlayout/objlayout.c b/fs/nfs/objlayout/objlayout.c
index 2f955f671003..765d3f54e986 100644
--- a/fs/nfs/objlayout/objlayout.c
+++ b/fs/nfs/objlayout/objlayout.c
@@ -53,10 +53,10 @@ objlayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
struct objlayout *objlay;

objlay = kzalloc(sizeof(struct objlayout), gfp_flags);
- if (objlay) {
- spin_lock_init(&objlay->lock);
- INIT_LIST_HEAD(&objlay->err_list);
- }
+ if (!objlay)
+ return NULL;
+ spin_lock_init(&objlay->lock);
+ INIT_LIST_HEAD(&objlay->err_list);
dprintk("%s: Return %p\n", __func__, objlay);
return &objlay->pnfs_layout;
}
--
1.9.3



2014-06-01 09:10:19

by Boaz Harrosh

[permalink] [raw]
Subject: Re: [PATCH] pNFS: Handle allocation errors correctly in objlayout_alloc_layout_hdr()

On 05/30/2014 03:29 AM, Trond Myklebust wrote:
> Return the NULL pointer when the allocation fails.
>
> Cc: Boaz Harrosh <[email protected]>
> Signed-off-by: Trond Myklebust <[email protected]>
> ---
> fs/nfs/objlayout/objlayout.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/nfs/objlayout/objlayout.c b/fs/nfs/objlayout/objlayout.c
> index 2f955f671003..765d3f54e986 100644
> --- a/fs/nfs/objlayout/objlayout.c
> +++ b/fs/nfs/objlayout/objlayout.c
> @@ -53,10 +53,10 @@ objlayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
> struct objlayout *objlay;
>
> objlay = kzalloc(sizeof(struct objlayout), gfp_flags);
> - if (objlay) {
> - spin_lock_init(&objlay->lock);
> - INIT_LIST_HEAD(&objlay->err_list);
> - }
> + if (!objlay)
> + return NULL;
> + spin_lock_init(&objlay->lock);
> + INIT_LIST_HEAD(&objlay->err_list);
> dprintk("%s: Return %p\n", __func__, objlay);
> return &objlay->pnfs_layout;
> }
>

Thanks! ACK

BTW it was not a bug. &NULL->pnfs_layout will return 0 because it is at offset 0.
Which explains why it works.

Thanks again, good catch
Boaz