Skip to content

Commit 620bb0f

Browse files
committed
Fix missing function call in error handling path
Previously, the code did not call kobject_put when sysfs_create_file failed, leading to a potential memory leak. This commit adds the missing kobject_put to ensure proper resource cleanup.
1 parent e3e2ee3 commit 620bb0f

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

examples/hello-sysfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static int __init mymodule_init(void)
4242

4343
error = sysfs_create_file(mymodule, &myvariable_attribute.attr);
4444
if (error) {
45+
kobject_put(mymodule);
4546
pr_info("failed to create the myvariable file "
4647
"in /sys/kernel/mymodule\n");
4748
}

0 commit comments

Comments
 (0)