* [PATCH] hisi_acc_vfio_pci: Fix reference leak in hisi_acc_vfio_debug_init
@ 2025-09-01 8:18 Miaoqian Lin
2025-09-02 2:23 ` liulongfang
2025-09-02 11:47 ` Markus Elfring
0 siblings, 2 replies; 3+ messages in thread
From: Miaoqian Lin @ 2025-09-01 8:18 UTC (permalink / raw)
To: Longfang Liu, Shameer Kolothum, Jason Gunthorpe, Yishai Hadas,
Kevin Tian, Alex Williamson, kvm, linux-kernel
Cc: linmq006, stable
The debugfs_lookup() function returns a dentry with an increased reference
count that must be released by calling dput().
Fixes: b398f91779b8 ("hisi_acc_vfio_pci: register debugfs for hisilicon migration driver")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
index 2149f49aeec7..1710485cbbec 100644
--- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
+++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
@@ -1611,8 +1611,10 @@ static void hisi_acc_vfio_debug_init(struct hisi_acc_vf_core_device *hisi_acc_vd
}
migf = kzalloc(sizeof(*migf), GFP_KERNEL);
- if (!migf)
+ if (!migf) {
+ dput(vfio_dev_migration);
return;
+ }
hisi_acc_vdev->debug_migf = migf;
vfio_hisi_acc = debugfs_create_dir("hisi_acc", vfio_dev_migration);
@@ -1622,6 +1624,8 @@ static void hisi_acc_vfio_debug_init(struct hisi_acc_vf_core_device *hisi_acc_vd
hisi_acc_vf_migf_read);
debugfs_create_devm_seqfile(dev, "cmd_state", vfio_hisi_acc,
hisi_acc_vf_debug_cmd);
+
+ dput(vfio_dev_migration);
}
static void hisi_acc_vf_debugfs_exit(struct hisi_acc_vf_core_device *hisi_acc_vdev)
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hisi_acc_vfio_pci: Fix reference leak in hisi_acc_vfio_debug_init
2025-09-01 8:18 [PATCH] hisi_acc_vfio_pci: Fix reference leak in hisi_acc_vfio_debug_init Miaoqian Lin
@ 2025-09-02 2:23 ` liulongfang
2025-09-02 11:47 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: liulongfang @ 2025-09-02 2:23 UTC (permalink / raw)
To: Miaoqian Lin, Shameer Kolothum, Jason Gunthorpe, Yishai Hadas,
Kevin Tian, Alex Williamson, kvm, linux-kernel
Cc: stable
On 2025/9/1 16:18, Miaoqian Lin wrote:
> The debugfs_lookup() function returns a dentry with an increased reference
> count that must be released by calling dput().
>
> Fixes: b398f91779b8 ("hisi_acc_vfio_pci: register debugfs for hisilicon migration driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> index 2149f49aeec7..1710485cbbec 100644
> --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> @@ -1611,8 +1611,10 @@ static void hisi_acc_vfio_debug_init(struct hisi_acc_vf_core_device *hisi_acc_vd
> }
>
> migf = kzalloc(sizeof(*migf), GFP_KERNEL);
> - if (!migf)
> + if (!migf) {
> + dput(vfio_dev_migration);
> return;
> + }
> hisi_acc_vdev->debug_migf = migf;
>
> vfio_hisi_acc = debugfs_create_dir("hisi_acc", vfio_dev_migration);
> @@ -1622,6 +1624,8 @@ static void hisi_acc_vfio_debug_init(struct hisi_acc_vf_core_device *hisi_acc_vd
> hisi_acc_vf_migf_read);
> debugfs_create_devm_seqfile(dev, "cmd_state", vfio_hisi_acc,
> hisi_acc_vf_debug_cmd);
> +
> + dput(vfio_dev_migration);
> }
>
Reviewed-by: Longfang Liu <liulongfang@huawei.com>
Thanks!
Longfang.
> static void hisi_acc_vf_debugfs_exit(struct hisi_acc_vf_core_device *hisi_acc_vdev)
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hisi_acc_vfio_pci: Fix reference leak in hisi_acc_vfio_debug_init
2025-09-01 8:18 [PATCH] hisi_acc_vfio_pci: Fix reference leak in hisi_acc_vfio_debug_init Miaoqian Lin
2025-09-02 2:23 ` liulongfang
@ 2025-09-02 11:47 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-09-02 11:47 UTC (permalink / raw)
To: Miaoqian Lin, kvm
Cc: stable, LKML, Alex Williamson, Jason Gunthorpe, Kevin Tian,
Longfang Liu, Shameer Kolothum, Yishai Hadas
> The debugfs_lookup() function returns a dentry with an increased reference
> count that must be released by calling dput().
* See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc4#n94
* Would you like to complete the object clean-up by using a goto chain?
* How do you think about to increase the application of scope-based resource management?
https://elixir.bootlin.com/linux/v6.17-rc4/source/include/linux/pci.h#L1208
* Would it be helpful to append parentheses to the function name
in the summary phrase?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-02 11:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-01 8:18 [PATCH] hisi_acc_vfio_pci: Fix reference leak in hisi_acc_vfio_debug_init Miaoqian Lin
2025-09-02 2:23 ` liulongfang
2025-09-02 11:47 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).