Stefan Hajnoczi <stefa...@redhat.com> 于2023年4月10日周一 21:49写道: > > Avoid mixing int and unsigned int for zone index and count values. This > eliminates the possibility of accidental negative write pointer array > indices. It also makes code review easier because we don't need to worry > about signed/unsigned comparisons. > > In practice I don't think zoned devices are likely to exceed MAX_INT > zones any time soon, so this is mostly a code cleanup. > > Cc: Sam Li <faithilike...@gmail.com> > Cc: Dmitry Fomichev <dmitry.fomic...@wdc.com> > Cc: Damien Le Moal <damien.lem...@opensource.wdc.com> > Signed-off-by: Stefan Hajnoczi <stefa...@redhat.com> > --- > block/file-posix.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > This is a cleanup on top of "[PATCH v9 0/4] Add zone append write for > zoned device". > > Based-on: <20230407081657.17947-1-faithilike...@gmail.com>
Reviewed-by: Sam Li <faithilike...@gmail.com> > > diff --git a/block/file-posix.c b/block/file-posix.c > index 32b16bc4fb..77fbf9e33e 100644 > --- a/block/file-posix.c > +++ b/block/file-posix.c > @@ -1338,8 +1338,9 @@ static int get_zones_wp(BlockDriverState *bs, int fd, > int64_t offset, > size_t rep_size; > uint64_t sector = offset >> BDRV_SECTOR_BITS; > BlockZoneWps *wps = bs->wps; > - int j = offset / bs->bl.zone_size; > - int ret, n = 0, i = 0; > + unsigned int j = offset / bs->bl.zone_size; > + int ret; > + unsigned int n = 0, i = 0; > rep_size = sizeof(struct blk_zone_report) + nrz * sizeof(struct > blk_zone); > g_autofree struct blk_zone_report *rep = NULL; > > @@ -2092,7 +2093,8 @@ static int handle_aiocb_zone_report(void *opaque) > struct blk_zone *blkz; > size_t rep_size; > unsigned int nrz; > - int ret, n = 0, i = 0; > + int ret; > + unsigned int n = 0, i = 0; > > nrz = *nr_zones; > rep_size = sizeof(struct blk_zone_report) + nrz * sizeof(struct > blk_zone); > @@ -3507,11 +3509,11 @@ static int coroutine_fn > raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, > return ret; > } > } else if (zo == BLKRESETZONE) { > - for (int j = 0; j < nrz; ++j) { > + for (unsigned int j = 0; j < nrz; ++j) { > wp[j] = offset + j * zone_size; > } > } else if (zo == BLKFINISHZONE) { > - for (int j = 0; j < nrz; ++j) { > + for (unsigned int j = 0; j < nrz; ++j) { > /* The zoned device allows the last zone smaller that the > * zone size. */ > wp[j] = MIN(offset + (j + 1) * zone_size, offset + len); > -- > 2.39.2 >