[{"id":3679217,"web_url":"http://patchwork.ozlabs.org/comment/3679217/","msgid":"<2caa071e-85ee-4e76-bb33-8f27a4579fac@163.com>","list_archive_url":null,"date":"2026-04-20T04:47:32","subject":"Re: [PATCH] PCI/MSI: Fix memory leak in\n pci_alloc_irq_vectors_affinity INTx path","submitter":{"id":89937,"url":"http://patchwork.ozlabs.org/api/people/89937/","name":"Hans Zhang","email":"18255117159@163.com"},"content":"On 4/20/26 12:09, neilfsun wrote:\n> In the INTx fallback path of pci_alloc_irq_vectors_affinity(),\n> affinity masks are created and never freed.\n> \n> Signed-off-by: neilfsun <neilfsun@tencent.com>\n> Signed-off-by: Sun Feng <loyou85@gmail.com>\n> ---\n>   drivers/pci/msi/api.c | 5 ++++-\n>   1 file changed, 4 insertions(+), 1 deletion(-)\n> \n> diff --git a/drivers/pci/msi/api.c b/drivers/pci/msi/api.c\n> index c18559b6272c..c1377f74b8f3 100644\n> --- a/drivers/pci/msi/api.c\n> +++ b/drivers/pci/msi/api.c\n> @@ -280,14 +280,17 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,\n>   \t/* use INTx IRQ if allowed */\n>   \tif (flags & PCI_IRQ_INTX) {\n>   \t\tif (min_vecs == 1 && dev->irq) {\n> +\t\t\tstruct irq_affinity_desc *masks = NULL;\n> +\n>   \t\t\t/*\n>   \t\t\t * Invoke the affinity spreading logic to ensure that\n>   \t\t\t * the device driver can adjust queue configuration\n>   \t\t\t * for the single interrupt case.\n>   \t\t\t */\n>   \t\t\tif (affd)\n> -\t\t\t\tirq_create_affinity_masks(1, affd);\n> +\t\t\t\tmasks = irq_create_affinity_masks(1, affd);\n\nHi,\n\nSuggestion:\n\ndiff --git a/drivers/pci/msi/api.c b/drivers/pci/msi/api.c\nindex c18559b6272c..0ce34db2b2bf 100644\n--- a/drivers/pci/msi/api.c\n+++ b/drivers/pci/msi/api.c\n@@ -286,7 +286,8 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev \n*dev, unsigned int min_vecs,\n                          * for the single interrupt case.\n                          */\n                         if (affd)\n-                               irq_create_affinity_masks(1, affd);\n+                               struct irq_affinity_desc *masks \n__free(kfree) =\n+                                       irq_create_affinity_masks(1, affd);\n                         pci_intx(dev, 1);\n                         return 1;\n                 }\n\n\nBest regards,\nHans\n\n>   \t\t\tpci_intx(dev, 1);\n> +\t\t\tkfree(masks);\n>   \t\t\treturn 1;\n>   \t\t}\n>   \t}","headers":{"Return-Path":"\n <linux-pci+bounces-52743-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256\n header.s=s110527 header.b=C1q/4KAn;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-52743-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=163.com header.i=@163.com\n header.b=\"C1q/4KAn\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=117.135.210.5","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=163.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=163.com"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fzXzt2MSnz1yGs\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 14:48:10 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 995213011C66\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 04:48:03 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id ED7AD2D060D;\n\tMon, 20 Apr 2026 04:48:02 +0000 (UTC)","from m16.mail.163.com (m16.mail.163.com [117.135.210.5])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 355163783D0;\n\tMon, 20 Apr 2026 04:47:58 +0000 (UTC)","from [192.168.50.71] (unknown [])\n\tby gzga-smtp-mtada-g0-3 (Coremail) with SMTP id\n _____wDnHwHkr+VpjVHSAg--.3663S2;\n\tMon, 20 Apr 2026 12:47:33 +0800 (CST)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776660482; cv=none;\n b=Zy3WNMJ+pxaPNflMFDdqYp9yXV99QDs09XKylW5NlYmX/0y3ee8Ja4Bh9KDSqkDcR2vbK+kEvOOTaY/Ec59TglZ95muyP5Dhj6yDD38KKW2c1nxetOsvy7l1jdFpxs4L1iG0FAiqrMI2ADAZrehIbJnYQLME+kFhKuUyjBphYEA=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776660482; c=relaxed/simple;\n\tbh=XT8sREQpVBa49QotSmJ5J0WOI6v8PbKibYNmcfVxnAY=;\n\th=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:\n\t In-Reply-To:Content-Type;\n b=bh/mwbRj4bG2gTG7NiqPfqs1Rk3zHoPWCibW+nWptBF1+QtVZaoaCDJwQqZVri71oBpfJM01bGgEAE62FZAaN8N1WU9n7CYqlvKCKONZLO4CC67oyQtgQaMa9RGrOFBbmoFL7YL4xXTNCq6cpobYwshNyKCYDUaStthVaUOlffI=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=163.com;\n spf=pass smtp.mailfrom=163.com;\n dkim=pass (1024-bit key) header.d=163.com header.i=@163.com\n header.b=C1q/4KAn; arc=none smtp.client-ip=117.135.210.5","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com;\n\ts=s110527; h=Message-ID:Date:MIME-Version:Subject:To:From:\n\tContent-Type; bh=pEUieLBQ4Kwa60UOZD4+xJNKj/Rv2EJ/8lbOK4yzsx8=;\n\tb=C1q/4KAn44fzyyoZJXCUuSvDiG05U++ZXzXzR3Rjg+XL5WwRnY5vtcBAOIJoCW\n\t096cZfuijr+5/hX65A883AFiIkOZnmo3yXvzF8EbF7lncUXPc3BfogTEczMpd+st\n\tl+6yPS4zP7BQByiYDWVai0YxsdSDo0eI5QHUMrs7GLYZA=","Message-ID":"<2caa071e-85ee-4e76-bb33-8f27a4579fac@163.com>","Date":"Mon, 20 Apr 2026 12:47:32 +0800","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] PCI/MSI: Fix memory leak in\n pci_alloc_irq_vectors_affinity INTx path","To":"neilfsun <loyou85@gmail.com>, bhelgaas@google.com,\n shawn.lin@rock-chips.com, hans.zhang@cixtech.com, tglx@kernel.org,\n linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org","Cc":"neilfsun <neilfsun@tencent.com>","References":"<20260420040940.14824-1-neilfsun@tencent.com>","Content-Language":"en-US","From":"Hans Zhang <18255117159@163.com>","In-Reply-To":"<20260420040940.14824-1-neilfsun@tencent.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-CM-TRANSID":"_____wDnHwHkr+VpjVHSAg--.3663S2","X-Coremail-Antispam":"1Uf129KBjvJXoW7uw1xtF15ZF4fWr1DGFWUXFb_yoW8WrW5pr\n\tWIgF4UAry8Xw45XF45Cw4fJFy3Xa9aq347CF4fC34xurW29FZYqry3KFy7Xws7tFWDCF4a\n\tqr4DAF18JF13trJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2\n\t9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UsJ5wUUUUU=","X-CM-SenderInfo":"rpryjkyvrrlimvzbiqqrwthudrp/xtbC7AX4nGnlr+UDZAAA3s"}}]