mirror-linux/drivers/counter
Guangshuo Li d9eeb0ea0d counter: Fix refcount leak in counter_alloc() error path
After device_initialize(), the lifetime of the embedded struct device
is expected to be managed through the device core reference counting.

In counter_alloc(), if dev_set_name() fails after device_initialize(),
the error path removes the chrdev, frees the ID, and frees the backing
allocation directly instead of releasing the device reference with
put_device(). This bypasses the normal device lifetime rules and may
leave the reference count of the embedded struct device unbalanced,
resulting in a refcount leak.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Fix this by using put_device() in the dev_set_name() failure path and
let counter_device_release() handle the final cleanup.

Fixes: 4da08477ea ("counter: Set counter device name")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Link: https://lore.kernel.org/r/20260413134604.2861772-1-lgs201920130244@gmail.com
Signed-off-by: William Breathitt Gray <wbg@kernel.org>
2026-05-03 13:48:39 +09:00
..
104-quad-8.c counter: 104-quad-8: Fix incorrect return value in IRQ handler 2025-12-22 20:03:23 +09:00
Kconfig counter: ti-eqep: Allow eQEP driver to be built for K3 devices 2024-07-01 19:05:42 +09:00
Makefile counter: i8254: Introduce the Intel 8254 interface library module 2023-06-08 10:11:17 -04:00
counter-chrdev.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
counter-chrdev.h counter: Add character device interface 2021-10-17 10:53:52 +01:00
counter-core.c counter: Fix refcount leak in counter_alloc() error path 2026-05-03 13:48:39 +09:00
counter-sysfs.c counter: sysfs: remove double return in counter_sysfs_attr_add() 2026-03-21 22:41:51 +09:00
counter-sysfs.h counter: Internalize sysfs interface code 2021-10-17 10:52:58 +01:00
ftm-quaddec.c module: Convert symbol namespace to string literal 2024-12-02 11:34:44 -08:00
i8254.c module: Convert symbol namespace to string literal 2024-12-02 11:34:44 -08:00
intel-qep.c module: Convert symbol namespace to string literal 2024-12-02 11:34:44 -08:00
interrupt-cnt.c counter: interrupt-cnt: Drop IRQF_NO_THREAD flag 2025-12-22 19:39:58 +09:00
microchip-tcb-capture.c counter: microchip-tcb-capture: Allow shared IRQ for multi-channel TCBs 2025-10-13 14:56:30 +09:00
rz-mtu3-cnt.c counter: rz-mtu3-cnt: do not use struct rz_mtu3_channel's dev member 2026-03-22 15:59:22 +09:00
stm32-lptimer-cnt.c counter: stm32-lptimer-cnt: fix error handling when enabling 2025-03-04 19:23:02 +09:00
stm32-timer-cnt.c counter: stm32-timer-cnt: add support for stm32mp25 2025-05-15 09:20:12 +09:00
ti-ecap-capture.c counter: ti-ecap-capture: Use devm_pm_runtime_enable() 2025-08-24 17:02:03 +09:00
ti-eqep.c counter: ti-eqep: add direction support 2025-02-05 13:22:04 +09:00