xfs
[Top] [All Lists]

[PATCH] xfs: ensure committed is initialized in xfs_trans_roll

To: xfs@xxxxxxxxxxx
Subject: [PATCH] xfs: ensure committed is initialized in xfs_trans_roll
From: Eric Sandeen <sandeen@xxxxxxxxxx>
Date: Thu, 10 Mar 2016 12:00:48 -0600
Cc: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.6.0
__xfs_trans_roll() can return without setting the
*committed argument; this was a problem for xfs_bmap_finish():

        int       committed;/* xact committed or not */
...
        error = __xfs_trans_roll(tp, ip, &committed);
        if (error) {
...
                if (committed) {

and we tested an uninitialized "committed" variable on the
error path.  No caller is preserving "committed" state across
calls to __xfs_trans_roll(), so just initialize committed inside
the function to avoid future errors like this.

Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index 748b16a..20c5366 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -1028,6 +1028,8 @@ __xfs_trans_roll(
        struct xfs_trans_res    tres;
        int                     error;
 
+       *committed = 0;
+
        /*
         * Ensure that the inode is always logged.
         */
@@ -1082,6 +1084,6 @@ xfs_trans_roll(
        struct xfs_trans        **tpp,
        struct xfs_inode        *dp)
 {
-       int                     committed = 0;
+       int                     committed;
        return __xfs_trans_roll(tpp, dp, &committed);
 }

<Prev in Thread] Current Thread [Next in Thread>