From: Greg KH <greg@kroah.com>
To: Cornelia Huck <cornelia.huck@de.ibm.com>,
Kay Sievers <kay.sievers@vrfy.org>,
Alan Stern <stern@rowland.harvard.edu>
Cc: Kernel development list <linux-kernel@vger.kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Randy Dunlap <randy.dunlap@oracle.com>
Subject: [RFC] kobject: convert some users of kobject_init to the new functions.
Date: Fri, 30 Nov 2007 11:54:45 -0800 [thread overview]
Message-ID: <20071130195445.GC4659@kroah.com> (raw)
In-Reply-To: <20071130195300.GB4659@kroah.com>
This converts the kernel/ directory and the char_dev directory to use
the new kobject_init functions as an example and test of them.
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
fs/char_dev.c | 18 ++++++++++++++----
kernel/module.c | 12 ++++--------
kernel/params.c | 5 +----
kernel/user.c | 5 +----
mm/slub.c | 5 +----
5 files changed, 21 insertions(+), 24 deletions(-)
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -509,10 +509,15 @@ static struct kobj_type ktype_cdev_dynam
struct cdev *cdev_alloc(void)
{
struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL);
+ int ret;
+
if (p) {
- p->kobj.ktype = &ktype_cdev_dynamic;
INIT_LIST_HEAD(&p->list);
- kobject_init(&p->kobj);
+ ret = kobject_init_ng(&p->kobj, &ktype_cdev_dynamic, NULL,
+ "cdev_dynamic");
+ if (ret)
+ printk(KERN_ERR "cdev: something went wrong "
+ "initializing the dynamic kobject!\n");
}
return p;
}
@@ -527,10 +532,15 @@ struct cdev *cdev_alloc(void)
*/
void cdev_init(struct cdev *cdev, const struct file_operations *fops)
{
+ int ret;
+
memset(cdev, 0, sizeof *cdev);
INIT_LIST_HEAD(&cdev->list);
- cdev->kobj.ktype = &ktype_cdev_default;
- kobject_init(&cdev->kobj);
+ ret = kobject_init_ng(&cdev->kobj, &ktype_cdev_default, NULL,
+ "cdev_static");
+ if (ret)
+ printk(KERN_ERR "cdev: something went very wrong initializing "
+ "the static kobject!\n");
cdev->ops = fops;
}
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1218,18 +1218,14 @@ int mod_sysfs_init(struct module *mod)
err = -EINVAL;
goto out;
}
- memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
- err = kobject_set_name(&mod->mkobj.kobj, "%s", mod->name);
- if (err)
- goto out;
- mod->mkobj.kobj.kset = module_kset;
- mod->mkobj.kobj.ktype = &module_ktype;
mod->mkobj.mod = mod;
- kobject_init(&mod->mkobj.kobj);
+ memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
+ mod->mkobj.kobj.kset = module_kset;
+ err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL,
+ "%s", mod->name);
/* delay uevent until full sysfs population */
- err = kobject_add(&mod->mkobj.kobj);
out:
return err;
}
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -561,10 +561,7 @@ static void __init kernel_param_sysfs_se
mk->mod = THIS_MODULE;
mk->kobj.kset = module_kset;
- mk->kobj.ktype = &module_ktype;
- kobject_set_name(&mk->kobj, name);
- kobject_init(&mk->kobj);
- ret = kobject_add(&mk->kobj);
+ ret = kobject_init_and_add(&mk->kobj, &module_ktype, NULL, "%s", name);
if (ret) {
printk(KERN_ERR "Module '%s' failed to be added to sysfs, "
"error number %d\n", name, ret);
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -181,11 +181,8 @@ static int uids_user_create(struct user_
int error;
memset(kobj, 0, sizeof(struct kobject));
- kobj->ktype = &uids_ktype;
kobj->kset = uids_kset;
- kobject_init(kobj);
- kobject_set_name(&up->kobj, "%d", up->uid);
- error = kobject_add(kobj);
+ error = kobject_init_and_add(kobj, &uids_ktype, NULL, "%d", up->uid);
if (error)
goto done;
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4021,11 +4021,8 @@ static int sysfs_slab_add(struct kmem_ca
name = create_unique_id(s);
}
- kobject_set_name(&s->kobj, name);
s->kobj.kset = slab_kset;
- s->kobj.ktype = &slab_ktype;
- kobject_init(&s->kobj);
- err = kobject_add(&s->kobj);
+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
if (err)
return err;
next prev parent reply other threads:[~2007-11-30 19:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-30 19:51 [RFC] kobject_init changes Greg KH
2007-11-30 19:53 ` [RFC] kobject: add kobject_init_ng and kobject_init_and_add functions Greg KH
2007-11-30 19:54 ` Greg KH [this message]
2007-11-30 20:25 ` Alan Stern
2007-11-30 21:04 ` Greg KH
2007-11-30 21:07 ` Greg KH
2007-11-30 21:19 ` Alan Stern
2007-11-30 21:48 ` Greg KH
2007-11-30 22:10 ` Alan Stern
2007-11-30 22:26 ` Greg KH
2007-11-30 23:22 ` Alan Stern
2007-12-01 0:58 ` Greg KH
2007-11-30 22:33 ` Greg KH
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=20071130195445.GC4659@kroah.com \
--to=greg@kroah.com \
--cc=corbet@lwn.net \
--cc=cornelia.huck@de.ibm.com \
--cc=kay.sievers@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
--cc=randy.dunlap@oracle.com \
--cc=stern@rowland.harvard.edu \
/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