From nobody Tue Apr 7 19:55:52 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=1773254144; cv=none; d=zohomail.com; s=zohoarc; b=Fw7cbOtdgGdu1+0sX/k6jwYMqh8u4aS6hhWuj4MWfIM2dXCNrwHBSenwKKLdzfoCjaBtGaB/V/Sg/s30AL2J6oKp018+N3sMLVFoN86k1fT4txML/HpxiXevkQV18KOILxNI5KF10lUl1iaTOO2cnzDgwJQaREdvh7OsI1TDvoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773254144; 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=z5KdpHl8lQZVz4X9aIb/yvs6ATdm7ngkD8mEgd4aj+s=; b=k69VdMuxZDMS9sH2Q+99+78VoiSuv6BFmddIiZECYEKLw16nGAQvBK0bc8CQ96G83AAoN2zfq5f2rzQ3cx9vMEDu4z+r7Rr1k4YFXju39wGOGTo5fCkm5AsCZ96VhIzoIUp7O/AMmZ2iXuddg1FR1yI6a+VqnExwIXR5PAy5fW8= 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 1773254144939145.90204288491634; Wed, 11 Mar 2026 11:35:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0OOj-0004ip-GS; Wed, 11 Mar 2026 14:35:09 -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 1w0OOh-0004fB-Gs for qemu-devel@nongnu.org; Wed, 11 Mar 2026 14:35:07 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w0OOf-0000iT-IG for qemu-devel@nongnu.org; Wed, 11 Mar 2026 14:35:07 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2ae5423b02aso1930725ad.1 for ; Wed, 11 Mar 2026 11:35:05 -0700 (PDT) Received: from localhost.localdomain ([123.19.166.13]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aeae222e2fsm42124115ad.2.2026.03.11.11.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 11:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773254104; x=1773858904; 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=z5KdpHl8lQZVz4X9aIb/yvs6ATdm7ngkD8mEgd4aj+s=; b=iUYIL58ChtIOgQpO8LeyYa2K/FDuK61e1rPoxKMujcG8a0H1T/sL61S+xqFwyZbxNO RXOvvb7RsnFfNQV2lgNXYCM1IuNfF0T9rO4bGxaCSsh9ifPlDnErGqoLorabk4QXWx6Q 8iZws2NbbXdM0lcdEa/bDBsvcNjLciRQyJUde0ousylxNTFEN2NcNEsVR8V8wLNETJoe edALXsIuZM0Y5Eb8nb6KszNx3JaAJuVTty5fXsWp31QcHr2pU9Tis6TN4wZEraigEHZJ UlmYlq7UVUVYoUJrE20dI/KiVGBpbAZLYes/aQ+XKbdscnoPncL964nxx1fbeIudN3po p6Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773254104; x=1773858904; 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=z5KdpHl8lQZVz4X9aIb/yvs6ATdm7ngkD8mEgd4aj+s=; b=DJrFvRW60JplAaUP6BmlePBU9ZN8NcXQcFJg7AYRVkejSYFU6M/eDvJU6XgPg+Xb2T XqRpUYKpijgnUwX6WFkthoutgz3/DC7hh7LtIu+ElVfvKmPJgL2Ik9Bm82nAoDfK9qRI tgeeWa1ajswhhDBepVm3GQu4BbSnTbI67/k9UK15hpLv6bUM2lK4F376crPdeQB28MOJ tjrrwK7+73edURVXwuswdV9boKlv8K722tUxIYmS8Y4zHTtcf46vC3+Ttkubp/rfV3Dg k2SiTamyLp9BVjcdRz8UZ8lY+KNoEaTwaYqezOKSGaZ0Sh3hslP5Bac/MFVX/mMh1bI+ rzWQ== X-Gm-Message-State: AOJu0YzPFKgXVA16BsTwWBzH5o1YbSaRu/BgaHeZ9Ea3F+5NnacMG7dL YxwHmJnYG+7xVEfCwHqZgJ7KdTPWP8sweqcGZz+CA8xdHm6Jr7c6EU81K77XqCsnKwNi4g== X-Gm-Gg: ATEYQzykTWTlveLUGfU8HsM4jrhiwFJJq6P5fVWrKz4EIwH1AQGbW3URDRei4s8oMtm 1xP+9hkE95MunWoTUthfvGjkKxLG5bZFZxDrJSFJJW8NSKWNiS+SX+vZycGaD30kkD7xC6HgTox TlOhExmJ4pPkVmfBM6jaWNjLMeuxbJu9IX+km3EjJQj99VVbWjD37bwSRe/hb5N4swkdBfl6/wl mCDxj/fhuAbEZ/SBsPQIt/fR4mzFL8MXHDz/chgGRVPnqRwTTzID0tsJJ+r7QIYLpEkdMziEpx9 Ekdfoe1lnzhCHCvHvhGscSKbXoJOGSLCpVBTr2xHyO68chc92wGvUnlDQGz/A/1Iy1NRkY+fMiY sLd7hcg4z52E+rWiAduJjjsYzM69V/U1geQaelOx4hQprDFwQOd0NxJiftAxA3EF78Dl7qaU1Uz v856DZo305JbTytvL3tpyUu8MUxOljKcQpjXYbD4Yw7UldBw== X-Received: by 2002:a17:903:2348:b0:2ae:4150:3125 with SMTP id d9443c01a7336-2aeae7dfcfdmr36539825ad.17.1773254103631; Wed, 11 Mar 2026 11:35:03 -0700 (PDT) From: Trieu Huynh X-Google-Original-From: Trieu Huynh To: qemu-devel@nongnu.org Cc: Trieu Huynh , Richard Henderson , Helge Deller , Thomas Huth , Laurent Vivier , "Edgar E. Iglesias" Subject: [PATCH v2 1/4] hw/core/loader: fix error handling for load_image_targphys callers Date: Thu, 12 Mar 2026 01:34:27 +0700 Message-ID: <20260311183432.214960-2-viking4@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260311183432.214960-1-viking4@gmail.com> References: <20260311183432.214960-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::634; envelope-from=vikingtc4@gmail.com; helo=mail-pl1-x634.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: 1773254148285154100 Content-Type: text/plain; charset="utf-8" From: Trieu Huynh Use QEMU's Error API to handle load_image_targphys() failures consistently across callers. - Use &error_fatal for callers that previously passed NULL, ensuring the process exits early on failure instead of continuing in an invalid state. - No functional changes. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413 Signed-off-by: Trieu Huynh --- v2: - Use &error_fatal instead of manual return value checks. - Remove redundant checks for ppc callers that already use &error_fatal. - Note: This replaces the "ret < 0" approach proposed in v1. --- hw/alpha/dp264.c | 2 +- hw/hppa/machine.c | 2 +- hw/m68k/next-cube.c | 2 +- hw/m68k/q800.c | 2 +- hw/m68k/virt.c | 2 +- hw/microblaze/boot.c | 3 ++- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c index 98219f0456..2ab3c14747 100644 --- a/hw/alpha/dp264.c +++ b/hw/alpha/dp264.c @@ -190,7 +190,7 @@ static void clipper_init(MachineState *machine) /* Put the initrd image as high in memory as possible. */ initrd_base =3D (ram_size - initrd_size) & TARGET_PAGE_MASK; load_image_targphys(initrd_filename, initrd_base, - ram_size - initrd_base, NULL); + ram_size - initrd_base, &error_fatal); =20 address_space_stq_le(&address_space_memory, param_offset + 0x1= 00, initrd_base + 0xfffffc0000000000ULL, diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index ec63dc1297..99a4c22c73 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -507,7 +507,7 @@ static void machine_HP_common_init_tail(MachineState *m= achine, PCIBus *pci_bus, } =20 load_image_targphys(initrd_filename, initrd_base, initrd_size, - NULL); + &error_fatal); cpu[0]->env.initrd_base =3D initrd_base; cpu[0]->env.initrd_end =3D initrd_base + initrd_size; } diff --git a/hw/m68k/next-cube.c b/hw/m68k/next-cube.c index 26177c7b86..4bc8e72f3e 100644 --- a/hw/m68k/next-cube.c +++ b/hw/m68k/next-cube.c @@ -1326,7 +1326,7 @@ static void next_cube_init(MachineState *machine) memory_region_init_alias(&m->rom2, NULL, "next.rom2", &m->rom, 0x0, 0x20000); memory_region_add_subregion(sysmem, 0x0, &m->rom2); - if (load_image_targphys(bios_name, 0x01000000, 0x20000, NULL) < 8) { + if (load_image_targphys(bios_name, 0x01000000, 0x20000, &error_fatal) = < 8) { if (!qtest_enabled()) { error_report("Failed to load firmware '%s'.", bios_name); } diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c index ded531394e..c0d78eb7d7 100644 --- a/hw/m68k/q800.c +++ b/hw/m68k/q800.c @@ -633,7 +633,7 @@ static void q800_machine_init(MachineState *machine) =20 initrd_base =3D (ram_size - initrd_size) & TARGET_PAGE_MASK; load_image_targphys(initrd_filename, initrd_base, - ram_size - initrd_base, NULL); + ram_size - initrd_base, &error_fatal); BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base, initrd_size); } else { diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c index e67900c727..ffe6e23415 100644 --- a/hw/m68k/virt.c +++ b/hw/m68k/virt.c @@ -292,7 +292,7 @@ static void virt_init(MachineState *machine) =20 initrd_base =3D (ram_size - initrd_size) & TARGET_PAGE_MASK; load_image_targphys(initrd_filename, initrd_base, - ram_size - initrd_base, NULL); + ram_size - initrd_base, &error_fatal); BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base, initrd_size); } else { diff --git a/hw/microblaze/boot.c b/hw/microblaze/boot.c index a6f9ebab90..4ad5ffd34b 100644 --- a/hw/microblaze/boot.c +++ b/hw/microblaze/boot.c @@ -38,6 +38,7 @@ #include "hw/core/loader.h" #include "elf.h" #include "qemu/cutils.h" +#include "qapi/error.h" =20 #include "boot.h" =20 @@ -171,7 +172,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, bool is= _little_endian, /* Not an ELF image nor an u-boot image, try a RAW image. */ if (kernel_size < 0) { kernel_size =3D load_image_targphys(kernel_filename, ddr_base, - ramsize, NULL); + ramsize, &error_fatal); boot_info.bootstrap_pc =3D ddr_base; high =3D (ddr_base + kernel_size + 3) & ~3; } --=20 2.43.0 From nobody Tue Apr 7 19:55:52 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=1773254167; cv=none; d=zohomail.com; s=zohoarc; b=EpVzenpREvydWeDasl+L/WXRkMpY+smZcuiR+1YGyuycMgJ7kwZd1MpJuhTKdzTgfLCMNm6TfGB6OAZaI3RBWah1FSfJVDDCT7Jax3TnMSS4RR8hsYptxeX60BYgtkmkP7abpRbW9kwo0V42OXJbcAL7mIh+IOjj9tTvEsA+dWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773254167; 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=RNM/dVkkML5tzgLzxAijspCwne80ByQcKUUWMceF6EY=; b=JmEo9LYd1Stg54TfLlg5SH5CrhvivpI/XYrVFo3RlbsT8a7xmx1yD91OBPzAripITbkbZdKKeV9nfuQnZrVFMGts9iRuVJYoC1MKqm9BxR0fgxbHal1vZHl5n39RJl1X7XPsSxX2PhFi07QyuIzQ8ogh1KmEya00LU/02oMpW4E= 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 1773254167528982.7209387246529; Wed, 11 Mar 2026 11:36:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0OOn-0004ne-BR; Wed, 11 Mar 2026 14:35:13 -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 1w0OOl-0004jE-3C for qemu-devel@nongnu.org; Wed, 11 Mar 2026 14:35:11 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w0OOj-0000jO-CJ for qemu-devel@nongnu.org; Wed, 11 Mar 2026 14:35:10 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2ae43042ea7so3061115ad.0 for ; Wed, 11 Mar 2026 11:35:09 -0700 (PDT) Received: from localhost.localdomain ([123.19.166.13]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aeae222e2fsm42124115ad.2.2026.03.11.11.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 11:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773254107; x=1773858907; 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=RNM/dVkkML5tzgLzxAijspCwne80ByQcKUUWMceF6EY=; b=jYImN7sJVtlVRQSUwKisn81gxPApIvvzm694SitsegN8XF/SeOdkRZXeXNWFecyvdh Ary4kGtRDQ/WdUfCmZT0/4Nl/rbV/ZZVFL8pfRVSLEVC5JxSgO89q9noFhi4Jh5hFnmT R5SbJQ6qFl7B3xVhiIDQ2z/CKRvOAZYKS+wiZE7IKqHahnEBN5R+TifW1G6XUEZrICoV ZnzXa5EUxhV2Vye1TgNWZ9d64em+ghs7uO7Rq++gcWuA9ombNdFKv0byyptdIOkHhWr+ z7tsiuT3ngqMzJdCjzGrYzDOsckkFMQU+cjfYKMi68aXaIeEyrgCWG+Yk05cInJIlzkg aloA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773254107; x=1773858907; 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=RNM/dVkkML5tzgLzxAijspCwne80ByQcKUUWMceF6EY=; b=ZxKI2IWlBY2BDKTjR0P3iNhMYSg1H/YKEWwZZIm8NLhcS2zvJzBdvkHGO1bgt3WdmH /Rjdh4Y+nF0roaiLZqab8wBZ0Tp5fl458i3Z1mrnc+ERjbIgXGzHoOU2T33r3Z649LbE N0PxDv7Cd6IT6o/DymQDC7vYdB1TbdiUx+oZnlPUAYUbeS3PitEp8d3fwX3OrrjAiyDE byMmlQmDoSseemLcri0dnQck9N53Cj0qs6af0IQapmxFr1xXB1EhjrNUljbeO5cpn7dP G/KzW4PXZzEWePEwrqJMKgVCs3uT/JBkGzj7cgzlSgTYJksuhcXciKoLa1kFD0SfZUt7 dsfA== X-Gm-Message-State: AOJu0YykM4tk8mODMTZUxXzFZmqHUiDzUz+vTK7J/7d2J3C7KzWsW5m4 WHRRvUIAAKVqxrxcuJEx/OIC56vi4W17gFo2Bdri9O9PpAagmyYZL9DxlWa2m4NYHm3mQg== X-Gm-Gg: ATEYQzw4CmADQwHPgODfq8yriD2emkz8JvlSQhmd0kdgSwfyKhuY0Nz1iWhHlZ0dNqo 6DjEk4WH27wDWJQ5NcjyNFXHzLhexaUNUlnDRbZKyO+xAWMu4uChgd2QKrYphRlA0C4xgtERzFC J7ncy7qVze3AoeoeCHO4Jp0ZKubuZOwwBmNK9Lif+wQeU6YeE50ZXxmNF8OWQukthELqvqyhP20 tPZwRMWcLW2tdaxU664WWggt+ve44yq59JTDx9z1q286a9JH/1V0G0pSsDu53OzH7HobMHzxAqQ tncas2UhDMUNguRiY0qgw8DsBWgJmkLPSquZZAxFcGaA5kgAJLORtmc7sXd4nkGogo77BwjUcu/ EZhLWZDVL7h9bASrhRAHbJmh4QitqVpHdvP/swVnLnET5GoDNeOfNzjN+l9iUmzHAJ8hMefngNG qC0t64raSQboGX9navYy64B28jBCP9/q76u2IA2tIycuSUcQ== X-Received: by 2002:a17:902:e80b:b0:2ae:80d5:bfa7 with SMTP id d9443c01a7336-2aeae76f5famr37277905ad.7.1773254107247; Wed, 11 Mar 2026 11:35:07 -0700 (PDT) From: Trieu Huynh X-Google-Original-From: Trieu Huynh To: qemu-devel@nongnu.org Cc: Trieu Huynh , Corey Minyard , =?UTF-8?q?Cl=C3=A9ment=20Chigot?= , Frederic Konrad , Mark Cave-Ayland , Artyom Tarasenko Subject: [PATCH v2 2/4] hw/core/loader: fix error handling for get_image_size callers Date: Thu, 12 Mar 2026 01:34:28 +0700 Message-ID: <20260311183432.214960-3-viking4@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260311183432.214960-1-viking4@gmail.com> References: <20260311183432.214960-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::62a; envelope-from=vikingtc4@gmail.com; helo=mail-pl1-x62a.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: 1773254168641158500 Content-Type: text/plain; charset="utf-8" From: Trieu Huynh Check the return value of get_image_size() and report failures for non-mandatory files such as BIOS or FRU images. - Use ret < 0 to detect failures in getting image size. - No functional changes. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413 Signed-off-by: Trieu Huynh --- v2: - Keep error reporting as it is. - Remove exit on error since it is not mandatory. --- hw/ipmi/ipmi_bmc_sim.c | 2 ++ hw/sparc/leon3.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c index 012e2ee4fe..fd875491f5 100644 --- a/hw/ipmi/ipmi_bmc_sim.c +++ b/hw/ipmi/ipmi_bmc_sim.c @@ -2561,6 +2561,8 @@ static void ipmi_fru_init(IPMIFru *fru) g_free(fru->data); fru->data =3D NULL; } + } else { + error_report("Could not get file size '%s'", fru->filename); } =20 out: diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c index 9147d56bd4..122366829d 100644 --- a/hw/sparc/leon3.c +++ b/hw/sparc/leon3.c @@ -354,6 +354,10 @@ static void leon3_generic_hw_init(MachineState *machin= e) } else { bios_size =3D -1; } + if (bios_size < 0) { + error_report("could not found or failed to get file size: '%s'", + filename); + } =20 if (bios_size > prom_size) { error_report("could not load prom '%s': file too big", filename); --=20 2.43.0 From nobody Tue Apr 7 19:55:52 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=1773254166; cv=none; d=zohomail.com; s=zohoarc; b=XEW9vHpYxgSrp21XRGGUV/AKW/3UdI/M+VvncDcQ++3gB6Lo5L2aFqbKj+wFxJcuOvLdtvYKedPsbKKMNqu/d8wOIE7BR6U+f39XVb2rk5OlUQ/pf9jNZ0qHmlRA7pcyRzIwS8GmKkOznlU+TA0b/2mZQc55AvcL8CJJpskRrCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773254166; 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=vEGrUNVPcQF125YpSiWYiQ37cQPYi06xBjgPkk+Wxd0=; b=DNFEJAosx7dmpll2QFW3W3VofiZva4SGcSWdjWMH4a6yiy6zilYM+cdA0WcZM+k9kP0T45A7Y/+FFJuux8cbvJT62admaBek8JnhTfUGuSnoBFmt8Q0ht4hPSmtJVFgS5KUtS1eLSuTrFfVsfjSDLMyyqUcb0KGBTrnGeyyqzdU= 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 1773254166365816.0647675509343; Wed, 11 Mar 2026 11:36:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0OOu-0004q8-Dj; Wed, 11 Mar 2026 14:35:20 -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 1w0OOs-0004pk-8a for qemu-devel@nongnu.org; Wed, 11 Mar 2026 14:35:18 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w0OOq-0000ky-Gk for qemu-devel@nongnu.org; Wed, 11 Mar 2026 14:35:17 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2ad4d639db3so1681245ad.0 for ; Wed, 11 Mar 2026 11:35:16 -0700 (PDT) Received: from localhost.localdomain ([123.19.166.13]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aeae222e2fsm42124115ad.2.2026.03.11.11.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 11:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773254115; x=1773858915; 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=vEGrUNVPcQF125YpSiWYiQ37cQPYi06xBjgPkk+Wxd0=; b=RD4g9us7mUKR9qBmOkZ7BDBo4bg+ngSpNXYTHTVLlXZxyA5G9kJca7smlkGLhprhir SzKXnxMg8bgf6v9dKqdqJLWO4jImvIgg2eM9te4lyh2VdvZVV3xcMIOQfZofJ4J5IVsT 93cPkmS+fHZZmq4CR3K8pJF3tG5jOJJuyEeLVUzGQWgfXYjuPcqQs7bzsV6bo9+k97zj ePSDnqFBaTj9kDx3x2pkJcVofqaP7mDEo9uh5SVHu73rF3ftImOwEbTtSpVQvNaRObFK 1BKy4VBwewR42346cZQY9eolL6R0ohJ+qUtCtsWTOG/deBJgPcuCdfWUi38lmbgJu4K5 DoYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773254115; x=1773858915; 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=vEGrUNVPcQF125YpSiWYiQ37cQPYi06xBjgPkk+Wxd0=; b=ooS0eXas+NG5HTB21pO7SrxI5h6fBKy7iPjtgqONQbzVrTIkIjku5UeLw4YhR3gG93 C/PkcmUgbriU8o0HztQZ8bN6PCjVr5WiE4Sfk+pgcSYC//b3tjSc4QaKWWTmTvDXHx6J b7LNwMIHHFpBEM2BabIexpMaADLqe4fB1/YW3+Nhf2J6F+7b8XV1Z9AB1LL/25DotSom MTFXdw85Mrvs+9RSp0NRjh7n09MnBi37vwRTrzjltFkJVjOkudY4EA/6ao0BF6V41GN9 wEesexK6AbqQacZV9HQxJrTXYjTA1kvNuPSv6tTRnTPE/0fbWNQGrid84gOROHD3e8Of xeug== X-Gm-Message-State: AOJu0YwVCVRhQrIGOseUAXXFKCDqB/zl1FlyeWyO6v4nMVckE15zD4Kj k63bbZJ1mcvnGrTb2o21Vh7oWkAsS+kRnbInbm2j4+iMEpTr8+2lYCS1LYJdDtNkxJTvEA== X-Gm-Gg: ATEYQzzQUNqQQ/GIVviSfQdL7we4yuYTfRO/uaDwcL3uUOM6bGtnnmu/nbBzsKPoIXM r0Vf1FklU/iwAycW4QyhiJoaO1g2XUzmdK49uCXrU+5wNrj80UNgGa6X0S+iIDqvsdDs3fDf3LH t1BBOuECOan9oYI2T7I2rp5Lzasp/H8NDmL5dy3o4/5/HG4VdayJa8jcpkf2BHFZARLr5Fb0wQL nGaIg33sUEDE8MjVdK8SsQBGxf4+iJebLNkc0E1vyMuiyGr9F56Mv7kgjenOx3YFL0JKPONGqca iOOQHJZC0yoeGlVUcCd2xZPIQbitVfeXs9HXLhNxwi1uq2xDHvgYsnjlL/wp261q7t4yYOVs74N g8re28wicRbMO5xq7xh6XS3lvt0PBunzlCwx1vyqo1GBS11y6SI7X1v/Q1K/1hcNNzVRm+BENGN IPrmJ/vM6G0K/8SJ8+UXqYAT33O70LbMZoL6XTh07cXbyBgw== X-Received: by 2002:a17:903:2a88:b0:2ae:7f70:b2aa with SMTP id d9443c01a7336-2aeae892fadmr40728955ad.29.1773254114898; Wed, 11 Mar 2026 11:35:14 -0700 (PDT) From: Trieu Huynh X-Google-Original-From: Trieu Huynh To: qemu-devel@nongnu.org Cc: Trieu Huynh , Anthony Krowiak , Jagannathan Raman , "Maciej S. Szmigiero" , Elena Ufimtseva , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Halil Pasic , Jason Herne , Thomas Huth , Eric Farman , Matthew Rosato , "Michael S. Tsirkin" , Stefano Garzarella , qemu-s390x@nongnu.org (open list:vfio-ap) Subject: [PATCH v2 3/4] util/event_notifier: fix error handling for event_notifier_init callers Date: Thu, 12 Mar 2026 01:34:29 +0700 Message-ID: <20260311183432.214960-4-viking4@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260311183432.214960-1-viking4@gmail.com> References: <20260311183432.214960-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::630; envelope-from=vikingtc4@gmail.com; helo=mail-pl1-x630.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: 1773254168572158500 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: Anthony Krowiak Reviewed-by: Jagannathan Raman Reviewed-by: C=C3=A9dric Le Goater 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 From nobody Tue Apr 7 19:55:53 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=1773254139; cv=none; d=zohomail.com; s=zohoarc; b=Ot+kIz6O+NkYxbgknprxRUaFXSms0MBZPGstLlY7WC5EM2QkMbk8CKy8KQZS35hZs4/4jX+qHnKKif6V5b248bcydxt/hWMzrH4uG+ID6Ia/Z+hHNwqvq1QjJ10qwAust4UVVfWPDELKXYFYnEyotQq/hoE1H5Cec5e+6/G3MnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773254139; 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=laRsm3TUDdJSpfAUPBx12/AjumPgyQ9OTcdCV3+erMI=; b=Ug32336jPid+L6V5J9vx/cereITot24ht0BdQzCyKfjf5rjY5H1pUxoeXMsF+CvtJAUB7dLgTYGMSYYnxCIs1aYXO4WQoamzJ8Z3gQxMcxANP3eJVxSrDJYNxLFIVnBJ8JlhhmngdKL73WqNcI856Vw6hKTvOtjyO/PvSnr/Sbo= 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 1773254139524645.3941482565713; Wed, 11 Mar 2026 11:35:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0OP0-0004tX-II; Wed, 11 Mar 2026 14:35:26 -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 1w0OOz-0004sA-3a for qemu-devel@nongnu.org; Wed, 11 Mar 2026 14:35:25 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w0OOw-0000m9-U1 for qemu-devel@nongnu.org; Wed, 11 Mar 2026 14:35:24 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2ad21f437eeso2310425ad.0 for ; Wed, 11 Mar 2026 11:35:22 -0700 (PDT) Received: from localhost.localdomain ([123.19.166.13]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aeae222e2fsm42124115ad.2.2026.03.11.11.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 11:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773254121; x=1773858921; 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=laRsm3TUDdJSpfAUPBx12/AjumPgyQ9OTcdCV3+erMI=; b=EwknB44rxSRT9848t4bsmDqoDH+cWpThB0+03grh5hfGNwFQHUzM9QAcdNZLfmK4Cr c4/DV1qo669n/NkXU4G7mkrELYogi1YHA7fZB5AjqI3GYUgttPIr4p1NDd/pHOSUN9R3 9PAvq0O+SMSmHJY9RUe62Qj0fbJXh93//PpBq+botPG5E74uDBY6GP+fESlTDETAzp/R td7aztiS726WYlkbQcadtwE+tn4uQK/W+sU1cs5TUH+xWmEj4lyyKEuiEUDglvi0Snxv olKEhJzFmV354wt3GQhuv1vPS2ZzSBKI80hUrLf5CqeA9rOE0iOXkDLKwWYMRTinHIzb OIGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773254121; x=1773858921; 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=laRsm3TUDdJSpfAUPBx12/AjumPgyQ9OTcdCV3+erMI=; b=Uh1jsx1Xs8Mb2ogecY20nM6o86CysF9tsR++4kMJZ9HC1IUTftq+mDIt0kRdjxPmp5 2gcsP1d8m8a5oxANUCs1z8aHsh7C6+BQQrg6KQZ1SwPJ5be3FQZhXMivc8v33kYnmEJj Btnt7c54a4hLuluV3yIOzkCKQX8pGQ1KornnvXLxIqWcSnp1lfCxGWV261nPEeKLU+Lr hQXLuSlaBUa5LanNKYvXdVYPTm14sxZnz4FbA0c8DgpY7DZTnuWIYZmyRv1Qp3Zc2+MP PxdBjqk69vxpFBv8xB6mUM3w9raEBPX1v+0cigGd60ZxhtIEExzqiJ4A5d2nuc/Qcwp5 4Irw== X-Gm-Message-State: AOJu0Yyt5JksbWkd3Scu4ZRUg8+/RwlZ0PgCCaMNHkd4dqm/4N0YtvGb /xnQdlJJK2fq5cGU6SdHqQW+h3hw8gHfbXnPQIsQUG2R2qs5YQ7Xd4ubzd/Tbvf3KQeyGw== X-Gm-Gg: ATEYQzwTZb+uEeyAS7cu31rmP0V/uOFknIBqFHN3e63GUTP+sLyutTrDDyDvXGq3nuQ PsWYskZwnnX9cHNvw56xKkigzc/g2gWWt4hxLwh92VqB63DoHqW6VdsA33JjjG0bvx4BNCxfcYy vp8s1qqaTdAd9tu/a+iK1hWGyn/Dh2FLnLW2ugrXNNwtch10LTqQKrufn2F/Zbr7saFgjARBmlf jjEc/5j40EdlxcmNcT3Wvvx36CsqYjwy2lekov3HUR+c4v2i8g7GRG23ewN3HS39KBcr2/TlZbD G+Y7x89s4ADLS0IR+pNk2khfzvn8Zs7aD6aJQEwuUm3QEx8TSIxGGwhsgxhReE6wHZdsr6NvR3z b2SxG4NQJd/be0FgG9XjAI1YjY40E9gaDfC+Yc1CWcDN0earfI6URj1ZEQXcaUQR88scwKeoxPI 3VmrVnL0iRLq0Qk9Gcqyf5Wp/2IlGf7osJ71HLTq9kqqX5jQ== X-Received: by 2002:a17:902:f543:b0:2ad:a96c:e40c with SMTP id d9443c01a7336-2aeba4bd825mr4186295ad.16.1773254121284; Wed, 11 Mar 2026 11:35:21 -0700 (PDT) From: Trieu Huynh X-Google-Original-From: Trieu Huynh To: qemu-devel@nongnu.org Cc: Trieu Huynh , Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Jiri Pirko , "Michael S. Tsirkin" , Marcel Apfelbaum , Paolo Bonzini , Fam Zheng , Hannes Reinecke , qemu-block@nongnu.org (open list:megasas) Subject: [PATCH v2 4/4] hw/pci/msix: fix error handling for msix_init callers Date: Thu, 12 Mar 2026 01:34:30 +0700 Message-ID: <20260311183432.214960-5-viking4@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260311183432.214960-1-viking4@gmail.com> References: <20260311183432.214960-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::632; envelope-from=vikingtc4@gmail.com; helo=mail-pl1-x632.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: 1773254140623158500 Content-Type: text/plain; charset="utf-8" From: Trieu Huynh Check return value of msix_init() and return early on failure instead of continuing with invalid state. - Use ret < 0 to handle negative return value. - Use errp parameter to handle failure instead of NULL. - No functional changes. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413 Signed-off-by: Trieu Huynh --- v2: - Use errp parameter to handle failure instead of NULL. --- hw/net/igbvf.c | 2 +- hw/net/rocker/rocker.c | 2 +- hw/pci/msix.c | 2 +- hw/scsi/megasas.c | 18 +++++++++++++----- hw/usb/hcd-xhci-pci.c | 19 ++++++++++++++----- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/hw/net/igbvf.c b/hw/net/igbvf.c index 48d56e43ac..9a165c7063 100644 --- a/hw/net/igbvf.c +++ b/hw/net/igbvf.c @@ -260,7 +260,7 @@ static void igbvf_pci_realize(PCIDevice *dev, Error **e= rrp) =20 ret =3D msix_init(dev, IGBVF_MSIX_VEC_NUM, &s->msix, IGBVF_MSIX_BAR_ID= X, 0, &s->msix, IGBVF_MSIX_BAR_IDX, 0x2000, 0x70, errp); - if (ret) { + if (ret < 0) { return; } =20 diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c index 4a7056bd45..910dce901b 100644 --- a/hw/net/rocker/rocker.c +++ b/hw/net/rocker/rocker.c @@ -1228,7 +1228,7 @@ static int rocker_msix_init(Rocker *r, Error **errp) &r->msix_bar, ROCKER_PCI_MSIX_BAR_IDX, ROCKER_PCI_MSIX_PBA_OFFSET, 0, errp); - if (err) { + if (err < 0) { return err; } =20 diff --git a/hw/pci/msix.c b/hw/pci/msix.c index b35476d057..1b23eaf100 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -432,7 +432,7 @@ int msix_init_exclusive_bar(PCIDevice *dev, uint32_t ne= ntries, 0, &dev->msix_exclusive_bar, bar_nr, bar_pba_offset, 0, errp); - if (ret) { + if (ret < 0) { return ret; } =20 diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index f62e420a91..b237ba7656 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -2380,11 +2380,19 @@ static void megasas_scsi_realize(PCIDevice *dev, Er= ror **errp) memory_region_init_io(&s->queue_io, OBJECT(s), &megasas_queue_ops, s, "megasas-queue", 0x40000); =20 - if (megasas_use_msix(s) && - msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000, - &s->mmio_io, b->mmio_bar, 0x3800, 0x68, NULL)) { - /* TODO: check msix_init's error, and should fail on msix=3Don */ - s->msix =3D ON_OFF_AUTO_OFF; + if (megasas_use_msix(s)) { + Error *local_err =3D NULL; + ret =3D msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000, + &s->mmio_io, b->mmio_bar, 0x3800, 0x68, &local_err= ); + + if (ret < 0) { + if (s->msix =3D=3D ON_OFF_AUTO_ON) { + error_propagate(errp, local_err); + return; + } + error_free(local_err); + s->msix =3D ON_OFF_AUTO_OFF; + } } =20 if (pci_is_express(dev)) { diff --git a/hw/usb/hcd-xhci-pci.c b/hw/usb/hcd-xhci-pci.c index aa570506fc..3bdde9b64a 100644 --- a/hw/usb/hcd-xhci-pci.c +++ b/hw/usb/hcd-xhci-pci.c @@ -173,11 +173,20 @@ static void usb_xhci_pci_realize(struct PCIDevice *de= v, Error **errp) } =20 if (s->msix !=3D ON_OFF_AUTO_OFF) { - /* TODO check for errors, and should fail when msix=3Don */ - msix_init(dev, s->xhci.numintrs, - &s->xhci.mem, 0, OFF_MSIX_TABLE, - &s->xhci.mem, 0, OFF_MSIX_PBA, - 0x90, NULL); + Error *local_err =3D NULL; + ret =3D msix_init(dev, s->xhci.numintrs, + &s->xhci.mem, 0, OFF_MSIX_TABLE, + &s->xhci.mem, 0, OFF_MSIX_PBA, + 0x90, &local_err); + + if (ret < 0) { + if (s->msix =3D=3D ON_OFF_AUTO_ON) { + error_propagate(errp, local_err); + return; + } + error_free(local_err); + s->msix =3D ON_OFF_AUTO_OFF; + } } s->xhci.as =3D pci_get_address_space(dev); } --=20 2.43.0