2023-12-31 08:39:44

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] 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



2023-12-31 08:41:42

by Markus Elfring

[permalink] [raw]
Subject: [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.

Signed-off-by: Markus Elfring <[email protected]>
---
kernel/gcov/fs.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/kernel/gcov/fs.c b/kernel/gcov/fs.c
index 01520689b57c..0fbfa444a388 100644
--- a/kernel/gcov/fs.c
+++ b/kernel/gcov/fs.c
@@ -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


2023-12-31 08:42:41

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] gcov: Return directly after a failed kzalloc() in new_node()

From: 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.

Signed-off-by: Markus Elfring <[email protected]>
---
kernel/gcov/fs.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/gcov/fs.c b/kernel/gcov/fs.c
index 0fbfa444a388..10916c70fad9 100644
--- a/kernel/gcov/fs.c
+++ b/kernel/gcov/fs.c
@@ -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


2023-12-31 08:43:46

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] gcov: Improve exception handling in add_links()

From: 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.

Signed-off-by: Markus Elfring <[email protected]>
---
kernel/gcov/fs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/gcov/fs.c b/kernel/gcov/fs.c
index 10916c70fad9..80c221bb7f20 100644
--- a/kernel/gcov/fs.c
+++ b/kernel/gcov/fs.c
@@ -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