Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2921163yba; Tue, 16 Apr 2019 00:24:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxJ9m+aAGS5Hn35H15XVe8htJ0uO+GiU0WRN9sUr1LzPCHplrIut8aMQp8iYJkMiNtBXXg X-Received: by 2002:a17:902:7841:: with SMTP id e1mr79469437pln.303.1555399466355; Tue, 16 Apr 2019 00:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555399466; cv=none; d=google.com; s=arc-20160816; b=geenbXw83LkZg5AWRF4TwLqTd3OXlDxNPPPYNTwfw/gpx5nKstKntVkw5VVxfQ8xrT GEu3RmCmGizqtYnLrh055ixGN0ltdlizqqxOIhycXNK9cONQdkz6ghtckaaumn37N+2h k2+GBZsE3NPk+6rwLGyGNknhi8ice+E9yLbvENreeZgWpzRw6LPIZKDzKwyQWeP/Pcya FpIyb+FB9Vipb9oEf4ymoppuFcRIX2kgajSocHFfXC/doxaCfceI9WkPWEAs9gGkvg5G Unu14m0WbOeJvMsVokXe7OjeI1HEjRP5kttabigme+OKIQeldrC3gvHg9MAyZ0Fm1G7U QF2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yrGXPuW39LplhySUkRwA1s1zOaRJ4W+2puff9jsZHPw=; b=vCuBX9MooVg/5aPek/5z4+mzZ3fkCHvmib/N92V8Ahf+D6zkNPPLYZPjmsy+wRDY5a OtdUT0n3m7l3GjwTDGYHZv7ivr3zl9r9ayyQJfFRg4ICe9rVVn6DZdp+PIemyTMXNaU4 jqWg2g9srwsrLHXZ04Qa87fjLN78xoEvy49M+abjio2XnH3CtSl0W2MF+WvVg02m4xsQ pxi9gJgZAeq6J7QtOFeVbl157us5WDmqiPK7XPNByhSCUBnYbBz5Mp+3+Bc8qGCCpRP0 /oflm5ayJSWlQTi+OE2LGMUKr27xDilChfmVQOEPF6kbTL+EOCduB/D6gTuYn5My96P2 CZIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="TfN/eBLv"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si47337366pgi.330.2019.04.16.00.24.10; Tue, 16 Apr 2019 00:24:26 -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=fail header.i=@gmail.com header.s=20161025 header.b="TfN/eBLv"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728505AbfDPHXd (ORCPT + 99 others); Tue, 16 Apr 2019 03:23:33 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34552 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726988AbfDPHXd (ORCPT ); Tue, 16 Apr 2019 03:23:33 -0400 Received: by mail-wm1-f65.google.com with SMTP id r186so1652273wmf.1; Tue, 16 Apr 2019 00:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=yrGXPuW39LplhySUkRwA1s1zOaRJ4W+2puff9jsZHPw=; b=TfN/eBLvOyIk4nnfKvdEdynlMYlTstXF18x5YyAhR8W6sSTporVApePoZgai+42jsg OGKPZcQCa+tqxa8vD+KEY4yrFYTGM2AnXlVq6Ttq0BqSOrlQrYHYAu5pjtUnjrCv0pNX MGjSjaSEB16eqeHNjIbVmtQNPpqqbemuBXPUJBTKDmLj9JCSicQT6V66QBz37DW08Ac0 3o6U4KzBLHW6wlKcQ9KVI8TLtlT8P2Wqw6nF53xDwe2agINJXKkrFYbmkDIqA+dhvVwN fGHNIDmLEPYWIy00qCgfJ5C2xNBgnr8kM4+sJvO/y2XyfNHP83Oe24Fa4jp8lDD9WZYO 3+5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=yrGXPuW39LplhySUkRwA1s1zOaRJ4W+2puff9jsZHPw=; b=uLXYq6XsYFDdiwgdYxPo16ZCLsaOFXCwa9j6CO96hH8BGoc1OjeuHbgfK1A/IHzs6b Xg01Np5PSBzbiVnlGOc/4VwFqJU3kDQKfNb48oVlyHPLhdoiAw2qgqiSLfWqKgdXEZsX Ip36NQErFAD1HJUqylp4PvvzrQs2QfwdQdB0/HSHd2IGFnjZgzbdI+9U1JjoDrjKQcGy CRouLdnf45wb4HPPBrN4zzvWf3F0lr2bQu3Lzd8pAuP8YO3iqs8keo8crV3HnnQBZu87 zrts/mQL4nVPLcyyG+bcjGEAdPotLq+S2RYiIB9sT3Owzk4BBGar4FU8Hbq68Kg1MidF 0SjA== X-Gm-Message-State: APjAAAW/wofcqKNC/JnlytxzjvokhmOcYe88S1RqCgD+UQfULNavSenk CjAdqcQq1KX841iw/+G4avxY+aPq X-Received: by 2002:a05:600c:2293:: with SMTP id 19mr25455436wmf.77.1555399411361; Tue, 16 Apr 2019 00:23:31 -0700 (PDT) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id a17sm17772101wmg.40.2019.04.16.00.23.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Apr 2019 00:23:30 -0700 (PDT) Date: Tue, 16 Apr 2019 09:23:27 +0200 From: Ingo Molnar To: Wenwen Wang Cc: Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "open list:PCI SUBSYSTEM" , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [PATCH] x86/PCI: fix a memory leak bug Message-ID: <20190416072327.GA127769@gmail.com> References: <1555340058-3065-1-git-send-email-wang6495@umn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1555340058-3065-1-git-send-email-wang6495@umn.edu> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Wenwen Wang wrote: > 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 can lead to > a memory leak bug. > > To fix this issue, this patch frees the allocated table if it is not used. > > Signed-off-by: Wenwen Wang > --- > 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..d9bcb96 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 *itable = NULL; > + Minor style nit: the canonical name of irq_routing_table local variables is usually 'rtable' or 'rt' - let's not add a third naming variant with 'itable'? > 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(); > + itable = 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(itable); > pirq_table = NULL; > + } Reviewed-by: Ingo Molnar Thanks, Ingo