Commit fc0d1923 authored by Dmitry Antipov's avatar Dmitry Antipov Committed by Carlos Maiolino
Browse files

xfs: scrub: use kstrdup_const() for metapath scan setups



Except 'xchk_setup_metapath_rtginode()' case, 'path' argument of
'xchk_setup_metapath_scan()' is a compile-time constant. So it may
be reasonable to use 'kstrdup_const()' / 'kree_const()' to manage
'path' field of 'struct xchk_metapath' in attempt to reuse .rodata
instance rather than making a copy. Compile tested only.

Signed-off-by: default avatarDmitry Antipov <dmantipov@yandex.ru>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarCarlos Maiolino <cem@kernel.org>
parent 6ef2175f
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ xchk_metapath_cleanup(

	if (mpath->dp_ilock_flags)
		xfs_iunlock(mpath->dp, mpath->dp_ilock_flags);
	kfree(mpath->path);
	kfree_const(mpath->path);
}

/* Set up a metadir path scan.  @path must be dynamically allocated. */
@@ -98,13 +98,13 @@ xchk_setup_metapath_scan(

	error = xchk_install_live_inode(sc, ip);
	if (error) {
		kfree(path);
		kfree_const(path);
		return error;
	}

	mpath = kzalloc(sizeof(struct xchk_metapath), XCHK_GFP_FLAGS);
	if (!mpath) {
		kfree(path);
		kfree_const(path);
		return -ENOMEM;
	}

@@ -132,7 +132,7 @@ xchk_setup_metapath_rtdir(
		return -ENOENT;

	return xchk_setup_metapath_scan(sc, sc->mp->m_metadirip,
			kasprintf(GFP_KERNEL, "rtgroups"), sc->mp->m_rtdirip);
			kstrdup_const("rtgroups", GFP_KERNEL), sc->mp->m_rtdirip);
}

/* Scan a rtgroup inode under the /rtgroups directory. */
@@ -179,7 +179,7 @@ xchk_setup_metapath_quotadir(
		return -ENOENT;

	return xchk_setup_metapath_scan(sc, sc->mp->m_metadirip,
			kstrdup("quota", GFP_KERNEL), qi->qi_dirip);
			kstrdup_const("quota", GFP_KERNEL), qi->qi_dirip);
}

/* Scan a quota inode under the /quota directory. */
@@ -212,7 +212,7 @@ xchk_setup_metapath_dqinode(
		return -ENOENT;

	return xchk_setup_metapath_scan(sc, qi->qi_dirip,
			kstrdup(xfs_dqinode_path(type), GFP_KERNEL), ip);
			kstrdup_const(xfs_dqinode_path(type), GFP_KERNEL), ip);
}
#else
# define xchk_setup_metapath_quotadir(...)	(-ENOENT)