From nobody Mon Feb 9 07:42:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1589269770; cv=none; d=zohomail.com; s=zohoarc; b=GnmS+k/pFfWifgp8w30VWOnysbQOEKBind9jbAR6zsCIpOQiLFdvqv5stR1Xu44O81NY2UUU0FQ6CjdyPtPsB6NoOFWlMuXlbwpiWC2/Z5buf4UjDsdk1oe3UaF0XgwL/CfEDqhiYNESin8KG153npAC7ySU5MM+kECSSEdtGUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589269770; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=olrssLZq87JihaVWusLCkJTiP56dPUZ0HwB6S/q6u0w=; b=GkNRKmm+u6T91iO5pwIXTIO+iiS6LLv8vyYaR1ShD+SK8dkm84mf8VCo1awbLBaV+zRbQLN8Z1yHejXdMluwSG9iGVmQpSqXqDxXJiDeSwpkuEtIH81MjI73BeGDjbaqmCHTE+ohMow8K2ipMVajRWLnMSzB7Jc3rRft8UcI7cw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589269770748395.5489242252098; Tue, 12 May 2020 00:49:30 -0700 (PDT) Received: from localhost ([::1]:36652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYPfN-00018S-Dr for importer@patchew.org; Tue, 12 May 2020 03:49:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYPeH-0008U6-NU; Tue, 12 May 2020 03:48:21 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:37027) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYPeG-0002qY-VH; Tue, 12 May 2020 03:48:21 -0400 Received: by mail-wm1-x344.google.com with SMTP id z72so12511946wmc.2; Tue, 12 May 2020 00:48:20 -0700 (PDT) Received: from localhost.localdomain (17.red-88-21-202.staticip.rima-tde.net. [88.21.202.17]) by smtp.gmail.com with ESMTPSA id c7sm7783754wro.80.2020.05.12.00.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 00:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=olrssLZq87JihaVWusLCkJTiP56dPUZ0HwB6S/q6u0w=; b=f3P8zUF8nDi60cSsADAjn0HuBAlTyEP3PErsw6ilb8yZZeoiHrQ8/G2mYZECjodLFy q1YST3BLB+8KddWsbiStLQaC5BXC8W2j2h98CU17mWxMyU94tnsNEX6pvlt0kAT1vh+M 0YMkTonu2AkxHMH1j+eoXpikkSF+ljAvgelEy8IhN840MZ98a5GZwcGoC9/LqzyAtlxc VeUmTyGlRjtcLvAX/La2LVLWasTKO2RkaCvAqwg8MEoPTm9E+AugmUTWCxQ4tf+mbLPr 1Vn8SfpUf5xzFEsragBU/AJcxhArOfTYEE/ZiQlmEjJfWm0aSbW+eEF4eD29ecvewv9t Bntg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=olrssLZq87JihaVWusLCkJTiP56dPUZ0HwB6S/q6u0w=; b=rouqVa/v73lnS9n6/Mi12KGpwpvkrI3bfkuH48CaIVA1H6qLwkh+nCfjq9SxnB1cMn 3wJ7N0eSj8sGcHKA+x6VgIoJH8f2mWXWCGCFzYc3kcjEREL4CRjnbUKP9yAJv87xOW9a e8qYUGbb4M2sP6KINvEOeSOQdpr9SOUMIZRoCVVKvlpLxOpzkvTe3Vl4si5ciXKHc1QH 9TLrLZTEzE6G3NAwfuGa83JBCXGICYKNpbeT1yevqjw08fMkYeTcAzvZYyAlPhHtVIeL mLZViZN1D1Ep4Y87b49MG8HhWw1h8mqZ/4ryXL2d0IQmHNmfKy4dg2Ba6ASYLeWGwIt7 x5Pw== X-Gm-Message-State: AGi0PubV0rrI/7k23INc6Ks2hvTf9hPifxQHNt2eD21xnQduQAEZvzEN nqsLL8eA+iUExzLr8yXg478akf9yIfE= X-Google-Smtp-Source: APiQypJAar1ayWLmftBaKkWXKHxNbu9HxtuHEMZoRyxJzs16ps5v0/K8/J4yCzSfzCY3+jID8y4ELg== X-Received: by 2002:a7b:c5c7:: with SMTP id n7mr25666708wmk.18.1589269698469; Tue, 12 May 2020 00:48:18 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 1/3] hw/ide/ahci: Use qdev gpio rather than qemu_allocate_irqs() Date: Tue, 12 May 2020 09:48:11 +0200 Message-Id: <20200512074813.29992-2-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200512074813.29992-1-f4bug@amsat.org> References: <20200512074813.29992-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::344; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x344.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Aleksandar Markovic , Alistair Francis , Stafford Horne , John Snow , Aleksandar Rikalo , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) When plugging/unplugging devices on a AHCI bus, we might leak the memory returned by qemu_allocate_irqs(). We can avoid this leak by switching to using qdev_init_gpio_in(); the base class finalize will free the irqs that this allocates under the hood. Patch created mechanically using spatch with this script inspired from commit d6ef883d9d7: @@ typedef qemu_irq; identifier irqs, handler; expression opaque, count, i; @@ - qemu_irq *irqs; ... - irqs =3D qemu_allocate_irqs(handler, opaque, count); + qdev_init_gpio_in(DEVICE(opaque), handler, count); <+... - irqs[i] + qdev_get_gpio_in(DEVICE(opaque), i) ...+> ?- g_free(irqs); Inspired-by: Peter Maydell Reviewed-by: Alistair Francis Reviewed-by: John Snow Acked-by: John Snow Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/ide/ahci.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 13d91e109a..991bb7c9c8 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1534,19 +1534,18 @@ void ahci_init(AHCIState *s, DeviceState *qdev) =20 void ahci_realize(AHCIState *s, DeviceState *qdev, AddressSpace *as, int p= orts) { - qemu_irq *irqs; int i; =20 s->as =3D as; s->ports =3D ports; s->dev =3D g_new0(AHCIDevice, ports); ahci_reg_init(s); - irqs =3D qemu_allocate_irqs(ahci_irq_set, s, s->ports); + qdev_init_gpio_in(qdev, ahci_irq_set, s->ports); for (i =3D 0; i < s->ports; i++) { AHCIDevice *ad =3D &s->dev[i]; =20 ide_bus_new(&ad->port, sizeof(ad->port), qdev, i, 1); - ide_init2(&ad->port, irqs[i]); + ide_init2(&ad->port, qdev_get_gpio_in(qdev, i)); =20 ad->hba =3D s; ad->port_no =3D i; @@ -1554,7 +1553,6 @@ void ahci_realize(AHCIState *s, DeviceState *qdev, Ad= dressSpace *as, int ports) ad->port.dma->ops =3D &ahci_dma_ops; ide_register_restart_cb(&ad->port); } - g_free(irqs); } =20 void ahci_uninit(AHCIState *s) --=20 2.21.3 From nobody Mon Feb 9 07:42:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1589269859; cv=none; d=zohomail.com; s=zohoarc; b=NPZSeLOjYOFLLq64km6ZGphV+42dGgioCer6cSJaUHWB/vnN503l3QkgUTyRuT55C+XRYeP1TqbCFVEwQV1pHKNaYOjF+SWQY5cSl07mJe+EORwerHxxGlmpAHRs2529NPr5CD8tihv+UYmijndxi3NM5I3lT4ATmE5nWq+iQ/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589269859; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gVc4pPl94gT2dO6tZ3Upozb9mh/UUaA4ooVvMaypxfs=; b=Xyh0EsI15WSxXdcpe1Ckq9TQJ/t7r3w/gxDt8ItNcujcQPpPh+9ig5jqeewB0fg44zyu60wp8jZn38Z/W3qfU15I3ZuKgimPBPx3Mnuo/HZWXbe6PqU8+7nnv0Qu+Er8+kHArj20+VT+ayooqjcEgMC5i4XpjrRxi8vs+f/FEho= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589269859068381.5751703534835; Tue, 12 May 2020 00:50:59 -0700 (PDT) Received: from localhost ([::1]:41006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYPgn-0003KQ-Lp for importer@patchew.org; Tue, 12 May 2020 03:50:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYPeI-0008Vf-TL; Tue, 12 May 2020 03:48:22 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:50836) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYPeI-0002qk-61; Tue, 12 May 2020 03:48:22 -0400 Received: by mail-wm1-x343.google.com with SMTP id m12so15699524wmc.0; Tue, 12 May 2020 00:48:21 -0700 (PDT) Received: from localhost.localdomain (17.red-88-21-202.staticip.rima-tde.net. [88.21.202.17]) by smtp.gmail.com with ESMTPSA id c7sm7783754wro.80.2020.05.12.00.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 00:48:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gVc4pPl94gT2dO6tZ3Upozb9mh/UUaA4ooVvMaypxfs=; b=Xo0nu1MJaLKnDIdmvK/OW5erxX8uoJJL+tEBRaKeV6iXhd2EnBWY1fPVe9o4Ck8u4p ByRNW/A/fY4/AiCupJQT5gYoiiM90QkaHeKjfSNDpQTgKv+oaJxdFAQTO2VJZWMMAP5L pn/EBpTVCuqgwPVzjqnu1Ndq7NR7Z29sxkS4V9hWEv0DfQAACTB+5wkVTZ6iL6nbHLwV u51A3Td2x2gq2Z+lxHNUayxr/skDtNvq76BlH3OL6MVhsdp8ET2um1cEp7Oi40ApimXu RrQAbDtCoTEaBjIOtqVv9Ib0EYLFOxljifXnfYRbAlYzZkYBLtbXNiE5KAbFtOSl8u+O b3/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=gVc4pPl94gT2dO6tZ3Upozb9mh/UUaA4ooVvMaypxfs=; b=fCV1qLIG7FoMVRFAmOeuxcYx/5DAMU4Q0h4lbH1uVdAzRBPFuo+K56d3eVRwZgUpeu 57qvihASVB0rBQwIVmszvD8RFxziH3qsxrYWmxKKCiaI/jV3wVYI0R7bzoWzB20DPa4g e+THI+9lAzA7cUF1fZM3rupv6L1MPw2SpgQQvIOdqrKQQ/NJFsV0Bv3CB7jbLeMgB3Gy 0YkdLgp2OXatlO5cQdDZtEcv1cFxWgvftZDjTb7dxqi73kMcAh63TWNimISZKiqnvCJw j9BvNH8cUoU3yW6R1X6lGa9SVVas4W5bz/VpxRcMw2uXk++ZWfaki2pytUfkD+K4w9Vs IgmQ== X-Gm-Message-State: AOAM53091UuAXMsb+W2N2OkQwRCcxexVLQ/lRB+zfP62k5oZH9czuRjz X4YG+Kt1EP3IJfbhkrXRhutDKEQtUwA= X-Google-Smtp-Source: ABdhPJxLr5qNckLQg1Evt9/7U45R9Jha6HyOniJv25pW9cRDJUr0XFySq20WtYHunaISp+RD1uUZEg== X-Received: by 2002:a1c:81d0:: with SMTP id c199mr1963426wmd.125.1589269700216; Tue, 12 May 2020 00:48:20 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 2/3] hw/mips/mips_int: Use qdev gpio rather than qemu_allocate_irqs() Date: Tue, 12 May 2020 09:48:12 +0200 Message-Id: <20200512074813.29992-3-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200512074813.29992-1-f4bug@amsat.org> References: <20200512074813.29992-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::343; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Aleksandar Markovic , Stafford Horne , John Snow , Aleksandar Rikalo , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Switch to using the qdev gpio API which is preferred over qemu_allocate_irqs(). One step to eventually deprecate and remove qemu_allocate_irqs() one day. Patch created mechanically using spatch with this script inspired from commit d6ef883d9d7: @@ typedef qemu_irq; identifier irqs, handler; expression opaque, count, i; @@ - qemu_irq *irqs; ... - irqs =3D qemu_allocate_irqs(handler, opaque, count); + qdev_init_gpio_in(DEVICE(opaque), handler, count); <+... - irqs[i] + qdev_get_gpio_in(DEVICE(opaque), i) ...+> ?- g_free(irqs); Fixes: Coverity CID 1421934 RESOURCE_LEAK Inspired-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Maydell --- hw/mips/mips_int.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/mips/mips_int.c b/hw/mips/mips_int.c index 796730b11d..91788c51a9 100644 --- a/hw/mips/mips_int.c +++ b/hw/mips/mips_int.c @@ -74,14 +74,12 @@ static void cpu_mips_irq_request(void *opaque, int irq,= int level) void cpu_mips_irq_init_cpu(MIPSCPU *cpu) { CPUMIPSState *env =3D &cpu->env; - qemu_irq *qi; int i; =20 - qi =3D qemu_allocate_irqs(cpu_mips_irq_request, cpu, 8); + qdev_init_gpio_in(DEVICE(cpu), cpu_mips_irq_request, 8); for (i =3D 0; i < 8; i++) { - env->irq[i] =3D qi[i]; + env->irq[i] =3D qdev_get_gpio_in(DEVICE(cpu), i); } - g_free(qi); } =20 void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level) --=20 2.21.3 From nobody Mon Feb 9 07:42:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1589269860; cv=none; d=zohomail.com; s=zohoarc; b=Kz3HHHpmi3WqYr3WglUBQWQKRbOaix2K89H9jqfBp5BHklZu6pmJTXYETbR9QFC2gBiyOMn1JHQTOw0WyojXQbXhwnJfUmpgNNQVBQb0cL9NSolkL94ueC3A1wOjs90wn9bq5WDi62+KONIpyy7Icnd+bRNNIPzU8u1o7Qa1ycw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589269860; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9+HPWfi6hB2pKPErn5CtXaV2y+G6fIj46U87L3EGk9I=; b=jmZt/dvYKb73I6eIvLtic/7mp31E4anrSNY/E3A84r0Lml+kCX8AOd+uUuMZtPfzdb8rIE8K0ctirYXY1GXwTb0VArVhbC+XkbG94z/7PRAGX1yPQXNHRKm6vC/iZ5YAHuVNmuE8QeMQboXKjeU1lzXhgnOrx2Kd5D1HjSnHR20= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589269860289949.8203447903776; Tue, 12 May 2020 00:51:00 -0700 (PDT) Received: from localhost ([::1]:41098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYPgp-0003Mj-4H for importer@patchew.org; Tue, 12 May 2020 03:50:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYPeK-00007r-Sw; Tue, 12 May 2020 03:48:24 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:41960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYPeK-0002qv-1z; Tue, 12 May 2020 03:48:24 -0400 Received: by mail-wr1-x441.google.com with SMTP id h17so5192807wrc.8; Tue, 12 May 2020 00:48:23 -0700 (PDT) Received: from localhost.localdomain (17.red-88-21-202.staticip.rima-tde.net. [88.21.202.17]) by smtp.gmail.com with ESMTPSA id c7sm7783754wro.80.2020.05.12.00.48.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 00:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9+HPWfi6hB2pKPErn5CtXaV2y+G6fIj46U87L3EGk9I=; b=NCH+FWx/bgOA/G53S0IB6rTD2XBw3Od7DLlx/agjhBGCfL8N7pnZFXs/MvFEbIFZfC lIdbXSDZxlVpFLvo+yaMoM/cLbfbEeyPNfyT7zdcSEuQuYPzSh8gIrLIIVbgbou7RQQf OcLVcPMhO7xefC7Xa9ZPPVJLIebhYCTN2kkPLWtYTk7QmAHD7jqoNNZ5GJQ+wNnzo5xV KOyOZIKsSXm4VtOsT/ECatvujb7ut+RKfKtZyfzPBOx/Ky8dVOTHvc+Rn9QJG+MVucSB 4ctM/kanl2j/CY/jq+EgolQu2G8t4brmhclm0QFQhEMfs/EejRNA49pNwRITIjoFiob6 GF3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=9+HPWfi6hB2pKPErn5CtXaV2y+G6fIj46U87L3EGk9I=; b=moRN58MwuKsGH3iYTfDvBt3UlJqPSO9vWUC16f4aEsdCPa8ieojGN9lgG0seSoAMob PKfu84CpD4Dg3f4DpkkaKroC1gWHw7nhjvJjvRyOf4rQrs2dIsvORJXOWQRSl53TBNIU +dLDWQdibarqIW+ee/TJTa3Eq33a1MRI8gVd6zECI35fqLzuwtWeiTStTG0stgyjyLsC SSQUqJc11H85NQ6LuJn1ewic8RZaPCYnWvBka2x40wgx2IOL14aQ5oPf4GtQQ6CkzGvj WFB44ztVkV+U/8E9xwNSwNf+oDKoGqtd+XRdVqPMH0aSWyqA2Y7lQByj0MF09L9JOQyo Lwkg== X-Gm-Message-State: AGi0PuanpByaI8GkAZrU73MgdwF0OVINg2WzGJ5yvBnbqiaWYbrZbrhq 1SkwG0fdVflSHk/KDl4uOkUjqsG90IE= X-Google-Smtp-Source: APiQypKkiNw8fkb0TPe0cxQGwb02CaORIWkDEN3FLgHhW8Pup6YHsTQk8RRrz3bviGdDv0C7yKVfqQ== X-Received: by 2002:a5d:4d46:: with SMTP id a6mr24475859wru.188.1589269701741; Tue, 12 May 2020 00:48:21 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 3/3] hw/openrisc/pic_cpu: Use qdev gpio rather than qemu_allocate_irqs() Date: Tue, 12 May 2020 09:48:13 +0200 Message-Id: <20200512074813.29992-4-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200512074813.29992-1-f4bug@amsat.org> References: <20200512074813.29992-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::441; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Aleksandar Markovic , Stafford Horne , John Snow , Aleksandar Rikalo , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Coverity points out (CID 1421934) that we are leaking the memory returned by qemu_allocate_irqs(). We can avoid this leak by switching to using qdev_init_gpio_in(); the base class finalize will free the irqs that this allocates under the hood. Patch created mechanically using spatch with this script inspired from commit d6ef883d9d7: @@ typedef qemu_irq; identifier irqs, handler; expression opaque, count, i; @@ - qemu_irq *irqs; ... - irqs =3D qemu_allocate_irqs(handler, opaque, count); + qdev_init_gpio_in(DEVICE(opaque), handler, count); <+... - irqs[i] + qdev_get_gpio_in(DEVICE(opaque), i) ...+> ?- g_free(irqs); Fixes: Coverity CID 1421934 RESOURCE_LEAK Inspired-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Maydell --- hw/openrisc/pic_cpu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/openrisc/pic_cpu.c b/hw/openrisc/pic_cpu.c index 36f9350830..4b0c92f842 100644 --- a/hw/openrisc/pic_cpu.c +++ b/hw/openrisc/pic_cpu.c @@ -52,10 +52,9 @@ static void openrisc_pic_cpu_handler(void *opaque, int i= rq, int level) void cpu_openrisc_pic_init(OpenRISCCPU *cpu) { int i; - qemu_irq *qi; - qi =3D qemu_allocate_irqs(openrisc_pic_cpu_handler, cpu, NR_IRQS); + qdev_init_gpio_in(DEVICE(cpu), openrisc_pic_cpu_handler, NR_IRQS); =20 for (i =3D 0; i < NR_IRQS; i++) { - cpu->env.irq[i] =3D qi[i]; + cpu->env.irq[i] =3D qdev_get_gpio_in(DEVICE(cpu), i); } } --=20 2.21.3