[ext4-next] ext4: ensure error return ret is zero on successful return

Message ID 20170623145840.26779-1-colin.king@canonical.com
State New
Headers show

Commit Message

Colin Ian King June 23, 2017, 2:58 p.m.
From: Colin Ian King <colin.king@canonical.com>

The error return ret is not set on a successful return path and
so it returns a garbage value. Ensure it is is set to zero on
a successful return.

Detected by CoverityScan, CID#1446616 ("Uninitialized scalar variable")

Fixes: 3499c0fb822d ("quota: add get_inode_usage callback to transfer multi-inode charges")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/ext4/xattr.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Tahsin Erdogan June 23, 2017, 5:04 p.m. | #1
On Fri, Jun 23, 2017 at 7:58 AM, Colin King <colin.king@canonical.com> wrote:
> The error return ret is not set on a successful return path and
> so it returns a garbage value. Ensure it is is set to zero on
> a successful return.
Thanks for catching this bug!

Reviewed-by: Tahsin Erdogan <tahsin@google.com>
Theodore Ts'o July 6, 2017, 7:28 p.m. | #2
On Fri, Jun 23, 2017 at 03:58:40PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The error return ret is not set on a successful return path and
> so it returns a garbage value. Ensure it is is set to zero on
> a successful return.
> 
> Detected by CoverityScan, CID#1446616 ("Uninitialized scalar variable")
> 
> Fixes: 3499c0fb822d ("quota: add get_inode_usage callback to transfer multi-inode charges")
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Thanks, I've folded this into the "quota: add get_inode_usage callback
to transfer multi-inode charges" with credit for your providing the
fix.

					- Ted

Patch

diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index ce12c3fb7e59..f454b2709b5a 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -794,6 +794,7 @@  int ext4_get_inode_usage(struct inode *inode, qsize_t *usage)
 				ea_inode_refs++;
 	}
 	*usage = ea_inode_refs + 1;
+	ret = 0;
 out:
 	brelse(iloc.bh);
 	brelse(bh);