From nobody Wed Nov 19 13:54:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616083797; cv=none; d=zohomail.com; s=zohoarc; b=Pbx3tvwbQXs2FpYoqO5gCesUkXQlUvhJyDdMHxGvnCFXDDdMbK7dIco59Zl+TrqH2TAC4V9jHBvTxBao5fr+t6WZeM+Lxj64aiyBR7M6ijvi4pr63aZNZ5hRQKQ4btHtt8RczhQtTQZGKwWwuOhvHbYmW/1tQ2FlwgQ45WNzYlE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616083797; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=0ILZwEmglVjVyYz5F4sj1LV2EThGiB2LjCTP+JRuw5I=; b=mk+Zd03apRVc6xJwcnWzrrqL5biz80CbJJlOv5yIC5p1ZaNMoKXKJBkzglMRFz9MDncOU0zR94ANAy0gwZJM5PsT0Oa7nlAsPQJ3Rgr4L66DxF/x28/8Gbmh5HMebEktCghrSgsv8aYpDBWXWbGYAlOUoaScKWnXq7SDOLaACvM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1616083797545807.7063512753563; Thu, 18 Mar 2021 09:09:57 -0700 (PDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-192-AjJsmiNHMeuXEUm_IedPjQ-1; Thu, 18 Mar 2021 12:09:52 -0400 Received: by mail-wm1-f71.google.com with SMTP id v5so12032547wml.9 for ; Thu, 18 Mar 2021 09:09:52 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (17.red-88-21-201.staticip.rima-tde.net. [88.21.201.17]) by smtp.gmail.com with ESMTPSA id u17sm3401540wrw.51.2021.03.18.09.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 09:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616083795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0ILZwEmglVjVyYz5F4sj1LV2EThGiB2LjCTP+JRuw5I=; b=EQQHDUpoC7Z0jXj95pQmmvQZaHCRKJT2AwRJCrrzDnC63xO/S9ad/rJBcWeoS0WkaOIU5S JGwMApQEPWY7ODuvO2GYAP/V0FscgbA34/gGP5OK+O7UYmZ0bIxTaHmekRR6fXDO98A8wZ BKXEiWD8Dlx0xZzMJh7OG2RQ9J9x9Po= X-MC-Unique: AjJsmiNHMeuXEUm_IedPjQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0ILZwEmglVjVyYz5F4sj1LV2EThGiB2LjCTP+JRuw5I=; b=aTgrpfPmKygu1j69ZikWm2GtcwfxpMG8NSHp6z13WqOBF03l1HcwIh0onpdOXfxzFi qBUuZ4/LLxNtmWBCeUpTHu6sKLGpyLCJgUgu4wFMishZ99Xmjq8OraHBbNGid3l13XFB M+WRHlDG34x4mkJNGCxrwbLtzuBqh9m4ITctYGkqxTz3udSr1Jh3P1W1rLw6xpJu8L9w YBqbpbuxmgk7PComEZdSasCWbkx9eJLwGG/SX5P+eDuipJtMKZDow7Z15T0yPjE7FIFf 8MT80FLJNlqmaf3/D502+6qhqU8IneMc4zSpNfdUeOp6u1RcxP06tb4yk7AclLoEUG32 Q+Kw== X-Gm-Message-State: AOAM530SPrPoSjNobYrx4QpQHaxUVI75X1h+0RfTu65SSvzmq/KKBHU6 jgxAw4JgwBA3LQiDtkr+kxAK4cmfafaz/VUewct8rzFWtnSX48pkOXSrJQkgl4UVOetnIOpEi2Q 1hB+niducZeM59g== X-Received: by 2002:a05:600c:608:: with SMTP id o8mr58205wmm.42.1616083791220; Thu, 18 Mar 2021 09:09:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8u5/G9jA+DMAJoSKxSGQfXY0OiGITPc8ggYoNhR6OMDW+jvw84D0Hzq0Z5z1qypBU7qEIDA== X-Received: by 2002:a05:600c:608:: with SMTP id o8mr58193wmm.42.1616083791087; Thu, 18 Mar 2021 09:09:51 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , "Michael S. Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Borntraeger Subject: [PATCH for 6.0 v2] hw/intc/i8259: Refactor pic_read_irq() to avoid uninitialized variable Date: Thu, 18 Mar 2021 17:09:49 +0100 Message-Id: <20210318160949.3681463-1-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Some compiler versions are smart enough to detect a potentially uninitialized variable, but are not smart enough to detect that this cannot happen due to the code flow: ../hw/intc/i8259.c: In function =E2=80=98pic_read_irq=E2=80=99: ../hw/intc/i8259.c:203:13: error: =E2=80=98irq2=E2=80=99 may be used uninit= ialized in this function [-Werror=3Dmaybe-uninitialized] 203 | irq =3D irq2 + 8; | ~~~~^~~~~~~~~~ Restrict irq2 variable use to the inner statement. Fixes: 78ef2b6989f ("i8259: Reorder intack in pic_read_irq") Reported-by: Christian Borntraeger Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- Supersedes: <20210318154738.27094-1-borntraeger@de.ibm.com> --- hw/intc/i8259.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c index 344fd04db14..52c039c6c03 100644 --- a/hw/intc/i8259.c +++ b/hw/intc/i8259.c @@ -176,10 +176,12 @@ static void pic_intack(PICCommonState *s, int irq) int pic_read_irq(DeviceState *d) { PICCommonState *s =3D PIC_COMMON(d); - int irq, irq2, intno; + int irq, intno; =20 irq =3D pic_get_irq(s); if (irq >=3D 0) { + int irq2; + if (irq =3D=3D 2) { irq2 =3D pic_get_irq(slave_pic); if (irq2 >=3D 0) { @@ -189,8 +191,11 @@ int pic_read_irq(DeviceState *d) irq2 =3D 7; } intno =3D slave_pic->irq_base + irq2; + pic_intack(s, irq); + irq =3D irq2 + 8; } else { intno =3D s->irq_base + irq; + pic_intack(s, irq); } pic_intack(s, irq); } else { @@ -199,10 +204,6 @@ int pic_read_irq(DeviceState *d) intno =3D s->irq_base + irq; } =20 - if (irq =3D=3D 2) { - irq =3D irq2 + 8; - } - #ifdef DEBUG_IRQ_LATENCY printf("IRQ%d latency=3D%0.3fus\n", irq, --=20 2.26.2