Skip to contentSkip to conversation

vfio/ap: Make vfio_ap_register_irq_notifier() return a bool

PATCH Applied Cédric Le Goater 4 participants 13 messages Apr 25, 2024 – May 16, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/4 vfio/ap: Use g_autofree variable in vfio_ap_register_irq_notifier()

---
 hw/vfio/ap.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
hw/vfio/ap.c +3 -7
index 7c4caa5938636937680fec87e999249ac84a4498..03f8ffaa5e2bf13cf8daa2f44aa4cf17809abd94 100644
@@ -77,7 +77,7 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
     size_t argsz;
     IOHandler *fd_read;
     EventNotifier *notifier;
-    struct vfio_irq_info *irq_info;
+    g_autofree struct vfio_irq_info *irq_info = NULL;
     VFIODevice *vdev = &vapdev->vdev;
 
     switch (irq) {
@@ -104,14 +104,14 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
     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;
     }
 
     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;
     }
 
     fd = event_notifier_get_fd(notifier);
@@ -122,10 +122,6 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
         qemu_set_fd_handler(fd, NULL, NULL, vapdev);
         event_notifier_cleanup(notifier);
     }
-
-out_free_info:
-    g_free(irq_info);
-
 }
 
 static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,
Signature · 1 line
2.44.0
Reviewed-by on v2 1/4
#3 lore raw

Re: [PATCH v2 1/4] vfio/ap: Use g_autofree variable in vfio_ap_register_irq_notifier()

In reply to Cédric Le Goater
Quoted 4 lines · Cédric Le Goater
---
  hw/vfio/ap.c | 10 +++-------
  1 file changed, 3 insertions(+), 7 deletions(-)

LGTM

Quoted 42 lines
hw/vfio/ap.c +3 -7
index 7c4caa5938636937680fec87e999249ac84a4498..03f8ffaa5e2bf13cf8daa2f44aa4cf17809abd94 100644
@@ -77,7 +77,7 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
      size_t argsz;
      IOHandler *fd_read;
      EventNotifier *notifier;
-    struct vfio_irq_info *irq_info;
+    g_autofree struct vfio_irq_info *irq_info = NULL;
      VFIODevice *vdev = &vapdev->vdev;
 
      switch (irq) {
@@ -104,14 +104,14 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
      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;
      }
 
      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;
      }
 
      fd = event_notifier_get_fd(notifier);
@@ -122,10 +122,6 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
          qemu_set_fd_handler(fd, NULL, NULL, vapdev);
          event_notifier_cleanup(notifier);
      }
-
-out_free_info:
-    g_free(irq_info);
-
  }
 
  static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,
author Applied
#4 lore raw

Re: [PATCH v2 1/4] vfio/ap: Use g_autofree variable in vfio_ap_register_irq_notifier()

In reply to Cédric Le Goater

Applied series to vfio-next.

Thanks,

C.

Quoted 46 lines · Cédric Le Goater
---
  hw/vfio/ap.c | 10 +++-------
  1 file changed, 3 insertions(+), 7 deletions(-)
hw/vfio/ap.c +3 -7
index 7c4caa5938636937680fec87e999249ac84a4498..03f8ffaa5e2bf13cf8daa2f44aa4cf17809abd94 100644
@@ -77,7 +77,7 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
      size_t argsz;
      IOHandler *fd_read;
      EventNotifier *notifier;
-    struct vfio_irq_info *irq_info;
+    g_autofree struct vfio_irq_info *irq_info = NULL;
      VFIODevice *vdev = &vapdev->vdev;
 
      switch (irq) {
@@ -104,14 +104,14 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
      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;
      }
 
      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;
      }
 
      fd = event_notifier_get_fd(notifier);
@@ -122,10 +122,6 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
          qemu_set_fd_handler(fd, NULL, NULL, vapdev);
          event_notifier_cleanup(notifier);
      }
-
-out_free_info:
-    g_free(irq_info);
-
  }
 
  static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,
#5 lore raw

PATCH v2 2/4 vfio/ap: Make vfio_ap_register_irq_notifier() return a bool

In reply to a message not in the archive

Since vfio_ap_register_irq_notifier() takes and 'Error **' argument, best practices suggest to return a bool. See the qapi/error.h Rules section.

---
 hw/vfio/ap.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
hw/vfio/ap.c +8 -7
index 03f8ffaa5e2bf13cf8daa2f44aa4cf17809abd94..8bb024e2fde4a1d72346dee4b662d762374326b9 100644
@@ -70,7 +70,7 @@ static void vfio_ap_req_notifier_handler(void *opaque)
     }
 }
 
-static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
+static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
                                           unsigned int irq, Error **errp)
 {
     int fd;
@@ -87,13 +87,13 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
         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);
@@ -104,14 +104,14 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
     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");
-        return;
+        return false;
     }
 
     if (event_notifier_init(notifier, 0)) {
         error_setg_errno(errp, errno,
                          "vfio: Unable to init event notifier for irq (%d)",
                          irq);
-        return;
+        return false;
     }
 
     fd = event_notifier_get_fd(notifier);
@@ -122,6 +122,8 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
         qemu_set_fd_handler(fd, NULL, NULL, vapdev);
         event_notifier_cleanup(notifier);
     }
+
+    return true;
 }
 
 static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,
@@ -167,8 +169,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
         goto error;
     }
 
-    vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err);
-    if (err) {
+    if (!vfio_ap_register_irq_notifier(vapdev, VFIO_AP_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.
Signature · 1 line
2.44.0
Reviewed-by on v2 2/4
#6 lore raw
Quoted 65 lines · Cédric Le Goater

Since vfio_ap_register_irq_notifier() takes and 'Error **' argument, best practices suggest to return a bool. See the qapi/error.h Rules section.

---
 hw/vfio/ap.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
hw/vfio/ap.c +7 -5
index 03f8ffaa5e2bf13cf8daa2f44aa4cf17809abd94..8bb024e2fde4a1d72346dee4b662d762374326b9 100644
@@ -70,7 +70,7 @@ static void vfio_ap_req_notifier_handler(void *opaque)
     }
 }
 
-static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
+static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
                                           unsigned int irq, Error **errp)
 {
     int fd;
@@ -87,13 +87,13 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
         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);
@@ -104,14 +104,14 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
     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");
-        return;
+        return false;
     }
 
     if (event_notifier_init(notifier, 0)) {
         error_setg_errno(errp, errno,
                          "vfio: Unable to init event notifier for irq (%d)",
                          irq);
-        return;
+        return false;
     }
 
     fd = event_notifier_get_fd(notifier);
@@ -122,6 +122,8 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
         qemu_set_fd_handler(fd, NULL, NULL, vapdev);
         event_notifier_cleanup(notifier);
     }
+
+    return true;
 }
 
 static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,

hw/vfio/ap.c static void vfio_ap_realize(DeviceState *dev, Error **errp) · line 175

Quoted 9 lines
hw/vfio/ap.c +1 -2
@@ -167,8 +169,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
         goto error;
     }
 
-    vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err);
-    if (err) {
+    if (!vfio_ap_register_irq_notifier(vapdev, VFIO_AP_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.
            */
           error_report_err(err);

Not this patch's problem, but here goes anyway: since this isn't an error, we shouldn't use error_report_err(). Would warn_report_err() be appropriate? info_report_err() doesn't exist, but it could.

This patch is fine as is, so

#7 lore raw

PATCH v2 3/4 vfio/ccw: Use g_autofree variable in vfio_ccw_register_irq_notifier()

In reply to a message not in the archive
---
 hw/vfio/ccw.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/vfio/ccw.c +3 -6
index 90e4a534371684c08e112364e1537eb8979f73f4..6764388bc47a970329fce2233626ccb8178e0165 100644
@@ -384,7 +384,7 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
                                            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;
@@ -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;
     }
 
     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;
     }
 
     fd = event_notifier_get_fd(notifier);
@@ -439,9 +439,6 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
         qemu_set_fd_handler(fd, NULL, NULL, vcdev);
         event_notifier_cleanup(notifier);
     }
-
-out_free_info:
-    g_free(irq_info);
 }
 
 static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,
Signature · 1 line
2.44.0
#10 lore raw

PATCH v2 4/4 vfio/ccw: Make vfio_ccw_register_irq_notifier() return a bool

In reply to a message not in the archive

Since vfio_ccw_register_irq_notifier() takes an 'Error **' argument, best practices suggest to return a bool. See the qapi/error.h Rules section.

---
 hw/vfio/ccw.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
hw/vfio/ccw.c +11 -11
index 6764388bc47a970329fce2233626ccb8178e0165..1c630f6e9abe93ae0c2b5615d4409669f096c8c9 100644
@@ -379,7 +379,7 @@ 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)
 {
@@ -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");
-        return;
+        return false;
     }
 
     if (event_notifier_init(notifier, 0)) {
         error_setg_errno(errp, errno,
                          "vfio: Unable to init event notifier for irq (%d)",
                          irq);
-        return;
+        return false;
     }
 
     fd = event_notifier_get_fd(notifier);
@@ -439,6 +439,8 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
         qemu_set_fd_handler(fd, NULL, NULL, vcdev);
         event_notifier_cleanup(notifier);
     }
+
+    return true;
 }
 
 static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,
@@ -602,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.
Signature · 1 line
2.44.0
Reviewed-by on v2 4/4
#11 lore raw

Re: [PATCH v2 4/4] vfio/ccw: Make vfio_ccw_register_irq_notifier() return a bool

Quoted 65 lines · Cédric Le Goater

Since vfio_ccw_register_irq_notifier() takes an 'Error **' argument, best practices suggest to return a bool. See the qapi/error.h Rules section.

---
 hw/vfio/ccw.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
hw/vfio/ccw.c +7 -5
index 6764388bc47a970329fce2233626ccb8178e0165..1c630f6e9abe93ae0c2b5615d4409669f096c8c9 100644
@@ -379,7 +379,7 @@ 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)
 {
@@ -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");
-        return;
+        return false;
     }
 
     if (event_notifier_init(notifier, 0)) {
         error_setg_errno(errp, errno,
                          "vfio: Unable to init event notifier for irq (%d)",
                          irq);
-        return;
+        return false;
     }
 
     fd = event_notifier_get_fd(notifier);
@@ -439,6 +439,8 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
         qemu_set_fd_handler(fd, NULL, NULL, vcdev);
         event_notifier_cleanup(notifier);
     }
+
+    return true;
 }
 
 static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,

hw/vfio/ccw.c static void vfio_ccw_realize(DeviceState *dev, Error **errp) · line 607

Quoted 6 lines
hw/vfio/ccw.c +1 -2
@@ -602,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.

hw/vfio/ccw.c static void vfio_ccw_realize(DeviceState *dev, Error **errp) · line 613

Quoted 8 lines
hw/vfio/ccw.c +2 -2
         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.

hw/vfio/ccw.c static void vfio_ccw_realize(DeviceState *dev, Error **errp) · line 621

Quoted 10 lines
hw/vfio/ccw.c +1 -2
             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.
            */
           error_report_err(err);

Not this patch's problem, but here goes anyway: since this isn't an error, we shouldn't use error_report_err(). Would warn_report_err() be appropriate? info_report_err() doesn't exist, but it could.

Preferably with errp instead of &err (two times):

Reviewed-by
#12 lore raw

Re: [PATCH v2 4/4] vfio/ccw: Make vfio_ccw_register_irq_notifier() return a bool

Quoted 118 lines · Markus Armbruster
Quoted 77 lines · Cédric Le Goater

Since vfio_ccw_register_irq_notifier() takes an 'Error **' argument,
best practices suggest to return a bool. See the qapi/error.h Rules section.

---
 hw/vfio/ccw.c | 22 +++++++++++-----------

 1 file changed, 11 insertions(+), 11 deletions(-)
hw/vfio/ccw.c +0 -0

index 6764388bc47a970329fce2233626ccb8178e0165..1c630f6e9abe93ae0c2b5615d 4409669f096c8c9 100644

hw/vfio/ccw.c +0 -0
@@ -379,7 +379,7 @@ read_err:
      css_inject_io_interrupt(sch);
  }

hw/vfio/ccw.c +1 -1
-static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
+static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,

                                            unsigned int irq, Error **errp) {

hw/vfio/ccw.c +0 -0
@@ -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);

hw/vfio/ccw.c +0 -0
@@ -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");
-        return;
+        return false;
     }

     if (event_notifier_init(notifier, 0)) { error_setg_errno(errp, errno,
                          "vfio: Unable to init event notifier for irq (%d)",
                          irq);
-        return;
+        return false;
     }

     fd = event_notifier_get_fd(notifier);

hw/vfio/ccw.c +2 -0
@@ -439,6 +439,8 @@ static void
 vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
          qemu_set_fd_handler(fd, NULL, NULL, vcdev);
          event_notifier_cleanup(notifier);
      }
+
+    return true;
  }


 static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,

hw/vfio/ccw.c +0 -0
@@ -602,20 +604,18 @@ static void vfio_ccw_realize(DeviceState
 *dev, Error **errp)
          goto out_region_err;
      }
Quoted 6 lines


-    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.

Quoted 10 lines

         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.

Quoted 6 lines

             goto out_irq_notifier_err;
         }
     }

-    vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX, &err);

Quoted 8 lines

-    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.

            */
           error_report_err(err);

Quoted 8 lines

Not this patch's problem, but here goes anyway: since this isn't an error, we shouldn't use error_report_err().  Would warn_report_err() be
appropriate?  info_report_err() doesn't exist, but it could.

Preferably with errp instead of &err (two times):

Don't recall why I used error_report_err() instead of something else (or creating info_), but probably just familiarity. There's no need for it (or the equivalent code in -ap) to be error, and could be another cleanup.

#13 lore raw

Re: [PATCH v2 4/4] vfio/ccw: Make vfio_ccw_register_irq_notifier() return a bool

Quoted 124 lines · Eric Farman
Quoted 123 lines · Markus Armbruster
Quoted 74 lines · Cédric Le Goater

Since vfio_ccw_register_irq_notifier() takes an 'Error **' argument,
best practices suggest to return a bool. See the qapi/error.h Rules section.

---
  hw/vfio/ccw.c | 22 +++++++++++-----------
  1 file changed, 11 insertions(+), 11 deletions(-)
hw/vfio/ccw.c +0 -0

index 6764388bc47a970329fce2233626ccb8178e0165..1c630f6e9abe93ae0c2b5615d 4409669f096c8c9 100644

hw/vfio/ccw.c +3 -3
@@ -379,7 +379,7 @@ 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)
  {
@@ -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);

hw/vfio/ccw.c +2 -2
@@ -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");
-        return;
+        return false;
      }
 
      if (event_notifier_init(notifier, 0)) {
          error_setg_errno(errp, errno,
                           "vfio: Unable to init event notifier for
 irq (%d)",
                           irq);
-        return;
+        return false;

     }

     fd = event_notifier_get_fd(notifier);

hw/vfio/ccw.c +2 -0
@@ -439,6 +439,8 @@ static void
 vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
          qemu_set_fd_handler(fd, NULL, NULL, vcdev);
          event_notifier_cleanup(notifier);
      }
+
+    return true;
  }
 

 static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,

hw/vfio/ccw.c static void vfio_ccw_realize(DeviceState · line 610

Quoted 9 lines
hw/vfio/ccw.c +1 -2
@@ -602,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.

hw/vfio/ccw.c static void vfio_ccw_realize(DeviceState *dev, Error **errp) · line 613

Quoted 10 lines
hw/vfio/ccw.c +2 -2
          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.

Quoted 6 lines
hw/vfio/ccw.c +0 -1
              goto out_irq_notifier_err;
          }
      }
 
-    vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX,

&err);

Quoted 8 lines

-    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.

            */
           error_report_err(err);

Not this patch's problem, but here goes anyway: since this isn't an error, we shouldn't use error_report_err().  Would warn_report_err() be
appropriate?  info_report_err() doesn't exist, but it could.

Quoted 8 lines
Quoted 3 lines

Preferably with errp instead of &err (two times):

Don't recall why I used error_report_err() instead of something else (or creating info_), but probably just familiarity. There's no need for it (or the equivalent code in -ap) to be error, and could be another cleanup.

yes. I will send an extra cleanup to replace error_... with warn_... and another one to use errp.

Thanks,

C.

Quoted 2 lines