Change the type of the third argument of f2fs_report_zone() from void * into struct blk_zone * to enable type checking.
Signed-off-by: Bart Van Assche <bvanass...@acm.org> --- include/f2fs_fs.h | 4 +++- lib/libf2fs_zoned.c | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index fdbf7c7a0b35..8125e9f8d082 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -1560,9 +1560,11 @@ blk_zone_cond_str(struct blk_zone *blkz) #endif +struct blk_zone; + extern int f2fs_get_zoned_model(int); extern int f2fs_get_zone_blocks(int); -extern int f2fs_report_zone(int, uint64_t, void *); +extern int f2fs_report_zone(int, uint64_t, struct blk_zone *); typedef int (report_zones_cb_t)(int i, void *, void *); extern int f2fs_report_zones(int, report_zones_cb_t *, void *); extern int f2fs_check_zones(int); diff --git a/lib/libf2fs_zoned.c b/lib/libf2fs_zoned.c index d8de66b82029..a0dd8bd269ef 100644 --- a/lib/libf2fs_zoned.c +++ b/lib/libf2fs_zoned.c @@ -200,21 +200,26 @@ int f2fs_get_zone_blocks(int i) return 0; } -int f2fs_report_zone(int i, uint64_t sector, void *blkzone) +int f2fs_report_zone(int i, uint64_t sector, struct blk_zone *blkzone) { - struct blk_zone *blkz = (struct blk_zone *)blkzone; - struct blk_zone_report *rep; + struct one_zone_report { + struct blk_zone_report rep; + struct blk_zone zone; + } *rep; int ret = -1; - rep = calloc(1, sizeof(struct blk_zone_report) + - sizeof(struct blk_zone)); + static_assert(sizeof(*rep) == sizeof(rep->rep) + sizeof(rep->zone), ""); + + rep = calloc(1, sizeof(*rep)); if (!rep) { ERR_MSG("No memory for report zones\n"); return -ENOMEM; } - rep->sector = sector; - rep->nr_zones = 1; + rep->rep = (struct blk_zone_report){ + .sector = sector, + .nr_zones = 1, + }; ret = ioctl(c.devices[i].fd, BLKREPORTZONE, rep); if (ret != 0) { ret = -errno; @@ -222,7 +227,7 @@ int f2fs_report_zone(int i, uint64_t sector, void *blkzone) goto out; } - *blkz = *(struct blk_zone *)(rep + 1); + *blkzone = rep->zone; out: free(rep); return ret; @@ -531,7 +536,8 @@ uint32_t f2fs_get_usable_segments(struct f2fs_super_block *sb) #else -int f2fs_report_zone(int i, uint64_t UNUSED(sector), void *UNUSED(blkzone)) +int f2fs_report_zone(int i, uint64_t UNUSED(sector), + struct blk_zone *UNUSED(blkzone)) { ERR_MSG("%d: Unsupported zoned block device\n", i); return -1; _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel