linux/drivers/base/firmware_loader
Guangshuo Li 896df22ee5 firmware_loader: fix device reference leak in firmware_upload_register()
firmware_upload_register()
  -> fw_create_instance()
     -> device_initialize()

After fw_create_instance() succeeds, the lifetime of the embedded struct
device is expected to be managed through the device core reference
counting, since fw_create_instance() has already called
device_initialize().

In firmware_upload_register(), if alloc_lookup_fw_priv() fails after
fw_create_instance() succeeds, the code reaches free_fw_sysfs and frees
fw_sysfs directly instead of releasing the device reference with
put_device(). This 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(fw_dev) in the
failure path and letting fw_dev_release() handle the final cleanup,
instead of freeing the instance directly from the error path.

Fixes: 97730bbb24 ("firmware_loader: Add firmware-upload support")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Link: https://patch.msgid.link/20260505091231.607089-1-lgs201920130244@gmail.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
History 2026-05-07 00:44:52 +02:00
..
builtin module: Convert symbol namespace to string literal 2024-12-02 11:34:44 -08:00
fallback.c firmware_loader: Abort all upcoming firmware load request once reboot triggered 2023-10-27 13:30:38 +02:00
fallback.h firmware_loader: Refactor kill_pending_fw_fallback_reqs() 2023-10-27 13:30:38 +02:00
fallback_platform.c firmware: Store opt_flags in fw_priv 2020-10-05 13:37:04 +02:00
fallback_table.c treewide: const qualify ctl_tables where applicable 2025-01-28 13:48:37 +01:00
firmware.h firmware_loader: Abort all upcoming firmware load request once reboot triggered 2023-10-27 13:30:38 +02:00
Kconfig firmware_loader: make RUST_FW_LOADER_ABSTRACTIONS select FW_LOADER 2025-11-26 14:32:10 +01:00
main.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
Makefile firmware_loader: Add firmware-upload support 2022-04-26 12:34:28 +02:00
sysfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
sysfs.h module: Convert symbol namespace to string literal 2024-12-02 11:34:44 -08:00
sysfs_upload.c firmware_loader: fix device reference leak in firmware_upload_register() 2026-05-07 00:44:52 +02:00
sysfs_upload.h firmware_loader: Move definitions from sysfs_upload.h to sysfs.h 2022-04-29 16:49:44 +02:00