diff mbox series

[v2,2/3] xfs_db: add helper for flist_find_type for clearer field matching

Message ID 20240417125937.917910-3-aalbersh@redhat.com (mailing list archive)
State Superseded, archived
Headers show
Series Refactoring and error handling from Coverity scan fixes | expand

Commit Message

Andrey Albershteyn April 17, 2024, 12:59 p.m. UTC
Make flist_find_type() more readable by unloading field type
matching to the helper.

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
 db/flist.c | 60 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 38 insertions(+), 22 deletions(-)

Comments

Darrick J. Wong April 17, 2024, 3:20 p.m. UTC | #1
On Wed, Apr 17, 2024 at 02:59:36PM +0200, Andrey Albershteyn wrote:
> Make flist_find_type() more readable by unloading field type
> matching to the helper.
> 
> Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>

Looks good now,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  db/flist.c | 60 ++++++++++++++++++++++++++++++++++--------------------
>  1 file changed, 38 insertions(+), 22 deletions(-)
> 
> diff --git a/db/flist.c b/db/flist.c
> index 0a6cc5fcee43..ab0a0f133804 100644
> --- a/db/flist.c
> +++ b/db/flist.c
> @@ -400,6 +400,40 @@ flist_split(
>  	return v;
>  }
>  
> +static flist_t *
> +flist_field_match(
> +	const field_t		*field,
> +	fldt_t			type,
> +	void			*obj,
> +	int			startoff)
> +{
> +	flist_t			*fl;
> +	int			count;
> +	const ftattr_t		*fa;
> +	flist_t			*nfl;
> +
> +	fl = flist_make(field->name);
> +	fl->fld = field;
> +	if (field->ftyp == type)
> +		return fl;
> +	count = fcount(field, obj, startoff);
> +	if (!count)
> +		goto out;
> +	fa = &ftattrtab[field->ftyp];
> +	if (!fa->subfld)
> +		goto out;
> +
> +	nfl = flist_find_ftyp(fa->subfld, type, obj, startoff);
> +	if (nfl) {
> +		fl->child = nfl;
> +		return fl;
> +	}
> +
> +out:
> +	flist_free(fl);
> +	return NULL;
> +}
> +
>  /*
>   * Given a set of fields, scan for a field of the given type.
>   * Return an flist leading to the first found field
> @@ -413,33 +447,15 @@ flist_find_ftyp(
>  	void		*obj,
>  	int		startoff)
>  {
> -	flist_t	*fl;
>  	const field_t	*f;
> -	int		count;
> -	const ftattr_t  *fa;
> +	flist_t		*fl;
>  
>  	for (f = fields; f->name; f++) {
> -		fl = flist_make(f->name);
> -		fl->fld = f;
> -		if (f->ftyp == type)
> +		fl = flist_field_match(f, type, obj, startoff);
> +		if (fl)
>  			return fl;
> -		count = fcount(f, obj, startoff);
> -		if (!count) {
> -			flist_free(fl);
> -			continue;
> -		}
> -		fa = &ftattrtab[f->ftyp];
> -		if (fa->subfld) {
> -			flist_t *nfl;
> -
> -			nfl = flist_find_ftyp(fa->subfld, type, obj, startoff);
> -			if (nfl) {
> -				fl->child = nfl;
> -				return fl;
> -			}
> -		}
> -		flist_free(fl);
>  	}
> +
>  	return NULL;
>  }
>  
> -- 
> 2.42.0
> 
>
Christoph Hellwig April 17, 2024, 3:22 p.m. UTC | #2
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/db/flist.c b/db/flist.c
index 0a6cc5fcee43..ab0a0f133804 100644
--- a/db/flist.c
+++ b/db/flist.c
@@ -400,6 +400,40 @@  flist_split(
 	return v;
 }
 
+static flist_t *
+flist_field_match(
+	const field_t		*field,
+	fldt_t			type,
+	void			*obj,
+	int			startoff)
+{
+	flist_t			*fl;
+	int			count;
+	const ftattr_t		*fa;
+	flist_t			*nfl;
+
+	fl = flist_make(field->name);
+	fl->fld = field;
+	if (field->ftyp == type)
+		return fl;
+	count = fcount(field, obj, startoff);
+	if (!count)
+		goto out;
+	fa = &ftattrtab[field->ftyp];
+	if (!fa->subfld)
+		goto out;
+
+	nfl = flist_find_ftyp(fa->subfld, type, obj, startoff);
+	if (nfl) {
+		fl->child = nfl;
+		return fl;
+	}
+
+out:
+	flist_free(fl);
+	return NULL;
+}
+
 /*
  * Given a set of fields, scan for a field of the given type.
  * Return an flist leading to the first found field
@@ -413,33 +447,15 @@  flist_find_ftyp(
 	void		*obj,
 	int		startoff)
 {
-	flist_t	*fl;
 	const field_t	*f;
-	int		count;
-	const ftattr_t  *fa;
+	flist_t		*fl;
 
 	for (f = fields; f->name; f++) {
-		fl = flist_make(f->name);
-		fl->fld = f;
-		if (f->ftyp == type)
+		fl = flist_field_match(f, type, obj, startoff);
+		if (fl)
 			return fl;
-		count = fcount(f, obj, startoff);
-		if (!count) {
-			flist_free(fl);
-			continue;
-		}
-		fa = &ftattrtab[f->ftyp];
-		if (fa->subfld) {
-			flist_t *nfl;
-
-			nfl = flist_find_ftyp(fa->subfld, type, obj, startoff);
-			if (nfl) {
-				fl->child = nfl;
-				return fl;
-			}
-		}
-		flist_free(fl);
 	}
+
 	return NULL;
 }