util/event_notifier: fix error handling for event_notifier_init callers
Check return value of event_notifier_init() and return early on failure instead of continuing with invalid state. - Use ret < 0 to handle negative return value. - No functional changes. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413 Signed-off-by: Trieu Huynh <vikingtc4@gmail.com> Acked-by: Anthony Krowiak <akrowiak@linux.ibm.com> Reviewed-by: Jagannathan Raman <jag.raman@oracle.com> Reviewed-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com> # for the Hyper-V part Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> Message-ID: <20260318141415.8538-4-vikingtc4@gmail.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Trieu Huynh committed
Mar 18, 2026 at 23:14 UTC
8953fd41e6ca1342ca798f8b030dc16ecbe3d61d
8 files changed
+23
-12
hw/hyperv/hyperv.c
+2
-2
@@ -439,7 +439,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
439
sint_route->staged_msg->cb_data = cb_data;
440
441
r = event_notifier_init(ack_notifier, false);
442
- if (r) {
442
+ if (r < 0) {
443
goto cleanup_err_sint;
444
}
445
event_notifier_set_handler(ack_notifier, sint_ack_handler);
@@ -453,7 +453,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
453
454
/* We need to setup a GSI for this SintRoute */
455
r = event_notifier_init(&sint_route->sint_set_notifier, false);
456
- if (r) {
456
+ if (r < 0) {
457
goto cleanup_err_sint;
458
}
459
hw/hyperv/vmbus.c
+2
-2
@@ -1432,7 +1432,7 @@ static void open_channel(VMBusChannel *chan)
1432
goto put_gpadl;
1433
}
1434
1435
- if (event_notifier_init(&chan->notifier, 0)) {
1435
+ if (event_notifier_init(&chan->notifier, 0) < 0) {
1436
goto put_gpadl;
1437
}
1438
@@ -2450,7 +2450,7 @@ static void vmbus_realize(BusState *bus, Error **errp)
2450
}
2451
2452
ret = event_notifier_init(&vmbus->notifier, 0);
2453
- if (ret != 0) {
2453
+ if (ret < 0) {
2454
error_setg(errp, "event notifier failed to init with %d", ret);
2455
goto remove_msg_handler;
2456
}
hw/remote/proxy.c
+13
-2
@@ -52,9 +52,20 @@ static void setup_irqfd(PCIProxyDev *dev)
52
PCIDevice *pci_dev = PCI_DEVICE(dev);
53
MPQemuMsg msg;
54
Error *local_err = NULL;
55
+ int ret = 0;
56
56
- event_notifier_init(&dev->intr, 0);
57
- event_notifier_init(&dev->resample, 0);
57
+ ret = event_notifier_init(&dev->intr, 0);
58
+ if (ret < 0) {
59
+ error_report("Failed to init intr notifier: %s", strerror(-ret));
60
+ return;
61
+ }
62
+
63
+ ret = event_notifier_init(&dev->resample, 0);
64
+ if (ret < 0) {
65
+ error_report("Failed to init resample notifier: %s", strerror(-ret));
66
+ event_notifier_cleanup(&dev->intr);
67
+ return;
68
+ }
69
70
memset(&msg, 0, sizeof(MPQemuMsg));
71
msg.cmd = MPQEMU_CMD_SET_IRQFD;
hw/vfio/ap.c
+1
-1
@@ -180,7 +180,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
180
return false;
181
}
182
183
- if (event_notifier_init(notifier, 0)) {
183
+ if (event_notifier_init(notifier, 0) < 0) {
184
error_setg_errno(errp, errno,
185
"vfio: Unable to init event notifier for irq (%d)",
186
irq);
hw/vfio/ccw.c
+1
-1
@@ -418,7 +418,7 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
418
return false;
419
}
420
421
- if (event_notifier_init(notifier, 0)) {
421
+ if (event_notifier_init(notifier, 0) < 0) {
422
error_setg_errno(errp, errno,
423
"vfio: Unable to init event notifier for irq (%d)",
424
irq);
hw/vfio/pci-quirks.c
+1
-1
@@ -318,7 +318,7 @@ static VFIOIOEventFD *vfio_ioeventfd_init(VFIOPCIDevice *vdev,
318
319
ioeventfd = g_malloc0(sizeof(*ioeventfd));
320
321
- if (event_notifier_init(&ioeventfd->e, 0)) {
321
+ if (event_notifier_init(&ioeventfd->e, 0) < 0) {
322
g_free(ioeventfd);
323
return NULL;
324
}
hw/vfio/pci.c
+1
-1
@@ -70,7 +70,7 @@ static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e,
70
}
71
72
ret = event_notifier_init(e, 0);
73
- if (ret) {
73
+ if (ret < 0) {
74
error_setg_errno(errp, -ret, "vfio_notifier_init %s failed", name);
75
return false;
76
}
hw/virtio/vhost-vdpa.c
+2
-2
@@ -1075,13 +1075,13 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,
1075
int r;
1076
1077
r = event_notifier_init(&svq->hdev_kick, 0);
1078
- if (r != 0) {
1078
+ if (r < 0) {
1079
error_setg_errno(errp, -r, "Couldn't create kick event notifier");
1080
goto err_init_hdev_kick;
1081
}
1082
1083
r = event_notifier_init(&svq->hdev_call, 0);
1084
- if (r != 0) {
1084
+ if (r < 0) {
1085
error_setg_errno(errp, -r, "Couldn't create call event notifier");
1086
goto err_init_hdev_call;
1087
}