From nobody Wed Apr 8 05:01:56 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=1773167564; cv=none; d=zohomail.com; s=zohoarc; b=ltDiN6WrW9PPQHTb4vqEu3Utxg4TOTx4MMTqPsCzMtxL90e/MMcP0SlALC/OeziCeEB5MmBHSXjh79CblNBWYcgGSV0GNbaDfAFrz0eKjJS0c77d76DLFFgMjg4trKMk3iXfM2kkXb19/xXlUkqBYiBUVxLGdbAPm5FRNq8XhAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773167564; 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=YftEthnO5ZbHmCNgkv0qnfwkakmKxf+SOGKN2IGfTXs=; b=Bmuufox0M3CQPv0Sj0bKM6katP/lwzmeBeGgVcblepm1loeekuTWwBIYa5javIdQ08RFYo1iXqLPy33f3Nb3PiNOU3uLlwV7GOnbcP6J8CZEPLczSVU/gk+t5jg9HE129W0ihh2yV33UCzZ/wrT6p8FqNSoXcNVd02ZVHjya2yg= 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 1773167564078442.49666920790366; Tue, 10 Mar 2026 11:32:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w01sJ-000242-EU; Tue, 10 Mar 2026 14:32:11 -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 1w01sH-00023m-7Q for qemu-devel@nongnu.org; Tue, 10 Mar 2026 14:32:09 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w01sF-0007iB-GB for qemu-devel@nongnu.org; Tue, 10 Mar 2026 14:32:08 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-3598e7155bbso6549154a91.2 for ; Tue, 10 Mar 2026 11:32:07 -0700 (PDT) Received: from localhost.localdomain ([123.19.166.13]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ae840b2e9dsm209437015ad.85.2026.03.10.11.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2026 11:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773167526; x=1773772326; 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=YftEthnO5ZbHmCNgkv0qnfwkakmKxf+SOGKN2IGfTXs=; b=mRNEx2fbCsMgzTL2IalXcc9+sxhnrlIFHitDFTnZzvd2tZUkyAtpyO/uaJmbhkrHNu DnYIoNfczcI3da2NgFyhhsCls8ZKFVHyEob9vJb/hQ4ri3FrGw4+yXWKtnbejhRx12Et YvLYMY94eSmlDoT5FDWmdCHZl5IyWeIqbxesuB1gsO6s3QfSFJmgzMEMopVCyNysuTnx DHVjFy+/8fyGopmxjsm68YzF9cyXYLw14G9/nq9ir0EFq4ir+NfYq/7aritHGUG4Y0Y/ /sToW9Nd/bUvTi/0qhR45+TvEDUeturr+AbY51iAs11kZm16O1h3O3s4ORDJ1ge6GRFp 40Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773167526; x=1773772326; 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=YftEthnO5ZbHmCNgkv0qnfwkakmKxf+SOGKN2IGfTXs=; b=odSAKZif5eaKuOSah/jtudF2GJRnhmj7KMs4l5Km3zEBvEPfeVopkxPlmOOzMo0oRp c5u0nSI1MAug1Q8Ftd1f/yUR/rvIkLnzDhHWX5P5r8Uv2ECxVIF4OaxGW/cmoPg1zQg4 Yo5D6D1PpMtz2ezBrrUmhj0qf7OixstRzcjf6wHVe/ABuhFbR1MTm+dcq4xyEoRNOpit pNDSxasNMtIi5r9lmUZFSTC5wIfpt67qgpJ6YRA4SmAV9OnJV+rADCD1dopXVbXDhbNv pKaHzlhPE4lykX5rhLuGIyHHKCB8mJ2mMM1s9t5optk84GUT+hsvDg4QlZPkMvBni9CV NM4A== X-Gm-Message-State: AOJu0YxVmBMHiXtY2ahOMbU1MogEnhAyYb0iO6SZXoMTLBf5U+pKntkb BgLJXQ1XHMrcNEja1kKdsiPEUI88H3DTCgXpu3aU7CcrIsVnZ6jgNHFQ4Yqrj7wosIMSKQ== X-Gm-Gg: ATEYQzwhxQ+0/1LDRo3ZyXP16vX578H+S7rRQaC5EwrCuooOc4QXIc0Fp82L+XH1sSo g4Oxjwrt4SsLBktke7SsIZD2foBgz42Ck8JaCzYbg/3FPRjlaLW2YXnKgkH8TTk2KV9tUpC9VF0 K6r6BAeAw/cM/YMx4i4Kka/82KbwEDDDmtsxPrAkTwcyPvankMnmnQwvpMsKz9FmGS+KR6AJ5nE fiCLx6pQfoTBME337LH1puxzHtV96KJt/b9+3NNebPUxOHiDlM52lepUs2wmtTXAbSW3UMau2/D elIu2DShidnQHrpt8Nk7rO+fS9eZ5Fpovdi3drokNudQgfL9d8HlJWN46f68qPHHMT/pcYTgrZW aKHssOhUWRlw2De+E8aXoLax5ou1tM6INHOh1rp5TNtBheMTLvx9iUqkb0LCR/ah29A4xabimWc Y0AdVaeZdyHurXCqfxn1BNSp7oPqZpNEX1Dvr9acFUomU/Uw== X-Received: by 2002:a17:903:3845:b0:2ae:80a3:ca7d with SMTP id d9443c01a7336-2ae8246be97mr176422845ad.39.1773167525946; Tue, 10 Mar 2026 11:32:05 -0700 (PDT) From: Trieu Huynh X-Google-Original-From: Trieu Huynh To: qemu-devel@nongnu.org Cc: Trieu Huynh , "Maciej S. Szmigiero" , Elena Ufimtseva , Jagannathan Raman , Thomas Huth , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Tony Krowiak , Halil Pasic , Jason Herne , Eric Farman , Matthew Rosato , "Michael S. Tsirkin" , Stefano Garzarella , qemu-s390x@nongnu.org Subject: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers Date: Wed, 11 Mar 2026 01:27:59 +0700 Message-ID: <20260310182801.196443-4-viking4@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260310182801.196443-1-viking4@gmail.com> References: <20260310182801.196443-1-viking4@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::102d; envelope-from=vikingtc4@gmail.com; helo=mail-pj1-x102d.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: 1773167566558158500 Content-Type: text/plain; charset="utf-8" From: Trieu Huynh 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:=C2=A0 Anthony Krowiak Reviewed-by: Jagannathan Raman --- 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 c5bab5d245..2f0d2a03d8 100644 --- a/hw/hyperv/vmbus.c +++ b/hw/hyperv/vmbus.c @@ -1425,7 +1425,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 @@ -2416,7 +2416,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 c89f3fbea3..29bf6511b3 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