Linux XFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] xfs: scrub: use kstrdup_const() for metapath scan setups
@ 2025-09-18 11:14 Dmitry Antipov
  2025-09-18 19:12 ` Darrick J. Wong
  2025-09-22 12:41 ` Carlos Maiolino
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Antipov @ 2025-09-18 11:14 UTC (permalink / raw)
  To: Carlos Maiolino; +Cc: Darrick J . Wong, linux-xfs, Dmitry Antipov

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: Dmitry Antipov <dmantipov@yandex.ru>
---
 fs/xfs/scrub/metapath.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/xfs/scrub/metapath.c b/fs/xfs/scrub/metapath.c
index 14939d7de349..378ec7c8d38e 100644
--- a/fs/xfs/scrub/metapath.c
+++ b/fs/xfs/scrub/metapath.c
@@ -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)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] xfs: scrub: use kstrdup_const() for metapath scan setups
  2025-09-18 11:14 [PATCH] xfs: scrub: use kstrdup_const() for metapath scan setups Dmitry Antipov
@ 2025-09-18 19:12 ` Darrick J. Wong
  2025-09-22 12:41 ` Carlos Maiolino
  1 sibling, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2025-09-18 19:12 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: Carlos Maiolino, linux-xfs

On Thu, Sep 18, 2025 at 02:14:03PM +0300, Dmitry Antipov wrote:
> 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: Dmitry Antipov <dmantipov@yandex.ru>

I guess that works...
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  fs/xfs/scrub/metapath.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/xfs/scrub/metapath.c b/fs/xfs/scrub/metapath.c
> index 14939d7de349..378ec7c8d38e 100644
> --- a/fs/xfs/scrub/metapath.c
> +++ b/fs/xfs/scrub/metapath.c
> @@ -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)
> -- 
> 2.51.0
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xfs: scrub: use kstrdup_const() for metapath scan setups
  2025-09-18 11:14 [PATCH] xfs: scrub: use kstrdup_const() for metapath scan setups Dmitry Antipov
  2025-09-18 19:12 ` Darrick J. Wong
@ 2025-09-22 12:41 ` Carlos Maiolino
  1 sibling, 0 replies; 3+ messages in thread
From: Carlos Maiolino @ 2025-09-22 12:41 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: Darrick J . Wong, linux-xfs

On Thu, 18 Sep 2025 14:14:03 +0300, Dmitry Antipov wrote:
> 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.
> 
> 
> [...]

Applied to for-next, thanks!

[1/1] xfs: scrub: use kstrdup_const() for metapath scan setups
      commit: fc0d192303bd385ac24dc52eb31ceb6ca7e027d0

Best regards,
-- 
Carlos Maiolino <cem@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-22 12:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18 11:14 [PATCH] xfs: scrub: use kstrdup_const() for metapath scan setups Dmitry Antipov
2025-09-18 19:12 ` Darrick J. Wong
2025-09-22 12:41 ` Carlos Maiolino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox