Skip to content

Commit 6d5925b

Browse files
Ma Kegregkh
authored andcommitted
intel_th: Fix error handling in intel_th_output_open
intel_th_output_open() calls bus_find_device_by_devt() which internally increments the device reference count via get_device(), but this reference is not properly released in several error paths. When device driver is unavailable, file operations cannot be obtained, or the driver's open method fails, the function returns without calling put_device(), leading to a permanent device reference count leak. This prevents the device from being properly released and could cause resource exhaustion over time. Found by code review. Cc: stable <stable@kernel.org> Fixes: 39f4034 ("intel_th: Add driver infrastructure for Intel(R) Trace Hub devices") Signed-off-by: Ma Ke <make24@iscas.ac.cn> Link: https://patch.msgid.link/20251112091723.35963-1-make24@iscas.ac.cn Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 43cd4b6 commit 6d5925b

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

  • drivers/hwtracing/intel_th

drivers/hwtracing/intel_th/core.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -810,24 +810,34 @@ static int intel_th_output_open(struct inode *inode, struct file *file)
810810
int err;
811811

812812
dev = bus_find_device_by_devt(&intel_th_bus, inode->i_rdev);
813-
if (!dev || !dev->driver)
814-
return -ENODEV;
813+
if (!dev || !dev->driver) {
814+
err = -ENODEV;
815+
goto out_no_device;
816+
}
815817

816818
thdrv = to_intel_th_driver(dev->driver);
817819
fops = fops_get(thdrv->fops);
818-
if (!fops)
819-
return -ENODEV;
820+
if (!fops) {
821+
err = -ENODEV;
822+
goto out_put_device;
823+
}
820824

821825
replace_fops(file, fops);
822826

823827
file->private_data = to_intel_th_device(dev);
824828

825829
if (file->f_op->open) {
826830
err = file->f_op->open(inode, file);
827-
return err;
831+
if (err)
832+
goto out_put_device;
828833
}
829834

830835
return 0;
836+
837+
out_put_device:
838+
put_device(dev);
839+
out_no_device:
840+
return err;
831841
}
832842

833843
static const struct file_operations intel_th_output_fops = {

0 commit comments

Comments
 (0)