Skip to content

Commit 187c8be

Browse files
2045geminigregkh
authored andcommitted
soundwire: debugfs: initialize firmware_file to empty string
[ Upstream commit 7215e45 ] Passing NULL to debugfs_create_str() causes a NULL pointer dereference, and creating debugfs nodes with NULL string pointers is no longer permitted. Additionally, firmware_file is a global pointer. Previously, adding every new slave blindly overwrote it with NULL. Fix these issues by initializing firmware_file to an allocated empty string once in the subsystem init path (sdw_debugfs_init), and freeing it in the exit path. Existing driver code handles empty strings correctly. Fixes: fe46d2a ("soundwire: debugfs: add interface to read/write commands") Reported-by: yangshiguang <yangshiguang@xiaomi.com> Closes: https://lore.kernel.org/lkml/17647e4c.d461.19b46144a4e.Coremail.yangshiguang1011@163.com/ Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com> Link: https://patch.msgid.link/20260323085930.88894-4-hanguidong02@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent bfe63c1 commit 187c8be

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

drivers/soundwire/debugfs.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ void sdw_slave_debugfs_init(struct sdw_slave *slave)
350350
debugfs_create_file("go", 0200, d, slave, &cmd_go_fops);
351351

352352
debugfs_create_file("read_buffer", 0400, d, slave, &read_buffer_fops);
353-
firmware_file = NULL;
354-
debugfs_create_str("firmware_file", 0200, d, &firmware_file);
353+
if (firmware_file)
354+
debugfs_create_str("firmware_file", 0200, d, &firmware_file);
355355

356356
slave->debugfs = d;
357357
}
@@ -363,10 +363,15 @@ void sdw_slave_debugfs_exit(struct sdw_slave *slave)
363363

364364
void sdw_debugfs_init(void)
365365
{
366+
if (!firmware_file)
367+
firmware_file = kstrdup("", GFP_KERNEL);
368+
366369
sdw_debugfs_root = debugfs_create_dir("soundwire", NULL);
367370
}
368371

369372
void sdw_debugfs_exit(void)
370373
{
371374
debugfs_remove_recursive(sdw_debugfs_root);
375+
kfree(firmware_file);
376+
firmware_file = NULL;
372377
}

0 commit comments

Comments
 (0)