Message ID | 20240424125441.215953-1-clg@redhat.com |
---|---|
State | New |
Headers | show |
Series | vfio/ccw: Use g_autofree variable | expand |
On 24/04/2024 14.54, Cédric Le Goater wrote: > Also change the return value of vfio_ccw_register_irq_notifier() to be > a bool since it takes and 'Error **' argument. See the qapi/error.h > Rules section. > > Signed-off-by: Cédric Le Goater <clg@redhat.com> > --- > hw/vfio/ccw.c | 25 +++++++++++-------------- > 1 file changed, 11 insertions(+), 14 deletions(-) Reviewed-by: Thomas Huth <thuth@redhat.com>
Cédric Le Goater <clg@redhat.com> writes: > Also change the return value of vfio_ccw_register_irq_notifier() to be > a bool since it takes and 'Error **' argument. See the qapi/error.h > Rules section. > > Signed-off-by: Cédric Le Goater <clg@redhat.com> My comments on "[PATCH] vfio/ap: Use g_autofree variable" apply. More inline. > --- > hw/vfio/ccw.c | 25 +++++++++++-------------- > 1 file changed, 11 insertions(+), 14 deletions(-) > > diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c > index 90e4a534371684c08e112364e1537eb8979f73f4..1c630f6e9abe93ae0c2b5615d4409669f096c8c9 100644 > --- a/hw/vfio/ccw.c > +++ b/hw/vfio/ccw.c > @@ -379,12 +379,12 @@ read_err: > css_inject_io_interrupt(sch); > } > > -static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, > +static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, > unsigned int irq, > Error **errp) > { > VFIODevice *vdev = &vcdev->vdev; > - struct vfio_irq_info *irq_info; > + g_autofree struct vfio_irq_info *irq_info = NULL; > size_t argsz; > int fd; > EventNotifier *notifier; > @@ -405,13 +405,13 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, > break; > default: > error_setg(errp, "vfio: Unsupported device irq(%d)", irq); > - return; > + return false; > } > > if (vdev->num_irqs < irq + 1) { > error_setg(errp, "vfio: IRQ %u not available (number of irqs %u)", > irq, vdev->num_irqs); > - return; > + return false; > } > > argsz = sizeof(*irq_info); > @@ -421,14 +421,14 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, > if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, > irq_info) < 0 || irq_info->count < 1) { > error_setg_errno(errp, errno, "vfio: Error getting irq info"); > - goto out_free_info; > + return false; > } > > if (event_notifier_init(notifier, 0)) { > error_setg_errno(errp, errno, > "vfio: Unable to init event notifier for irq (%d)", > irq); > - goto out_free_info; > + return false; > } > > fd = event_notifier_get_fd(notifier); > @@ -440,8 +440,7 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, > event_notifier_cleanup(notifier); > } > > -out_free_info: > - g_free(irq_info); > + return true; > } > > static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev, > @@ -605,20 +604,18 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp) > goto out_region_err; > } > > - vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err); > - if (err) { > + if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err)) { Please pass errp instead of &err. > goto out_io_notifier_err; > } > > if (vcdev->crw_region) { > - vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, &err); > - if (err) { > + if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, > + &err)) { Likewise. > goto out_irq_notifier_err; > } > } > > - vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX, &err); > - if (err) { > + if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX, &err)) { > /* > * Report this error, but do not make it a failing condition. > * Lack of this IRQ in the host does not prevent normal operation. Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 90e4a534371684c08e112364e1537eb8979f73f4..1c630f6e9abe93ae0c2b5615d4409669f096c8c9 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -379,12 +379,12 @@ read_err: css_inject_io_interrupt(sch); } -static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, +static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, unsigned int irq, Error **errp) { VFIODevice *vdev = &vcdev->vdev; - struct vfio_irq_info *irq_info; + g_autofree struct vfio_irq_info *irq_info = NULL; size_t argsz; int fd; EventNotifier *notifier; @@ -405,13 +405,13 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, break; default: error_setg(errp, "vfio: Unsupported device irq(%d)", irq); - return; + return false; } if (vdev->num_irqs < irq + 1) { error_setg(errp, "vfio: IRQ %u not available (number of irqs %u)", irq, vdev->num_irqs); - return; + return false; } argsz = sizeof(*irq_info); @@ -421,14 +421,14 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, irq_info) < 0 || irq_info->count < 1) { error_setg_errno(errp, errno, "vfio: Error getting irq info"); - goto out_free_info; + return false; } if (event_notifier_init(notifier, 0)) { error_setg_errno(errp, errno, "vfio: Unable to init event notifier for irq (%d)", irq); - goto out_free_info; + return false; } fd = event_notifier_get_fd(notifier); @@ -440,8 +440,7 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, event_notifier_cleanup(notifier); } -out_free_info: - g_free(irq_info); + return true; } static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev, @@ -605,20 +604,18 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp) goto out_region_err; } - vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err); - if (err) { + if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err)) { goto out_io_notifier_err; } if (vcdev->crw_region) { - vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, &err); - if (err) { + if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, + &err)) { goto out_irq_notifier_err; } } - vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX, &err); - if (err) { + if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX, &err)) { /* * Report this error, but do not make it a failing condition. * Lack of this IRQ in the host does not prevent normal operation.
Also change the return value of vfio_ccw_register_irq_notifier() to be a bool since it takes and 'Error **' argument. See the qapi/error.h Rules section. Signed-off-by: Cédric Le Goater <clg@redhat.com> --- hw/vfio/ccw.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)