diff options
author | Oliver O'Halloran <oohall@gmail.com> | 2017-11-08 19:59:11 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2017-11-20 20:35:24 -0600 |
commit | f6174ffe5a2efd0dd60a31882374191671668838 (patch) | |
tree | fc8a5d5ce02182376575fd8fdf13fff63188e3da /external/gard/gard.c | |
parent | 07d6b1a134126e9e276feb8f8b818313d3e8b7f9 (diff) | |
download | talos-skiboot-f6174ffe5a2efd0dd60a31882374191671668838.tar.gz talos-skiboot-f6174ffe5a2efd0dd60a31882374191671668838.zip |
gard: Use iterators for count_record()
Starting coverting code to use the iterators and fix some bad naming
along the way.
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'external/gard/gard.c')
-rw-r--r-- | external/gard/gard.c | 53 |
1 files changed, 12 insertions, 41 deletions
diff --git a/external/gard/gard.c b/external/gard/gard.c index c43b8594..bb92402f 100644 --- a/external/gard/gard.c +++ b/external/gard/gard.c @@ -243,55 +243,26 @@ static int __gard_next(struct gard_ctx *ctx, int pos, struct gard_record *gard, for (pos = __gard_next(ctx, 0, gard, rc); \ pos >= 0; pos = __gard_next(ctx, ++pos, gard, rc)) -static int get_largest_pos_i(struct gard_ctx *ctx, int pos, struct gard_record *gard, void *priv) +static int count_records(struct gard_ctx *ctx) { - (void)ctx; - (void)gard; - - if (!priv) - return -1; - - *(int *)priv = pos; - - return 0; -} - -static int get_largest_pos(struct gard_ctx *ctx) -{ - int rc, largest = -1; - - (void)ctx; - - rc = do_iterate(ctx, &get_largest_pos_i, &largest); - if (rc) - return -1; + struct gard_record record; + int rc, pos, count = 0; - return largest; -} + for_each_gard(ctx, pos, &record, &rc) + count++; -static int count_valid_records_i(struct gard_ctx *ctx, int pos, struct gard_record *gard, void *priv) -{ - (void)ctx; - (void)pos; - - if (!gard || !priv) - return -1; - - if (is_valid_record(gard)) - (*(int *)priv)++; - - return 0; + return rc ? rc : count; } static int count_valid_records(struct gard_ctx *ctx) { - int rc, count = 0; + struct gard_record record; + int rc, pos, count = 0; - rc = do_iterate(ctx, &count_valid_records_i, &count); - if (rc) - return 0; + for_each_gard(ctx, pos, &record, &rc) + count++; - return count; + return rc ? rc : count; } static int do_list_i(struct gard_ctx *ctx, int pos, struct gard_record *gard, void *priv) @@ -392,7 +363,7 @@ static int do_clear_i(struct gard_ctx *ctx, int pos, struct gard_record *gard, v memset(&null_gard, 0xFF, sizeof(null_gard)); - largest = get_largest_pos(ctx); + largest = count_records(ctx); printf("Clearing gard record 0x%08x...", be32toh(gard->record_id)); |