From nobody Mon Apr 6 19:40:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1773843367; cv=none; d=zohomail.com; s=zohoarc; b=C4Cg22f0F/JMkPzoqDIxt+15Ozavfv5NIiGaP2aYj/xHDESRSc3encr2mNn9eVICOWiLhIN1LrY2VCsR436kgysnKfAMxHaZGngY4QnGoCioazeGRAmYfXsGqtFLv8HLlOCznCLfpMa2F4ZSRnA5VYAYQFb4/RVJLSogIkuQvBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773843367; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9AsPYgj95PXD3MBcJoJu/VQSlxFjkWCj9VT48jKP+PA=; b=SBiT6vlEs4FHvqWb5vivCxroMV4NYEwo7nX99bKUTpd5+JVPMtuP4+5t9AcQ7yUmFilGq32J5u3BsUPSL7x1dj9eRe2XtbjqhCkqUmtV5KE6Uq0hUNVB7NiZF3t67EbS77oTR6IKQefPG7Rzwpv0DO7m4+OZfVG+GrxW0+RSn8k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773843367519366.0256868045474; Wed, 18 Mar 2026 07:16:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2rgf-0007Ld-He; Wed, 18 Mar 2026 10:15:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2rgR-0007Fc-1o for qemu-devel@nongnu.org; Wed, 18 Mar 2026 10:15:39 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w2rgM-00060J-RE for qemu-devel@nongnu.org; Wed, 18 Mar 2026 10:15:38 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-82a67ce6969so886331b3a.1 for ; Wed, 18 Mar 2026 07:15:34 -0700 (PDT) Received: from trieu2-huynh-trieuhpn-ubuntu24.bee-live.svc.cluster.local ([27.122.242.65]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82a6af06bd7sm2927272b3a.0.2026.03.18.07.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 07:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773843333; x=1774448133; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9AsPYgj95PXD3MBcJoJu/VQSlxFjkWCj9VT48jKP+PA=; b=Ja0rutqfHkCD4mBBvgqyd0BtZrPUWHSL8npaKbpFtMHyNODifeKabtKnfVU8XsiCXe ouSa2syaBH/PYUamzy2ZLolxG3g1wGc1wSRM9JqcWYi2POmzKpZDnc9fOrE9wwCtTQsw kFsFAVbjHagaKIop0JgG3HTTUzQCUzubPPOYuMn4z1AIwq9fan2sJBwwCntBtPb48tA1 wjpAgLtMB7s4lq68GVcugX3pCvkEw0SNhsbzeNJ5aTM8LqQMS3hyqtvRdgDAV6pCM7AU kHV3k9xWWxyXd0d6XOS4UB7LD4fCJs6+oyrbLv1zNW/VuUQzCEJuJSpGBsbjg5AzaCK2 4y+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773843333; x=1774448133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9AsPYgj95PXD3MBcJoJu/VQSlxFjkWCj9VT48jKP+PA=; b=Dc55+C+DwAXkjytHhqXRe0Z3SNLCoblSGoJ1Zs/pUsuoFuMtnfO7+bp8xZnEvDjdKm zv1b4YjDx0f7VTl1IXYEBuBOoQACLWvNWTzDlc3ow+lVrFmFlfFiXGLIWVTaEtkFe//H QtP4011lacHj9OLp8zShFxBoq0ycwKGrRSwppLFWX3hjgVp5eowz+wdqBMcDqTDeR/IR GivOJTDgH/3LF0caZe9c8zrco25tkmcTPdFrsVOog1Y3LZVDYSnrCguKG7lDlPMREXbr N4Am+ocLIi4RQPEg1J3Cv327y/clay/EmvHIEWlnBy98EOCLXit90v+o4AUlb8g927ld bhqA== X-Gm-Message-State: AOJu0YxmiqMEh92cXCq22jorsStr9KyJpw60KvHayD1l0LMpOy9oYpKF JwUcB51t3R96/pqBSe5gR/67jUpLWvZPb8J7iS9/ReEt4Q0OzLmrQT3QcGmU2CniDAw= X-Gm-Gg: ATEYQzzBs7bUMKNplcTVoyU67kaLNAhNT21SVmOmXT+2Xra43uHx9C5Si0rgTeVOQvE QvD8uzRJI5nHJR2ig6dPsAWeyJig/jfC+R4Xag1zfl+kFOpiJH6q4JspisZECPcuw0J6/UmhtZk xVJWSz7vB/XQFeL5aDjCSZZvApJTcYeFqAJJgzBdcMGnJXiftyRyo5af/II6CKX26Xoo6qyk8qe nr3mkMuSjA5l6rdKPBveyB4UCbrbJKZZE6VcIxJx1u8y8RovJU2PgNSaDH33tq738zrpTaRSwYe VwA54A3IDW+oFhNhOcdPc3sLvnifpq78fhxof3BKB2YXjrba9Dv/dKTGUi7o4SXKlwsgqYpP4cw MDcCGEuyMHsvZbIXb76y8igu/sCtIeLBEZsqCHUWdNoQRmEYxuxvwJoTNMATJ+rZBATQDHSVIts TLeD3b7MignOe4t872oyoW779BWlza8h0jqLaTAYPAAOu+yTQmdMajNHWHOpBU8rAG2r30Oqy9m nwccgBhsA== X-Received: by 2002:a05:6a00:908e:b0:82a:78cd:3ba4 with SMTP id d2e1a72fcca58-82a78cd64a0mr422801b3a.13.1773843332696; Wed, 18 Mar 2026 07:15:32 -0700 (PDT) From: Trieu Huynh To: qemu-devel@nongnu.org Cc: Trieu Huynh , Anthony Krowiak , Jagannathan Raman , "Maciej S . Szmigiero" , Matthew Rosato , Elena Ufimtseva , Halil Pasic , Jason Herne , Cornelia Huck , Eric Farman , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , "Michael S. Tsirkin" , Stefano Garzarella , qemu-s390x@nongnu.org (open list:vfio-ap) Subject: [PATCH v3 3/4] util/event_notifier: fix error handling for event_notifier_init callers Date: Wed, 18 Mar 2026 23:14:12 +0900 Message-ID: <20260318141415.8538-4-vikingtc4@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318141415.8538-1-vikingtc4@gmail.com> References: <20260318141415.8538-1-vikingtc4@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=vikingtc4@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1773843368793154100 Content-Type: text/plain; charset="utf-8" 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 Acked-by: Anthony Krowiak Reviewed-by: Jagannathan Raman Reviewed-by: Maciej S. Szmigiero # for the Hy= per-V part Reviewed-by: Matthew Rosato --- hw/hyperv/hyperv.c | 4 ++-- hw/hyperv/vmbus.c | 4 ++-- hw/remote/proxy.c | 15 +++++++++++++-- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/pci-quirks.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/vhost-vdpa.c | 4 ++-- 8 files changed, 23 insertions(+), 12 deletions(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 27e323a819..aa278b179e 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -439,7 +439,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, u= int32_t sint, sint_route->staged_msg->cb_data =3D cb_data; =20 r =3D event_notifier_init(ack_notifier, false); - if (r) { + if (r < 0) { goto cleanup_err_sint; } event_notifier_set_handler(ack_notifier, sint_ack_handler); @@ -453,7 +453,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, u= int32_t sint, =20 /* We need to setup a GSI for this SintRoute */ r =3D event_notifier_init(&sint_route->sint_set_notifier, false); - if (r) { + if (r < 0) { goto cleanup_err_sint; } =20 diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c index 64abe4c4c1..5388f4277f 100644 --- a/hw/hyperv/vmbus.c +++ b/hw/hyperv/vmbus.c @@ -1432,7 +1432,7 @@ static void open_channel(VMBusChannel *chan) goto put_gpadl; } =20 - if (event_notifier_init(&chan->notifier, 0)) { + if (event_notifier_init(&chan->notifier, 0) < 0) { goto put_gpadl; } =20 @@ -2450,7 +2450,7 @@ static void vmbus_realize(BusState *bus, Error **errp) } =20 ret =3D event_notifier_init(&vmbus->notifier, 0); - if (ret !=3D 0) { + if (ret < 0) { error_setg(errp, "event notifier failed to init with %d", ret); goto remove_msg_handler; } diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index 5081d67e7f..e91566509f 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -52,9 +52,20 @@ static void setup_irqfd(PCIProxyDev *dev) PCIDevice *pci_dev =3D PCI_DEVICE(dev); MPQemuMsg msg; Error *local_err =3D NULL; + int ret =3D 0; =20 - event_notifier_init(&dev->intr, 0); - event_notifier_init(&dev->resample, 0); + ret =3D event_notifier_init(&dev->intr, 0); + if (ret < 0) { + error_report("Failed to init intr notifier: %s", strerror(-ret)); + return; + } + + ret =3D event_notifier_init(&dev->resample, 0); + if (ret < 0) { + error_report("Failed to init resample notifier: %s", strerror(-ret= )); + event_notifier_cleanup(&dev->intr); + return; + } =20 memset(&msg, 0, sizeof(MPQemuMsg)); msg.cmd =3D MPQEMU_CMD_SET_IRQFD; diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index e58a0169af..5c8f305653 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -180,7 +180,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice = *vapdev, return false; } =20 - if (event_notifier_init(notifier, 0)) { + if (event_notifier_init(notifier, 0) < 0) { error_setg_errno(errp, errno, "vfio: Unable to init event notifier for irq (%d)= ", irq); diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 2251facb35..ce9c014e6a 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -418,7 +418,7 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevic= e *vcdev, return false; } =20 - if (event_notifier_init(notifier, 0)) { + if (event_notifier_init(notifier, 0) < 0) { error_setg_errno(errp, errno, "vfio: Unable to init event notifier for irq (%d)= ", irq); diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index 7b907b9360..66e02b15a4 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -318,7 +318,7 @@ static VFIOIOEventFD *vfio_ioeventfd_init(VFIOPCIDevice= *vdev, =20 ioeventfd =3D g_malloc0(sizeof(*ioeventfd)); =20 - if (event_notifier_init(&ioeventfd->e, 0)) { + if (event_notifier_init(&ioeventfd->e, 0) < 0) { g_free(ioeventfd); return NULL; } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 94c174a773..1945751ffd 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -70,7 +70,7 @@ static bool vfio_notifier_init(VFIOPCIDevice *vdev, Event= Notifier *e, } =20 ret =3D event_notifier_init(e, 0); - if (ret) { + if (ret < 0) { error_setg_errno(errp, -ret, "vfio_notifier_init %s failed", name); return false; } diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 2f8f11df86..9c7634e243 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1075,13 +1075,13 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev = *dev, int r; =20 r =3D event_notifier_init(&svq->hdev_kick, 0); - if (r !=3D 0) { + if (r < 0) { error_setg_errno(errp, -r, "Couldn't create kick event notifier"); goto err_init_hdev_kick; } =20 r =3D event_notifier_init(&svq->hdev_call, 0); - if (r !=3D 0) { + if (r < 0) { error_setg_errno(errp, -r, "Couldn't create call event notifier"); goto err_init_hdev_call; } --=20 2.43.0