xfs: Add error handling for xfs_reflink_cancel_cow_range
authorWentao Liang <vulab@iscas.ac.cn>
Fri, 24 Jan 2025 03:45:09 +0000 (11:45 +0800)
committerCarlos Maiolino <cem@kernel.org>
Mon, 27 Jan 2025 10:42:48 +0000 (11:42 +0100)
In xfs_inactive(), xfs_reflink_cancel_cow_range() is called
without error handling, risking unnoticed failures and
inconsistent behavior compared to other parts of the code.

Fix this issue by adding an error handling for the
xfs_reflink_cancel_cow_range(), improving code robustness.

Fixes: 6231848c3aa5 ("xfs: check for cow blocks before trying to clear them")
Cc: stable@vger.kernel.org # v4.17
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/xfs_inode.c

index c95fe1b1de4e6f3dc2651cd68804e1c14ff49447..b1f9f156ec8883c943b0372c4b1c83793abdfe87 100644 (file)
@@ -1404,8 +1404,11 @@ xfs_inactive(
                goto out;
 
        /* Try to clean out the cow blocks if there are any. */
-       if (xfs_inode_has_cow_data(ip))
-               xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF, true);
+       if (xfs_inode_has_cow_data(ip)) {
+               error = xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF, true);
+               if (error)
+                       goto out;
+       }
 
        if (VFS_I(ip)->i_nlink != 0) {
                /*