Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

intel_th: fix device leak on output open()

Make sure to drop the reference taken when looking up the th device
during output device open() on errors and on close().

Note that a recent commit fixed the leak in a couple of open() error
paths but not all of them, and the reference is still leaking on
successful open().

Fixes: 39f4034693b7 ("intel_th: Add driver infrastructure for Intel(R) Trace Hub devices")
Fixes: 6d5925b667e4 ("intel_th: Fix error handling in intel_th_output_open")
Cc: stable@vger.kernel.org # 4.4: 6d5925b667e4
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ma Ke <make24@iscas.ac.cn>
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20251208153524.68637-2-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Johan Hovold and committed by
Greg Kroah-Hartman
95fc36a2 10d28cff

+16 -3
+16 -3
drivers/hwtracing/intel_th/core.c
··· 810 810 int err; 811 811 812 812 dev = bus_find_device_by_devt(&intel_th_bus, inode->i_rdev); 813 - if (!dev || !dev->driver) { 813 + if (!dev) 814 + return -ENODEV; 815 + 816 + if (!dev->driver) { 814 817 err = -ENODEV; 815 - goto out_no_device; 818 + goto out_put_device; 816 819 } 817 820 818 821 thdrv = to_intel_th_driver(dev->driver); ··· 839 836 840 837 out_put_device: 841 838 put_device(dev); 842 - out_no_device: 839 + 843 840 return err; 841 + } 842 + 843 + static int intel_th_output_release(struct inode *inode, struct file *file) 844 + { 845 + struct intel_th_device *thdev = file->private_data; 846 + 847 + put_device(&thdev->dev); 848 + 849 + return 0; 844 850 } 845 851 846 852 static const struct file_operations intel_th_output_fops = { 847 853 .open = intel_th_output_open, 854 + .release = intel_th_output_release, 848 855 .llseek = noop_llseek, 849 856 }; 850 857