virtio-blk: do not use C99 mixed declarations
PATCH 1/1 virtio-blk: do not use C99 mixed declarations
QEMU's coding style generally forbids C99 mixed declarations.
--- hw/block/virtio-blk.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
hw/block/virtio-blk.c +14 -11
@@ -661,16 +661,16 @@ static void virtio_blk_zone_report_complete(void *opaque, int ret)int64_t zrp_size, n, j =0 ;int64_t nz = data->zone_report_data.nr_zones;int8_t err_status =VIRTIO_BLK_S_OK ; - -trace_virtio_blk_zone_report_complete (vdev, req, nz, ret); -if (ret) { - err_status =VIRTIO_BLK_S_ZONE_INVALID_CMD ; - goto out; - } -struct virtio_blk_zone_report zrp_hdr = (struct virtio_blk_zone_report ) { .nr_zones =cpu_to_le64 (nz), }; + +trace_virtio_blk_zone_report_complete (vdev, req, nz, ret); +if (ret) { + err_status =VIRTIO_BLK_S_ZONE_INVALID_CMD ; + goto out; + } + zrp_size =sizeof (struct virtio_blk_zone_report ) +sizeof (struct virtio_blk_zone_descriptor ) * nz; n =iov_from_buf (in_iov, in_num,0 , &zrp_hdr,sizeof (zrp_hdr));
@@ -898,13 +898,14 @@ static int virtio_blk_handle_zone_append(VirtIOBlockReq *req,int64_t offset =virtio_ldq_p (vdev, &req->out.sector) <<BDRV_SECTOR_BITS ;int64_t len =iov_size (out_iov, out_num); +ZoneCmdData *data;trace_virtio_blk_handle_zone_append (vdev, req, offset >>BDRV_SECTOR_BITS );if (!check_zoned_request (s, offset, len, true, &err_status)) { goto out; } -ZoneCmdData *data =g_malloc (sizeof (ZoneCmdData)); + data =g_malloc (sizeof (ZoneCmdData)); data->req = req; data->in_iov = in_iov; data->in_num = in_num;
@@ -1191,14 +1192,15 @@ static void virtio_blk_dma_restart_cb(void *opaque, bool running, {VirtIOBlock *s = opaque;uint16_t num_queues = s->conf.num_queues; + g_autofree VirtIOBlockReq **vq_rq = NULL; +VirtIOBlockReq *rq;if (!running) {return ; }/* Split the device-wide s->rq request list into per-vq request lists */ - g_autofree VirtIOBlockReq **vq_rq = g_new0(VirtIOBlockReq *, num_queues); -VirtIOBlockReq *rq; + vq_rq = g_new0(VirtIOBlockReq *, num_queues); WITH_QEMU_LOCK_GUARD(&s->rq_lock) { rq = s->rq;
@@ -1924,6 +1926,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)VirtIODevice *vdev =VIRTIO_DEVICE (dev);VirtIOBlock *s =VIRTIO_BLK (dev);VirtIOBlkConf *conf = &s->conf; +BlockDriverState *bs;Error *err =NULL ;unsigned i;
@@ -1969,7 +1972,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)return ; } -BlockDriverState *bs =blk_bs (conf->conf.blk); + bs =blk_bs (conf->conf.blk);if (bs->bl.zoned !=BLK_Z_NONE ) {virtio_add_feature (&s->host_features,VIRTIO_BLK_F_ZONED );if (bs->bl.zoned ==BLK_Z_HM ) {
Signature · 1 line
2.43.0
Quoted 6 lines · Stefan Hajnoczi
QEMU's coding style generally forbids C99 mixed declarations.
Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/block/virtio-blk.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
Quoted 3 lines · Stefan Hajnoczi
QEMU's coding style generally forbids C99 mixed declarations.
Signed-off-by Stefan Hajnoczi <[email protected]>
or maybe it's time we moved on?
Quoted 85 lines
--- hw/block/virtio-blk.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)hw/block/virtio-blk.c +14
-11@@ -661,16 +661,16 @@ static void virtio_blk_zone_report_complete(void *opaque, int ret)int64_t zrp_size, n, j =0 ;int64_t nz = data->zone_report_data.nr_zones;int8_t err_status =VIRTIO_BLK_S_OK ; - -trace_virtio_blk_zone_report_complete (vdev, req, nz, ret); -if (ret) { - err_status =VIRTIO_BLK_S_ZONE_INVALID_CMD ; - goto out; - } -struct virtio_blk_zone_report zrp_hdr = (struct virtio_blk_zone_report ) { .nr_zones =cpu_to_le64 (nz), }; + +trace_virtio_blk_zone_report_complete (vdev, req, nz, ret); +if (ret) { + err_status =VIRTIO_BLK_S_ZONE_INVALID_CMD ; + goto out; + } + zrp_size =sizeof (struct virtio_blk_zone_report ) +sizeof (struct virtio_blk_zone_descriptor ) * nz; n =iov_from_buf (in_iov, in_num,0 , &zrp_hdr,sizeof (zrp_hdr));@@ -898,13 +898,14 @@ static int virtio_blk_handle_zone_append(VirtIOBlockReq *req,int64_t offset =virtio_ldq_p (vdev, &req->out.sector) <<BDRV_SECTOR_BITS ;int64_t len =iov_size (out_iov, out_num); +ZoneCmdData *data;trace_virtio_blk_handle_zone_append (vdev, req, offset >>BDRV_SECTOR_BITS );if (!check_zoned_request (s, offset, len, true, &err_status)) { goto out; } -ZoneCmdData *data =g_malloc (sizeof (ZoneCmdData)); + data =g_malloc (sizeof (ZoneCmdData)); data->req = req; data->in_iov = in_iov; data->in_num = in_num;@@ -1191,14 +1192,15 @@ static void virtio_blk_dma_restart_cb(void *opaque, bool running, {VirtIOBlock *s = opaque;uint16_t num_queues = s->conf.num_queues; + g_autofree VirtIOBlockReq **vq_rq = NULL; +VirtIOBlockReq *rq;if (!running) {return ; }/* Split the device-wide s->rq request list into per-vq request lists */ - g_autofree VirtIOBlockReq **vq_rq = g_new0(VirtIOBlockReq *, num_queues); -VirtIOBlockReq *rq; + vq_rq = g_new0(VirtIOBlockReq *, num_queues); WITH_QEMU_LOCK_GUARD(&s->rq_lock) { rq = s->rq;@@ -1924,6 +1926,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)VirtIODevice *vdev =VIRTIO_DEVICE (dev);VirtIOBlock *s =VIRTIO_BLK (dev);VirtIOBlkConf *conf = &s->conf; +BlockDriverState *bs;Error *err =NULL ;unsigned i;@@ -1969,7 +1972,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)return ; } -BlockDriverState *bs =blk_bs (conf->conf.blk); + bs =blk_bs (conf->conf.blk);if (bs->bl.zoned !=BLK_Z_NONE ) {virtio_add_feature (&s->host_features,VIRTIO_BLK_F_ZONED );if (bs->bl.zoned ==BLK_Z_HM ) {Signature · 1 line
2.43.0
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Stefan Hajnoczi
QEMU's coding style generally forbids C99 mixed declarations.
Signed-off-by Stefan Hajnoczi <[email protected]>or maybe it's time we moved on?
I sent a patch to allow C99 mixed declarations but a number of people spoke out against changing the coding style so it didn't seem like a good thing to pursue:
https://lore.kernel.org/qemu-devel/[email protected]/
Instead, I just want to make virtio-blk consistent with the coding style...especially because I introduced one of the recent violations :-).
Stefan
Kevin Wolf
AppliedAm 06.02.2024 um 15:04 hat Stefan Hajnoczi geschrieben:
Quoted 3 lines
QEMU's coding style generally forbids C99 mixed declarations.
Signed-off-by Stefan Hajnoczi <[email protected]>
Thanks, applied to the block branch.
Kevin