Skip to content

Commit

Permalink
Fix missing function call in error handling path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NOVBobLee committed Nov 5, 2024
1 parent e3e2ee3 commit 620bb0f
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions examples/hello-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static int __init mymodule_init(void)

error = sysfs_create_file(mymodule, &myvariable_attribute.attr);
if (error) {
kobject_put(mymodule);
pr_info("failed to create the myvariable file "
"in /sys/kernel/mymodule\n");
}
Expand Down

0 comments on commit 620bb0f

Please sign in to comment.