Skip to contentSkip to conversation

hisi_acc_vfio_pci: Fix reference leak in hisi_acc_vfio_debug_init

PATCH In review Miaoqian Lin 3 participants 3 messages Sep 1, 2025 – Sep 2, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hisi_acc_vfio_pci: Fix reference leak in hisi_acc_vfio_debug_init

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")
---
 drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +5 -1
index 2149f49aeec7..1710485cbbec 100644
@@ -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)
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Miaoqian Lin

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")
---
 drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +3 -1
index 2149f49aeec7..1710485cbbec 100644
@@ -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);

drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static void hisi_acc_vfio_debug_init(struct hisi_acc_vf_core_device *hisi_acc_vd · line 1630

Quoted 7 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +2 -0
@@ -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);
 }
 

Thanks!
Longfang.

Quoted 2 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +0 -0
 static void hisi_acc_vf_debugfs_exit(struct hisi_acc_vf_core_device *hisi_acc_vdev)
#2 lore raw
In reply to Miaoqian Lin
Quoted 2 lines

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