]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfs: allocate m_errortag early
authorChristoph Hellwig <hch@lst.de>
Fri, 30 Jan 2026 05:19:17 +0000 (06:19 +0100)
committerCarlos Maiolino <cem@kernel.org>
Fri, 30 Jan 2026 09:41:42 +0000 (10:41 +0100)
Ensure the mount structure always has a valid m_errortag for debug
builds.  This removes the NULL checking from the runtime code, and
prepares for allowing to set errortags from mount.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/xfs_error.c
fs/xfs/xfs_super.c

index 873f2d1a134c265937493949cec4273ac0175313..dfa4abf9fd1a9954edb71130b43881a169dc90b6 100644 (file)
@@ -114,18 +114,8 @@ int
 xfs_errortag_init(
        struct xfs_mount        *mp)
 {
-       int ret;
-
-       mp->m_errortag = kzalloc(sizeof(unsigned int) * XFS_ERRTAG_MAX,
-                               GFP_KERNEL | __GFP_RETRY_MAYFAIL);
-       if (!mp->m_errortag)
-               return -ENOMEM;
-
-       ret = xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
+       return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
                                &mp->m_kobj, "errortag");
-       if (ret)
-               kfree(mp->m_errortag);
-       return ret;
 }
 
 void
@@ -133,7 +123,6 @@ xfs_errortag_del(
        struct xfs_mount        *mp)
 {
        xfs_sysfs_del(&mp->m_errortag_kobj);
-       kfree(mp->m_errortag);
 }
 
 static bool
@@ -154,8 +143,6 @@ xfs_errortag_enabled(
        struct xfs_mount        *mp,
        unsigned int            tag)
 {
-       if (!mp->m_errortag)
-               return false;
        if (!xfs_errortag_valid(tag))
                return false;
 
@@ -171,17 +158,6 @@ xfs_errortag_test(
 {
        unsigned int            randfactor;
 
-       /*
-        * To be able to use error injection anywhere, we need to ensure error
-        * injection mechanism is already initialized.
-        *
-        * Code paths like I/O completion can be called before the
-        * initialization is complete, but be able to inject errors in such
-        * places is still useful.
-        */
-       if (!mp->m_errortag)
-               return false;
-
        if (!xfs_errortag_valid(error_tag))
                return false;
 
index b6a92f027d645c204e367accb89971abbeaf1447..5029bf63b87d460d0f88872acb4539b23dc082c9 100644 (file)
@@ -40,6 +40,7 @@
 #include "xfs_defer.h"
 #include "xfs_attr_item.h"
 #include "xfs_xattr.h"
+#include "xfs_errortag.h"
 #include "xfs_iunlink_item.h"
 #include "xfs_dahash_test.h"
 #include "xfs_rtbitmap.h"
@@ -824,6 +825,9 @@ xfs_mount_free(
        debugfs_remove(mp->m_debugfs);
        kfree(mp->m_rtname);
        kfree(mp->m_logname);
+#ifdef DEBUG
+       kfree(mp->m_errortag);
+#endif
        kfree(mp);
 }
 
@@ -2266,6 +2270,14 @@ xfs_init_fs_context(
        mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
        if (!mp)
                return -ENOMEM;
+#ifdef DEBUG
+       mp->m_errortag = kcalloc(XFS_ERRTAG_MAX, sizeof(*mp->m_errortag),
+                       GFP_KERNEL);
+       if (!mp->m_errortag) {
+               kfree(mp);
+               return -ENOMEM;
+       }
+#endif
 
        spin_lock_init(&mp->m_sb_lock);
        for (i = 0; i < XG_TYPE_MAX; i++)