From: Dan Carpenter <dan.carpenter@oracle.com>
To: linux-kernel@vger.kernel.org,
Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
Cc: kernel-janitors@vger.kernel.org
Subject: [patch] gcov: cleanup an allocation in new_node()
Date: Tue, 11 Sep 2012 11:13:33 +0000 [thread overview]
Message-ID: <20120911111333.GD22259@elgon.mountain> (raw)
1) kcalloc(1, ...) can be replaced with kzalloc().
2) There was a small leak if the debugfs_create_dir() fails.
3) I removed a pr_warning("out of memory\n") because kmalloc() already
prints a more useful failure message in the unlikely case of an
allocation failure.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/kernel/gcov/fs.c b/kernel/gcov/fs.c
index 9bd0934..132168f 100644
--- a/kernel/gcov/fs.c
+++ b/kernel/gcov/fs.c
@@ -437,7 +437,7 @@ static struct gcov_node *new_node(struct gcov_node *parent,
if (!node)
goto err_nomem;
if (info) {
- node->loaded_info = kcalloc(1, sizeof(struct gcov_info *),
+ node->loaded_info = kzalloc(sizeof(struct gcov_info *),
GFP_KERNEL);
if (!node->loaded_info)
goto err_nomem;
@@ -451,8 +451,7 @@ static struct gcov_node *new_node(struct gcov_node *parent,
node->dentry = debugfs_create_dir(node->name, parent->dentry);
if (!node->dentry) {
pr_warning("could not create file\n");
- kfree(node);
- return NULL;
+ goto err_info;
}
if (info)
add_links(node, parent->dentry);
@@ -461,9 +460,11 @@ static struct gcov_node *new_node(struct gcov_node *parent,
return node;
+err_info:
+ if (info)
+ kfree(node->loaded_info);
err_nomem:
kfree(node);
- pr_warning("out of memory\n");
return NULL;
}
next reply other threads:[~2012-09-11 11:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-11 11:13 Dan Carpenter [this message]
2012-09-13 12:43 ` [patch] gcov: cleanup an allocation in new_node() Peter Oberparleiter
2012-09-14 6:52 ` [patch v2] gcov: add a kfree() on error to new_node() Dan Carpenter
2012-09-17 7:58 ` Peter Oberparleiter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120911111333.GD22259@elgon.mountain \
--to=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oberpar@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).