[{"id":3679692,"web_url":"http://patchwork.ozlabs.org/comment/3679692/","msgid":"<85068e3d-2b80-fb63-ee06-0f1f668760f7@rock-chips.com>","list_archive_url":null,"date":"2026-04-21T06:24:52","subject":"Re: [PATCH v2 v2] PCI/MSI: Fix memory leak in\n pci_alloc_irq_vectors_affinity INTx path","submitter":{"id":66993,"url":"http://patchwork.ozlabs.org/api/people/66993/","name":"Shawn Lin","email":"shawn.lin@rock-chips.com"},"content":"On 2026/04/21 Tuesday 11:20, 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> Reviewed-by: Hans Zhang <18255117159@163.com>\n\nI don't see when Hans provided his tag in v1.\n\n> ---\n> v2: use __free to auto-release pointers\n> ---\n>   drivers/pci/msi/api.c | 6 ++++--\n>   1 file changed, 4 insertions(+), 2 deletions(-)\n> \n> diff --git a/drivers/pci/msi/api.c b/drivers/pci/msi/api.c\n> index c18559b6272c..994f12813ce3 100644\n> --- a/drivers/pci/msi/api.c\n> +++ b/drivers/pci/msi/api.c\n> @@ -285,8 +285,10 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,\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\tif (affd) {\n> +\t\t\t\tstruct irq_affinity_desc *masks __free(kfree) =\n> +\t\t\t\t\tirq_create_affinity_masks(1, affd);\n\n\nThe __free() attribute is typically used for ensuring cleanup across\nmultiple exit paths​ within a function. In this case, the allocated masks\nis not used and its scope ends immediately after creation. Why can't\nwe simply kfree(irq_create_affinity_masks(1, affd))...\n\n\n> +\t\t\t}\n>   \t\t\tpci_intx(dev, 1);\n>   \t\t\treturn 1;\n>   \t\t}","headers":{"Return-Path":"\n <linux-pci+bounces-52817-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=rock-chips.com header.i=@rock-chips.com\n header.a=rsa-sha256 header.s=default header.b=QMrIhxVu;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-52817-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=rock-chips.com header.i=@rock-chips.com\n header.b=\"QMrIhxVu\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=220.197.31.99","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=rock-chips.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=rock-chips.com"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\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 4g0CFk6LsDz1yGs\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 16:32:26 +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 1A4CE3023359\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 06:30:21 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 06AB63603D3;\n\tTue, 21 Apr 2026 06:30:20 +0000 (UTC)","from mail-m1973199.qiye.163.com (mail-m1973199.qiye.163.com\n [220.197.31.99])\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 A7783385508;\n\tTue, 21 Apr 2026 06:30:15 +0000 (UTC)","from [172.16.12.17] (unknown [58.22.7.114])\n\tby smtp.qiye.163.com (Hmail) with ESMTP id 3b8458711;\n\tTue, 21 Apr 2026 14:24:54 +0800 (GMT+08:00)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776753019; cv=none;\n b=g+GOAT06EBJg/Tw3eCQmbHLEJTZN9UjKWH2Vi0ipuCB3xzITHWWwS4L5d6oBICzvY/gGcgTEUOTK/2nLIz9zVpvaSu0C/fnFmbx/ZrurHplqInp5sWOCArvC5s5toT6Ebbcx9VH9aUufY6QtJBRhhkbIzM0dkHtZk1emhZXfTN8=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776753019; c=relaxed/simple;\n\tbh=pMZi3EB8EJxPE7srGU/1U+XhvTKCBOfW1/luoVWtN1U=;\n\th=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From:\n\t In-Reply-To:Content-Type;\n b=gNhNa7wqUQCtBM/YZCNmjT4j2kPbL2OEjfa+7GAxm7fOBDe3fYhfomg8Me3lrbD6riJbov6RD9fo27bIEdFJkvkfPKvKyF6jh8PYxcVq/Mn+ZO0AziY0xvTwaq77t0JcSpeP5oz5CTElwZe8BHrmV7Ggbm6UdRendfkfbxWbCaE=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=rock-chips.com;\n spf=pass smtp.mailfrom=rock-chips.com;\n dkim=pass (1024-bit key) header.d=rock-chips.com header.i=@rock-chips.com\n header.b=QMrIhxVu; arc=none smtp.client-ip=220.197.31.99","Message-ID":"<85068e3d-2b80-fb63-ee06-0f1f668760f7@rock-chips.com>","Date":"Tue, 21 Apr 2026 14:24:52 +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/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101\n Thunderbird/102.15.1","Cc":"shawn.lin@rock-chips.com, bhelgaas@google.com, hans.zhang@cixtech.com,\n linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,\n neilfsun@tencent.com, tglx@kernel.org, 18255117159@163.com","Subject":"Re: [PATCH v2 v2] PCI/MSI: Fix memory leak in\n pci_alloc_irq_vectors_affinity INTx path","To":"neilfsun <loyou85@gmail.com>","References":"<2caa071e-85ee-4e76-bb33-8f27a4579fac@163.com>\n <20260421032044.55948-1-neilfsun@tencent.com>","From":"Shawn Lin <shawn.lin@rock-chips.com>","In-Reply-To":"<20260421032044.55948-1-neilfsun@tencent.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-HM-Tid":"0a9daeb692ca09cckunm2e6be9fcd1abc","X-HM-MType":"1","X-HM-Spam-Status":"e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly\n\ttZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGR8fT1YYSEpOHkpDGUlDGB1WFRQJFh\n\toXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUJNS0\n\tpVSktLVUtZBg++","DKIM-Signature":"a=rsa-sha256;\n\tb=QMrIhxVutDW05Una+5upa+xjlFcMFe18BgKKhnnWMBhrzlazbNW+3324x0luOmbP6UMv59L0zBbbgPpDiNlh1xJ+jHIT3NwxD0xqF7ndlgYGeEvTVJMsWjTcvKSOFJeUuHbaCSqLu8xTx/0l5L2pi4w43MgVf3fsgjV+huitvr0=;\n c=relaxed/relaxed; s=default; d=rock-chips.com; v=1;\n\tbh=z4YuwEeVttqjnnmWRHhUoJiE4Wv1sD796VmCFtMQMO0=;\n\th=date:mime-version:subject:message-id:from;"}},{"id":3679723,"web_url":"http://patchwork.ozlabs.org/comment/3679723/","msgid":"<878qagd9fm.ffs@tglx>","list_archive_url":null,"date":"2026-04-21T08:06:21","subject":"Re: [PATCH v2 v2] PCI/MSI: Fix memory leak in\n pci_alloc_irq_vectors_affinity INTx path","submitter":{"id":92397,"url":"http://patchwork.ozlabs.org/api/people/92397/","name":"Thomas Gleixner","email":"tglx@kernel.org"},"content":"On Tue, Apr 21 2026 at 11:20, neilfsun wrote:\n\nPlease use function() notation in the subject as well.\n\n> In the INTx fallback path of pci_alloc_irq_vectors_affinity(),\n> affinity masks are created and never freed.\n\nAnd then?\n\nhttps://www.kernel.org/doc/html/latest/process/maintainer-tip.html#changelog\n\n\nThis also lacks a Fixes: tag to identify the commit which introduced the\nproblem. Hint: It was not commit beddb5efb43ee.\n\n> Signed-off-by: neilfsun <neilfsun@tencent.com>\n                 ^^^^^^^^\nPlease provide your real name and not your nickname. See\nDocumentation/process/...\n\n> Signed-off-by: Sun Feng <loyou85@gmail.com>\n\nThis Signed-off-by chain is broken. See Documentation/process/...\n\n> Reviewed-by: Hans Zhang <18255117159@163.com>\n\nHans did not provide you a Reviewed-by tag. The fact that he reviewed V1\nand made suggestions how to improve does not imply that.\n\n> @@ -285,8 +285,10 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,\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\tif (affd) {\n> +\t\t\t\tstruct irq_affinity_desc *masks __free(kfree) =\n> +\t\t\t\t\tirq_create_affinity_masks(1, affd);\n\nThere is no point to use __free() here. The only reason why this is\ninvoked for the INTX case is to ensure that the affinity descriptor is\nupdated and an eventually provided calc_sets() callback is invoked. The\nreturned mask is not used at all, so this can be simplified to:\n\n         kfree(affd ? irq_create_affinity_masks(1, affd) : NULL);\n\nAlong with a proper comment.\n\nThanks,\n\n        tglx","headers":{"Return-Path":"\n <linux-pci+bounces-52829-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 (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=ljZ2MCtZ;\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-52829-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"ljZ2MCtZ\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"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)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0FLD2tVGz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 18:06:28 +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 7738E3009CDC\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 08:06:26 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id AA0E237DE84;\n\tTue, 21 Apr 2026 08:06:25 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\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 86A1C378D93;\n\tTue, 21 Apr 2026 08:06:25 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 88587C2BCB0;\n\tTue, 21 Apr 2026 08:06:24 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776758785; cv=none;\n b=Dom5aeLpuIPqHMJqh6HapkpsgfDUFavGFoWlvxmiAQpOWA6fK5SM5o+Wt5Z1mMGIXkT1a5Uh0SJvmoo4czfXc0SxxznfStaVGHAE16KixUiFdDFQKqikq+TzhfZn3KbQNoVfdVRRVed9IBoJUm+9buDiRKCtYKaVLD+CqslFcyI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776758785; c=relaxed/simple;\n\tbh=Kcuc5Xdw3I0X1wDe1tIZffJ2xBhEeRpjQ+Urye3ls5s=;\n\th=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:\n\t MIME-Version:Content-Type;\n b=cFq1osciUq1Y2p8Cmx5QXQk31UAsK8x6Mwh7PWOIHwz2GVxycZf2KcrD8jVGQaSFRchZMc8I04KkWuUmD6alZJNKTskzN/OX/we4tMx7dfxQznP9zLyyRtc84TCFwbV3EZ7/1ms7sxyrdBLYS7yRVMGl0TYmxDinEjjyARR+b3E=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=ljZ2MCtZ; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1776758785;\n\tbh=Kcuc5Xdw3I0X1wDe1tIZffJ2xBhEeRpjQ+Urye3ls5s=;\n\th=From:To:Cc:Subject:In-Reply-To:References:Date:From;\n\tb=ljZ2MCtZhT2Nfb4GVgTMd7pHrJ/PQKwqmJjfGzTbKds4rZL+SWAUZg4G3cWtUYdzI\n\t PMDLh4rv5n/9ul5eRz1D2otA59ozHuXHOYpPmwj8C9Nlj5yIHAezgfYxsQUCd5rncG\n\t OLYG9kIJH56yy5/H4IdIYOWDcldQZE1EQCaq4vHGo+OOXoOK825fgQIQ9MQIjeP9Aj\n\t sNGnIEHdCykStWD9E1bYdneYypVrVU5CfYrLafdr2mzhPqIenUzQ0750DSxKXDAgy1\n\t 6oOIxH2pcn7P5NInDjtBhFEFPHb7txwTWDqIUSpXV1zaoK4u7cSLQ1/KpmqzkTvME0\n\t aTnK4zzJC4u9w==","From":"Thomas Gleixner <tglx@kernel.org>","To":"neilfsun <loyou85@gmail.com>, 18255117159@163.com","Cc":"bhelgaas@google.com, hans.zhang@cixtech.com,\n linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,\n loyou85@gmail.com, neilfsun@tencent.com, shawn.lin@rock-chips.com","Subject":"Re: [PATCH v2 v2] PCI/MSI: Fix memory leak in\n pci_alloc_irq_vectors_affinity INTx path","In-Reply-To":"<20260421032044.55948-1-neilfsun@tencent.com>","References":"<2caa071e-85ee-4e76-bb33-8f27a4579fac@163.com>\n <20260421032044.55948-1-neilfsun@tencent.com>","Date":"Tue, 21 Apr 2026 10:06:21 +0200","Message-ID":"<878qagd9fm.ffs@tglx>","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","Content-Type":"text/plain"}}]