Skip to contentSkip to conversation

Check for Null return from logfs_readpage_nolock in btree_write_block

PATCH In review Nicholas Krause 3 participants 3 messages Jun 16, 2014 – Jun 17, 2014 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Check for Null return from logfs_readpage_nolock in btree_write_block

---
 fs/logfs/readwrite.c | 2 ++
 1 file changed, 2 insertions(+)
fs/logfs/readwrite.c +2 -0
index 4814031..adb9233 100644
@@ -2210,6 +2210,8 @@ void btree_write_block(struct logfs_block *block)
 	page = logfs_get_write_page(inode, block->bix, block->level);
 
 	err = logfs_readpage_nolock(page);
+	if (!err)
+		return -ENOMEM;
 	BUG_ON(err);
 	BUG_ON(!PagePrivate(page));
 	BUG_ON(logfs_block(page) != block);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 10 lines · Nicholas Krause
---
 fs/logfs/readwrite.c | 2 ++
 1 file changed, 2 insertions(+)
fs/logfs/readwrite.c +0 -0
index 4814031..adb9233 100644

fs/logfs/readwrite.c void btree_write_block(struct logfs_block *block) · line 2217

Quoted 8 lines
fs/logfs/readwrite.c +2 -0
@@ -2210,6 +2210,8 @@ void btree_write_block(struct logfs_block *block)
 	page = logfs_get_write_page(inode, block->bix, block->level);
 
 	err = logfs_readpage_nolock(page);
+	if (!err)
+		return -ENOMEM;
 	BUG_ON(err);
 	BUG_ON(!PagePrivate(page));
 	BUG_ON(logfs_block(page) != block);

This function returns 0 on success, which you turn into error condition and return -ENOMEM.
But the function returns void, thus it cannot return the error. It does not allocate anything, thus -ENOMEM would not be appropriate in the first place.

Since the function returns error, nobody would check the condition in the first place.

Even if it was not void, it would either have to return the error or oops on BUG_ON(err).

Read the code more carefully and at least compile-test your changes. Instructions how to compile the kernel can be found here:
http://kernelnewbies.org/FAQ/KernelCompilation

I would also suggest letting the patch wait few hours and have another look before sending.

Cheers,

Signature · 1 line
Mateusz Guzik

A message that is not in the archive (sent off-list or not yet received): CAPDOMVgDUgfr9oqGmQ2a6u9Jm0eyBP=RP8EbCuHmnu-MRb+=+w@mail.gmail.com

#3 lore raw
Quoted 5 lines · Nick Krause

You are right about the compile errors it compiles but with warning. I am curious since the function is void how do you want me to give the error back to logfs and in turn the other subsystems of the kernel.

My first question would be: What is the problem? If there is no problem, don't try to fix it. If there is a problem, your fix should contain a decent description of the problem as part of the commit message. Even if the patch itself ends up being bad, having a good problem description with a first stab at a fix serves as a useful bug report.

Jörn

--
Was there any time in human history where democratic forms continued when the citizens could not credibly defend their rights? -- Daniel Suarez