linux/arch/sparc
Ma Ke 971009a25f sparc: fix error handling in scan_one_device()
commit 302c04110f upstream.

Once of_device_register() failed, we should call put_device() to
decrement reference count for cleanup. Or it could cause memory leak.
So fix this by calling put_device(), then the name can be freed in
kobject_cleanup().

Calling path: of_device_register() -> of_device_add() -> device_add().
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.

Found by code review.

Cc: stable@vger.kernel.org
Fixes: cf44bbc26c ("[SPARC]: Beginnings of generic of_device framework.")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
Reviewed-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2025-10-19 16:21:47 +02:00
..
boot sparc: Add missing "FORCE" target when using if_changed 2021-11-18 19:17:00 +01:00
configs drivers/char: remove /dev/kmem for good 2021-05-07 00:26:34 -07:00
crypto crypto: sparc - Fix sparse endianness warnings 2020-11-27 17:13:42 +11:00
include sched: Add wrapper for get_wchan() to keep task blocked 2025-08-28 16:24:03 +02:00
kernel sparc: fix error handling in scan_one_device() 2025-10-19 16:21:47 +02:00
lib sparc: fix accurate exception reporting in copy_{from,to}_user for M7 2025-10-19 16:21:36 +02:00
math-emu treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
mm sparc64: fix hugetlb for sun4u 2025-10-19 16:21:46 +02:00
net bpf: Introduce BPF nospec instruction for mitigating Spectre v4 2021-07-29 00:20:56 +02:00
power treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
prom sparc64: Fix incorrect function signature and add prototype for prom_cif_init 2024-08-19 05:45:04 +02:00
vdso sparc: vDSO: fix return value of __setup handler 2024-04-10 16:18:34 +02:00
Kbuild treewide: Add SPDX license identifier - Kbuild 2019-05-30 11:32:33 -07:00
Kconfig sparc/cpu: Switch to arch_cpu_finalize_init() 2023-08-08 19:58:31 +02:00
Kconfig.debug tracing: Refactor TRACE_IRQFLAGS_SUPPORT in Kconfig 2021-08-16 11:37:21 -04:00
Makefile sparc: move the install rule to arch/sparc/Makefile 2021-09-03 08:17:20 +09:00