From: Christoph Hellwig Date: Fri, 30 Jan 2026 05:19:17 +0000 (+0100) Subject: xfs: allocate m_errortag early X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=394969e2f9d11427ce493e171949958122dc11ee;p=thirdparty%2Flinux.git xfs: allocate m_errortag early 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 Reviewed-by: Hans Holmberg Reviewed-by: Carlos Maiolino Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 873f2d1a134c2..dfa4abf9fd1a9 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -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; diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index b6a92f027d645..5029bf63b87d4 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -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++)