Skip to contentSkip to conversation

pNFS: Handle allocation errors correctly in objlayout_alloc_layout_hdr()

PATCH In review Trond Myklebust 2 participants 2 messages May 30, 2014 – Jun 1, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pNFS: Handle allocation errors correctly in objlayout_alloc_layout_hdr()

Return the NULL pointer when the allocation fails.

---
 fs/nfs/objlayout/objlayout.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/nfs/objlayout/objlayout.c +4 -4
index 2f955f671003..765d3f54e986 100644
@@ -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;
 }
Signature · 1 line
1.9.3
#1 lore raw
Quoted 18 lines · Trond Myklebust

Return the NULL pointer when the allocation fails.

---
 fs/nfs/objlayout/objlayout.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/nfs/objlayout/objlayout.c +0 -1
index 2f955f671003..765d3f54e986 100644
@@ -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) {

fs/nfs/objlayout/objlayout.c objlayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags) · line 62

Quoted 10 lines
fs/nfs/objlayout/objlayout.c +4 -3
-		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