gcov: Adjustments for two function implementations
Subsystems (2)
cover gcov: Adjustments for two function implementations
From: Markus Elfring <[email protected]>
Date: Sun, 31 Dec 2023 09:34:56 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Delete an error message for a failed memory allocation in new_node() Return directly after a failed kzalloc() in new_node() Improve exception handling in add_links()
kernel/gcov/fs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
--
2.43.0
PATCH 1/3 gcov: Delete an error message for a failed memory allocation in new_node()
From: Markus Elfring <[email protected]>
Date: Sun, 31 Dec 2023 09:09:25 +0100
Omit an extra message for a memory allocation failure in this function.
--- kernel/gcov/fs.c | 1 - 1 file changed, 1 deletion(-)
kernel/gcov/fs.c +0 -1
@@ -566,7 +566,6 @@ static struct gcov_node *new_node(struct gcov_node *parent, err_nomem:kfree (node); -pr_warn ("out of memory\n" );return NULL ; }
--
2.43.0
PATCH 2/3 gcov: Return directly after a failed kzalloc() in new_node()
In reply to Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 31 Dec 2023 09:12:44 +0100
The kfree() function was called in one case by the new_node() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software.
Thus return directly after a call of the function “kzalloc” failed at the beginning.
--- kernel/gcov/fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/gcov/fs.c +2 -1
@@ -543,7 +543,8 @@ static struct gcov_node *new_node(struct gcov_node *parent, node =kzalloc (sizeof (struct gcov_node ) +strlen (name) +1 ,GFP_KERNEL );if (!node) - goto err_nomem; +return NULL ; +if (info) { node->loaded_info =kcalloc (1 ,sizeof (struct gcov_info *),GFP_KERNEL );
--
2.43.0
PATCH 3/3 gcov: Improve exception handling in add_links()
In reply to Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 31 Dec 2023 09:23:50 +0100
The kfree() function was called in one case by the add_links() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software.
Thus use another label.
--- kernel/gcov/fs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/gcov/fs.c +3 -1
@@ -490,7 +490,8 @@ static void add_links(struct gcov_node *node, struct dentry *parent)gcov_info_filename (get_node_info (node)), &gcov_link[i]);if (!target) - goto out_err; + goto remove_links; + basename =kbasename (target);if (basename == target) goto out_err;
@@ -502,6 +503,7 @@ static void add_links(struct gcov_node *node, struct dentry *parent)return ; out_err:kfree (target); +remove_links:while (i-- >0 )debugfs_remove (node->links[i]);kfree (node->links);
--
2.43.0