linux/arch/sparc
Ma Ke c2640cbea3 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:37:31 +02:00
..
boot kbuild: Abort make on install failures 2024-07-20 13:34:54 +09:00
configs crypto: tcrypt - rename CRYPTO_TEST to CRYPTO_BENCHMARK 2025-05-12 13:32:53 +08:00
crypto lib/crypto: sparc/sha1: Migrate optimized code into library 2025-07-14 11:11:49 -07:00
include Summary of significant series in this pull request: 2025-07-31 14:57:54 -07:00
kernel sparc: fix error handling in scan_one_device() 2025-10-19 16:37:31 +02:00
lib sparc: fix accurate exception reporting in copy_{from,to}_user for M7 2025-10-15 12:04:03 +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:37:31 +02:00
net Modules changes for v6.10-rc1 2024-05-15 14:05:08 -07:00
power sparc64: Fix prototype warnings in hibernate.c 2024-07-11 15:58:28 +02:00
prom sparc64: Fix prototype warning for prom_get_mmu_ihandle 2024-07-11 15:58:28 +02:00
vdso stackleak: Split KSTACK_ERASE_CFLAGS from GCC_PLUGINS_CFLAGS 2025-07-21 21:40:57 -07:00
video arch: Fix name collision with ACPI's video.o 2024-05-20 21:17:06 +00:00
Kbuild kbuild: use more subdir- for visiting subdirectories while cleaning 2021-10-24 13:49:46 +09:00
Kconfig Summary of significant series in this pull request: 2025-07-31 14:57:54 -07:00
Kconfig.debug sparc: select FRAME_POINTER instead of redefining it 2024-02-16 16:50:26 +01:00
Makefile sparc/build: Put usage of -fcall-used* flags behind cc-option 2024-11-16 09:52:56 +01:00