Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4230470yba; Wed, 17 Apr 2019 07:20:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyumJiWe1RuVnekIqiRYu5WBqyzqWM9VIWh2EpHekpMa/kwvqFicuV9ktpRXADWJmG3V1f3 X-Received: by 2002:a65:5304:: with SMTP id m4mr82002466pgq.281.1555510819232; Wed, 17 Apr 2019 07:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555510819; cv=none; d=google.com; s=arc-20160816; b=h+80tX5luUgvpl1AD4WPqjXeqVWrOzlZJBi8bSOKlsKgJhz0HXY2Vd/dhlS8E08ufU ohJak0jJFVM108vVHH4H8aT3PuZjLQN9WitDLtQtYTxFXjAXj72LzL+3vJ+owSy3DKUv DePHxMH2i9JgUbMxtrwkMS8K5DJofTIIlzaFy2YPTVXFUzSWbSgYC8TWXyDKIq/IRgur yUzXcb7p6/TX/hXtnubS/w6ssNJ+sNWhdp3W0E325TifmOOWaiMJux0aZnbS67863lan baPAFJAwA3Kh3UGu0DWfQtSMuGp41ocB1XpRjz1hveskhePNfTwZFmR94WjxHMFT+7iG ZI7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=uojC63LlRZMao2Xj4ZjGaAJ2xtzmNGWu+Lgx37e3mxc=; b=VFnwuPvvuKxlQmCyi4E3KV8I69qHTSQtLMyZ3jEHbOF5lBCKA3rlfNkw+8sMst4XDy 122St8oF2jSjlLGrC9xcsHn1/7KAaseu9NowsdHuGbiNhGRZRvlNkHymIwF9SAnqbLfS 8tJaceVFc8vAX+pYCMHpYabCvzN9AzEHVcTuem9SeK0rjUCyfGOqtxS7eO+3ZL7UaUHM xzqt7YAnqeJwbWcmHRz/PdUjIShEcuq888sFZbHR4YC9kYSZmaea5Jllo8+1jGe6E7vA 6KTeH8nouinsFacojTuGeak3Xc4SdddbJSBikKKHxpLmqM/yUwA5R5MAVPclnXxaMW0+ wEpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b="fnSP/znF"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e22si48155249pgi.66.2019.04.17.07.20.04; Wed, 17 Apr 2019 07:20:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b="fnSP/znF"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732471AbfDQOTF (ORCPT + 99 others); Wed, 17 Apr 2019 10:19:05 -0400 Received: from mta-p5.oit.umn.edu ([134.84.196.205]:39682 "EHLO mta-p5.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732267AbfDQOTE (ORCPT ); Wed, 17 Apr 2019 10:19:04 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p5.oit.umn.edu (Postfix) with ESMTP id CA204D30 for ; Wed, 17 Apr 2019 14:19:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p5.oit.umn.edu ([127.0.0.1]) by localhost (mta-p5.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GiGOEJBQvWwd for ; Wed, 17 Apr 2019 09:19:02 -0500 (CDT) Received: from mail-it1-f200.google.com (mail-it1-f200.google.com [209.85.166.200]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p5.oit.umn.edu (Postfix) with ESMTPS id 9FD5ED20 for ; Wed, 17 Apr 2019 09:19:02 -0500 (CDT) Received: by mail-it1-f200.google.com with SMTP id s21so2641176ite.6 for ; Wed, 17 Apr 2019 07:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=uojC63LlRZMao2Xj4ZjGaAJ2xtzmNGWu+Lgx37e3mxc=; b=fnSP/znF9HoI91HHaFKybcEPhsXHBY1++8r6g6Hv1Ul7W/0bqN3+aJfRkmri/3PYfx HN56IjoL+zIa7IOyXmh2wZLkI4b49CaBwgNF+8Xhimo32S3D3/9BYK+2GKJh4lAZ6P5A +zjJu2I0rutSN5Kr/YVW4NG4Z8wkjcFTZ8FxfpwshRusI0411TFSMM2V+x9igc0DKbjn 5yXYxkhKsWU48xNF9vGy+eedNIrHzdtNFv7keE4MYzhJ0nzCKB+xzPOoSr1nxMQY3C29 ofSdxgvXzwebXSYIYNJ+9YV6tVp2+JqBkWnOB2o9zRjVuSfpcXdSdp5NoZE1ArU/oKAL uJWw== 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; bh=uojC63LlRZMao2Xj4ZjGaAJ2xtzmNGWu+Lgx37e3mxc=; b=jQ3lQcAbXpmkPfHVk1hVXTKhA0qdNhcWq+H/2w+zJuBJ4skcZgjE90oUAXbJzN4Dso BvBTe8CE7Tte0UaJ3VXOXf55cH2RzGECNUPdNaZqjQQu91tdBkNKHwQPaxmRgmtxNl6g N9DJvPJ/aA2yEOakOk85JdA0lUqx/OEhOQXvraULBjskPwqKOKBZk4KYPZ0HlhF2KrcE MR1Vdv/TO+0F/8EjHdOWWIMhbIaZWb5kRZoE0sHZccPpGw8zs76255Hom1tTak+5hfDP YeKCVmQY78cMJXPo91I1mOItQWhZ4znMwuvE+zozyZXdp7d47+RCE8tT9peuNn1CzU35 82oQ== X-Gm-Message-State: APjAAAXY2wBpJ9gZuDTACdh9N6iiS3SCYczIRMxJLd37bSKSeTBE6D/V GuofzB1jpKXI5x8aIYUvq1Gl6tue1qLUxxa1lVByFxTnvY71HW01aLRfvjPGoTd3IcWiIlRSyQq a0R+uztU5KnJgQZQAwoIAi13yQno6 X-Received: by 2002:a5d:8d88:: with SMTP id b8mr47103252ioj.58.1555510742095; Wed, 17 Apr 2019 07:19:02 -0700 (PDT) X-Received: by 2002:a5d:8d88:: with SMTP id b8mr47103238ioj.58.1555510741947; Wed, 17 Apr 2019 07:19:01 -0700 (PDT) Received: from cs-u-cslp16.dtc.umn.edu (cs-u-cslp16.cs.umn.edu. [128.101.106.40]) by smtp.gmail.com with ESMTPSA id g126sm1317062itg.36.2019.04.17.07.19.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Apr 2019 07:19:01 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH v4] x86/PCI: fix a memory leak bug Date: Wed, 17 Apr 2019 09:18:50 -0500 Message-Id: <1555510730-9060-1-git-send-email-wang6495@umn.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In pcibios_irq_init(), the PCI IRQ routing table 'pirq_table' is firstly found through pirq_find_routing_table(). If the table is not found and 'CONFIG_PCI_BIOS' is defined, the table is then allocated in pcibios_get_irq_routing_table() using kmalloc(). In the following execution, if the I/O APIC is used, this table is actually not used. However, in that case, the allocated table is not freed, which is a memory leak bug. To fix this issue, free the allocated table if it is not used. Signed-off-by: Wenwen Wang Acked-by: Thomas Gleixner --- arch/x86/pci/irq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c index 52e5510..d3a73f9 100644 --- a/arch/x86/pci/irq.c +++ b/arch/x86/pci/irq.c @@ -1119,6 +1119,8 @@ static const struct dmi_system_id pciirq_dmi_table[] __initconst = { void __init pcibios_irq_init(void) { + struct irq_routing_table *rtable = NULL; + DBG(KERN_DEBUG "PCI: IRQ init\n"); if (raw_pci_ops == NULL) @@ -1129,8 +1131,10 @@ void __init pcibios_irq_init(void) pirq_table = pirq_find_routing_table(); #ifdef CONFIG_PCI_BIOS - if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) + if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) { pirq_table = pcibios_get_irq_routing_table(); + rtable = pirq_table; + } #endif if (pirq_table) { pirq_peer_trick(); @@ -1145,8 +1149,10 @@ void __init pcibios_irq_init(void) * If we're using the I/O APIC, avoid using the PCI IRQ * routing table */ - if (io_apic_assign_pci_irqs) + if (io_apic_assign_pci_irqs) { + kfree(rtable); pirq_table = NULL; + } } x86_init.pci.fixup_irqs(); -- 2.7.4