From 620bb0f5f8f9011acd132b1c0e024dfd24037cb8 Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Tue, 5 Nov 2024 19:48:42 +0800 Subject: [PATCH] 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. --- examples/hello-sysfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/hello-sysfs.c b/examples/hello-sysfs.c index 7fc0e77..a86f4df 100644 --- a/examples/hello-sysfs.c +++ b/examples/hello-sysfs.c @@ -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"); }