linux/net/atm
Wang Liang 0a228624bc net: atm: fix memory leak in atm_register_sysfs when device_register fail
When device_register() return error in atm_register_sysfs(), which can be
triggered by kzalloc fail in device_private_init() or other reasons,
kmemleak reports the following memory leaks:

unreferenced object 0xffff88810182fb80 (size 8):
  comm "insmod", pid 504, jiffies 4294852464
  hex dump (first 8 bytes):
    61 64 75 6d 6d 79 30 00                          adummy0.
  backtrace (crc 14dfadaf):
    __kmalloc_node_track_caller_noprof+0x335/0x450
    kvasprintf+0xb3/0x130
    kobject_set_name_vargs+0x45/0x120
    dev_set_name+0xa9/0xe0
    atm_register_sysfs+0xf3/0x220
    atm_dev_register+0x40b/0x780
    0xffffffffa000b089
    do_one_initcall+0x89/0x300
    do_init_module+0x27b/0x7d0
    load_module+0x54cd/0x5ff0
    init_module_from_file+0xe4/0x150
    idempotent_init_module+0x32c/0x610
    __x64_sys_finit_module+0xbd/0x120
    do_syscall_64+0xa8/0x270
    entry_SYSCALL_64_after_hwframe+0x77/0x7f

When device_create_file() return error in atm_register_sysfs(), the same
issue also can be triggered.

Function put_device() should be called to release kobj->name memory and
other device resource, instead of kfree().

Fixes: 1fa5ae857b ("driver core: get rid of struct device's bus_id string array")
Signed-off-by: Wang Liang <wangliang74@huawei.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250901063537.1472221-1-wangliang74@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2025-09-04 09:53:44 +02:00
..
addr.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
addr.h
atm_misc.c
atm_sysfs.c net: atm: Remove redundant check. 2023-10-23 08:45:25 +01:00
br2684.c
clip.c atm: clip: Fix NULL pointer dereference in vcc_sendmsg() 2025-07-09 19:09:36 -07:00
common.c atm: atmtcp: Prevent arbitrary write in atmtcp_recv_control(). 2025-08-22 17:23:15 -07:00
common.h
ioctl.c atm: clean up a put_user() calls 2024-06-14 19:08:50 -07:00
Kconfig
lec.c net: atm: fix /proc/net/atm/lec handling 2025-06-19 08:36:31 -07:00
lec.h
lec_arpc.h
Makefile
mpc.c treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
mpc.h
mpoa_caches.c
mpoa_caches.h
mpoa_proc.c
pppoatm.c
proc.c
protocols.h
pvc.c sock: Remove ->sendpage*() in favour of sendmsg(MSG_SPLICE_PAGES) 2023-06-24 15:50:13 -07:00
raw.c atm: Revert atm_account_tx() if copy_from_iter_full() fails. 2025-06-17 18:42:44 -07:00
resources.c net: atm: fix memory leak in atm_register_sysfs when device_register fail 2025-09-04 09:53:44 +02:00
resources.h
signaling.c net: annotate lockless accesses to sk->sk_err_soft 2023-03-17 08:25:05 +00:00
signaling.h
svc.c net: change proto and proto_ops accept type 2024-05-13 18:19:09 -06:00