From: Andrey Albershteyn <aalbersh@redhat.com>
To: cem@kernel.org, linux-xfs@vger.kernel.org
Cc: djwong@kernel.org, hch@infradead.org,
Andrey Albershteyn <aalbersh@redhat.com>
Subject: [PATCH 2/2] xfs_db: add helper for flist_find_type for clearer field matching
Date: Tue, 16 Apr 2024 22:28:42 +0200 [thread overview]
Message-ID: <20240416202841.725706-4-aalbersh@redhat.com> (raw)
In-Reply-To: <20240416202841.725706-2-aalbersh@redhat.com>
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 | 59 ++++++++++++++++++++++++++++++++++--------------------
1 file changed, 37 insertions(+), 22 deletions(-)
diff --git a/db/flist.c b/db/flist.c
index 0a6cc5fcee43..18052a744a65 100644
--- a/db/flist.c
+++ b/db/flist.c
@@ -400,6 +400,40 @@ flist_split(
return v;
}
+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;
+
+ 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) {
+ flist_t *nfl;
+
+ 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,14 @@ 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)
+ if ((fl = flist_field_match(f, type, obj, startoff)) != NULL)
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
next prev parent reply other threads:[~2024-04-16 20:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-16 20:28 [PATCH 0/2] Refactoring from Coverity scan fixes Andrey Albershteyn
2024-04-16 20:28 ` [PATCH 1/2] xfs_fsr: replace atoi() with strtol() Andrey Albershteyn
2024-04-16 20:49 ` Darrick J. Wong
2024-04-16 20:28 ` Andrey Albershteyn [this message]
2024-04-16 20:53 ` [PATCH 2/2] xfs_db: add helper for flist_find_type for clearer field matching Darrick J. Wong
2024-04-17 5:03 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240416202841.725706-4-aalbersh@redhat.com \
--to=aalbersh@redhat.com \
--cc=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.