diff mbox series

[6/8] xfs: use xfs_attr_sf_findname in xfs_attr_shortform_getvalue

Message ID 20231217170350.605812-7-hch@lst.de (mailing list archive)
State Superseded
Headers show
Series [1/8] xfs: make if_data a void pointer | expand

Commit Message

Christoph Hellwig Dec. 17, 2023, 5:03 p.m. UTC
xfs_attr_shortform_getvalue duplicates the logic in xfs_attr_sf_findname.
Use the helper instead.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/libxfs/xfs_attr_leaf.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

Comments

Darrick J. Wong Dec. 18, 2023, 10:37 p.m. UTC | #1
On Sun, Dec 17, 2023 at 06:03:48PM +0100, Christoph Hellwig wrote:
> xfs_attr_shortform_getvalue duplicates the logic in xfs_attr_sf_findname.
> Use the helper instead.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Nice cleanup!
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/libxfs/xfs_attr_leaf.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
> index 75c597805ffa8b..82e1830334160b 100644
> --- a/fs/xfs/libxfs/xfs_attr_leaf.c
> +++ b/fs/xfs/libxfs/xfs_attr_leaf.c
> @@ -848,23 +848,17 @@ int
>  xfs_attr_shortform_getvalue(
>  	struct xfs_da_args		*args)
>  {
> -	struct xfs_attr_shortform	*sf = args->dp->i_af.if_data;
>  	struct xfs_attr_sf_entry	*sfe;
> -	int				i;
>  
>  	ASSERT(args->dp->i_af.if_format == XFS_DINODE_FMT_LOCAL);
>  
>  	trace_xfs_attr_sf_lookup(args);
>  
> -	sfe = &sf->list[0];
> -	for (i = 0; i < sf->hdr.count;
> -				sfe = xfs_attr_sf_nextentry(sfe), i++) {
> -		if (xfs_attr_match(args, sfe->namelen, sfe->nameval,
> -				sfe->flags))
> -			return xfs_attr_copy_value(args,
> -				&sfe->nameval[args->namelen], sfe->valuelen);
> -	}
> -	return -ENOATTR;
> +	sfe = xfs_attr_sf_findname(args);
> +	if (!sfe)
> +		return -ENOATTR;
> +	return xfs_attr_copy_value(args, &sfe->nameval[args->namelen],
> +			sfe->valuelen);
>  }
>  
>  /* Convert from using the shortform to the leaf format. */
> -- 
> 2.39.2
> 
>
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
index 75c597805ffa8b..82e1830334160b 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -848,23 +848,17 @@  int
 xfs_attr_shortform_getvalue(
 	struct xfs_da_args		*args)
 {
-	struct xfs_attr_shortform	*sf = args->dp->i_af.if_data;
 	struct xfs_attr_sf_entry	*sfe;
-	int				i;
 
 	ASSERT(args->dp->i_af.if_format == XFS_DINODE_FMT_LOCAL);
 
 	trace_xfs_attr_sf_lookup(args);
 
-	sfe = &sf->list[0];
-	for (i = 0; i < sf->hdr.count;
-				sfe = xfs_attr_sf_nextentry(sfe), i++) {
-		if (xfs_attr_match(args, sfe->namelen, sfe->nameval,
-				sfe->flags))
-			return xfs_attr_copy_value(args,
-				&sfe->nameval[args->namelen], sfe->valuelen);
-	}
-	return -ENOATTR;
+	sfe = xfs_attr_sf_findname(args);
+	if (!sfe)
+		return -ENOATTR;
+	return xfs_attr_copy_value(args, &sfe->nameval[args->namelen],
+			sfe->valuelen);
 }
 
 /* Convert from using the shortform to the leaf format. */