From: Changli Gao <xiaosuo@gmail.com>
To: Greg Kroah-Hartman <gregkh@suse.de>
Cc: "Jike Song" <albcamus@gmail.com>,
linux-kernel@vger.kernel.org, Changli Gao <xiaosuo@gmail.com>
Subject: [PATCH v2] drivers: code cleanups
Date: Wed, 14 Jul 2010 17:42:56 +0800 [thread overview]
Message-ID: <1279100576-8680-1-git-send-email-xiaosuo@gmail.com> (raw)
drivers: code cleanups
the first three goto clauses caused kfree(NULL), and the error code returned
by kset->uevent_ops->uevent() wasn't passed to the caller of show_uevent().
This patch also eliminates the unnecessary initializations of env and count.
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
drivers/base/core.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 38bbbd0..76cd4f0 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -274,9 +274,8 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
{
struct kobject *top_kobj;
struct kset *kset;
- struct kobj_uevent_env *env = NULL;
+ struct kobj_uevent_env *env;
int i;
- size_t count = 0;
int retval;
/* search the kset, the device belongs to */
@@ -284,16 +283,16 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
while (!top_kobj->kset && top_kobj->parent)
top_kobj = top_kobj->parent;
if (!top_kobj->kset)
- goto out;
+ return 0;
kset = top_kobj->kset;
if (!kset->uevent_ops || !kset->uevent_ops->uevent)
- goto out;
+ return 0;
/* respect filter */
if (kset->uevent_ops && kset->uevent_ops->filter)
if (!kset->uevent_ops->filter(kset, &dev->kobj))
- goto out;
+ return 0;
env = kzalloc(sizeof(struct kobj_uevent_env), GFP_KERNEL);
if (!env)
@@ -306,10 +305,10 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
/* copy keys to file */
for (i = 0; i < env->envp_idx; i++)
- count += sprintf(&buf[count], "%s\n", env->envp[i]);
+ retval += sprintf(&buf[retval], "%s\n", env->envp[i]);
out:
kfree(env);
- return count;
+ return retval;
}
static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
next reply other threads:[~2010-07-14 9:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-14 9:42 Changli Gao [this message]
2010-07-14 10:02 ` [PATCH v2] drivers: code cleanups Oliver Neukum
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=1279100576-8680-1-git-send-email-xiaosuo@gmail.com \
--to=xiaosuo@gmail.com \
--cc=albcamus@gmail.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
/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