From nobody Sat May 18 23:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1616163798; cv=none; d=zohomail.com; s=zohoarc; b=TYzSxzWHPuX+ctCQvPyBSq92KNR49OxkVSBuNh3+PLplwmR9rFaYF02cKk4cOa/RLxUQGC/VS1pLk4eX1OZ1kM9zAjUwlzHofZPlsI0IhT09+ujG5/iiON/2nUWmIa/qrlXKe+jnFRoDf9K6Wl/axd6HW7HtCWkfthzvV9LZHOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616163798; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=L6ao+ru9GH1VH9Sp7obIJ//NGjertJqEquapjCNSKrA=; b=MAe0wYCamPyTvvUwxbhRvr6vJJ0Xw8UqZ2/wcMLBeaXBpqN+uTvkmefRIRWuAteoU01bT+p9Bx739A6xmsEpgBqsaZ5iELIccXW+BA5PDfrErrTBUH1TYFVxpUiDYigkHHKxQzA6X0yi1H9q8N78qWwU8+rA6XteAHDhYlOeYGU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1616163798660340.93201196901714; Fri, 19 Mar 2021 07:23:18 -0700 (PDT) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-500-S9bQIoEJOmC5YWItuDITYQ-1; Fri, 19 Mar 2021 10:23:12 -0400 Received: by mail-wm1-f69.google.com with SMTP id s192so12999789wme.6 for ; Fri, 19 Mar 2021 07:23:12 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (17.red-88-21-201.staticip.rima-tde.net. [88.21.201.17]) by smtp.gmail.com with ESMTPSA id n6sm8411011wrt.1.2021.03.19.07.23.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 07:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616163796; 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=L6ao+ru9GH1VH9Sp7obIJ//NGjertJqEquapjCNSKrA=; b=bx2/4g+N1F0js4Ww3Z7pc7oEy7YWiMzaufk9NMLjWYPDwguGGtvbRcT7+LIMVZhQSout3a 1UNONfBkgU6lXBBcaPpZsZmfosfoIsHFAqqHqvKWvITvPFN3Jm+StvCuVWeutxMsYfufY+ 0vznI1qRw287AzwIxjLh+TcHnEJYZ6A= X-MC-Unique: S9bQIoEJOmC5YWItuDITYQ-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=L6ao+ru9GH1VH9Sp7obIJ//NGjertJqEquapjCNSKrA=; b=NyBPBm0vvD8qiCY2DmYQ3Jg8TkzkTL9W+Dt+t66hdp6/a69RCjEV5txbxiObfrjMtg ri5KB2y7SHp6nVAkwZL3gsUebXX81/XNi23mC/Q263u6eFQal8zs8HsmV9sCPmgWleGO Hq0FMXQQWcZJ6BeBKuBLEkgM/S9v+cr8tuKJUHE3y7P+Wf5gRfo5HLI+fyZAUIE2t7Ay o5je1hw8ibA6THQMCJyR/uFLlkTboYExZthwljHxjzay/gxyMSvTjwMtR46POESTib7R Cljg8ak0CdHyVl2HS4RvYp+tMj/T2H/+W+W9zhXOLR/gd5iYhg91O4GSitJLdvp81orp 5cpg== X-Gm-Message-State: AOAM532jVGfnoBrZV+hFiHuJuYpnIWWF3sdW2dQuLH3t/fuHmyRkSkWQ iCIzjKISIhzNfHW9nQJeXPlQjCk6JknGePbLv3QHV+bY8y5Gh+ygHNK99XCk9XTWx952UtgNrPF qTgTJAr3hMerpxA== X-Received: by 2002:a1c:f404:: with SMTP id z4mr4072748wma.39.1616163791725; Fri, 19 Mar 2021 07:23:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVXeq9zGV0MwTCURc+u/z/1LTnGR59UPmCyrzxwAxcB9RNe/ijSh7ITyL9F7ip/ibiRGTfvQ== X-Received: by 2002:a1c:f404:: with SMTP id z4mr4072736wma.39.1616163791616; Fri, 19 Mar 2021 07:23:11 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Richard Henderson , Paolo Bonzini , "Michael S. Tsirkin" , BALATON Zoltan , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Borntraeger Subject: [PATCH for 6.0 v4] hw/intc/i8259: Refactor pic_read_irq() to avoid uninitialized variable Date: Fri, 19 Mar 2021 15:23:08 +0100 Message-Id: <20210319142308.3980259-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 Acked-by: Michael S. Tsirkin Tested-by: Christian Borntraeger --- Since v3: - Declare irq2 really local (Richard) Since v2: - Remove pic_intack() call (Zoltan) --- hw/intc/i8259.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c index 344fd04db14..d67c4710f15 100644 --- a/hw/intc/i8259.c +++ b/hw/intc/i8259.c @@ -176,12 +176,13 @@ 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) { if (irq =3D=3D 2) { - irq2 =3D pic_get_irq(slave_pic); + int irq2 =3D pic_get_irq(slave_pic); + if (irq2 >=3D 0) { pic_intack(slave_pic, irq2); } else { @@ -189,20 +190,18 @@ 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 { /* spurious IRQ on host controller */ irq =3D 7; 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