Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
764dfe0b
Commit
764dfe0b
authored
Aug 24, 2004
by
Greg Kroah-Hartman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kobject: convert struct kobject use kref.
Signed-off-by:
Greg Kroah-Hartman
<
greg@kroah.com
>
parent
4abd21a8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
14 deletions
+13
-14
include/linux/kobject.h
include/linux/kobject.h
+2
-1
lib/Makefile
lib/Makefile
+1
-4
lib/kobject.c
lib/kobject.c
+10
-9
No files found.
include/linux/kobject.h
View file @
764dfe0b
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include <linux/list.h>
#include <linux/list.h>
#include <linux/sysfs.h>
#include <linux/sysfs.h>
#include <linux/rwsem.h>
#include <linux/rwsem.h>
#include <linux/kref.h>
#include <asm/atomic.h>
#include <asm/atomic.h>
#define KOBJ_NAME_LEN 20
#define KOBJ_NAME_LEN 20
...
@@ -26,7 +27,7 @@
...
@@ -26,7 +27,7 @@
struct
kobject
{
struct
kobject
{
char
*
k_name
;
char
*
k_name
;
char
name
[
KOBJ_NAME_LEN
];
char
name
[
KOBJ_NAME_LEN
];
atomic_t
refcount
;
struct
kref
kref
;
struct
list_head
entry
;
struct
list_head
entry
;
struct
kobject
*
parent
;
struct
kobject
*
parent
;
struct
kset
*
kset
;
struct
kset
*
kset
;
...
...
lib/Makefile
View file @
764dfe0b
...
@@ -5,12 +5,9 @@
...
@@ -5,12 +5,9 @@
lib-y
:=
errno.o ctype.o string.o vsprintf.o cmdline.o
\
lib-y
:=
errno.o ctype.o string.o vsprintf.o cmdline.o
\
bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o
\
bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o
\
kobject.o idr.o div64.o parser.o int_sqrt.o
\
kobject.o
kref.o
idr.o div64.o parser.o int_sqrt.o
\
bitmap.o extable.o
bitmap.o extable.o
# hack for now till some static code uses krefs, then it can move up above...
obj-y
+=
kref.o
lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK)
+=
rwsem-spinlock.o
lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK)
+=
rwsem-spinlock.o
lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM)
+=
rwsem.o
lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM)
+=
rwsem.o
...
...
lib/kobject.c
View file @
764dfe0b
...
@@ -243,10 +243,9 @@ void kobject_hotplug(const char *action, struct kobject *kobj)
...
@@ -243,10 +243,9 @@ void kobject_hotplug(const char *action, struct kobject *kobj)
* kobject_init - initialize object.
* kobject_init - initialize object.
* @kobj: object in question.
* @kobj: object in question.
*/
*/
void
kobject_init
(
struct
kobject
*
kobj
)
void
kobject_init
(
struct
kobject
*
kobj
)
{
{
atomic_set
(
&
kobj
->
refcount
,
1
);
kref_init
(
&
kobj
->
kref
);
INIT_LIST_HEAD
(
&
kobj
->
entry
);
INIT_LIST_HEAD
(
&
kobj
->
entry
);
kobj
->
kset
=
kset_get
(
kobj
->
kset
);
kobj
->
kset
=
kset_get
(
kobj
->
kset
);
}
}
...
@@ -447,10 +446,8 @@ void kobject_unregister(struct kobject * kobj)
...
@@ -447,10 +446,8 @@ void kobject_unregister(struct kobject * kobj)
struct
kobject
*
kobject_get
(
struct
kobject
*
kobj
)
struct
kobject
*
kobject_get
(
struct
kobject
*
kobj
)
{
{
if
(
kobj
)
{
if
(
kobj
)
WARN_ON
(
!
atomic_read
(
&
kobj
->
refcount
));
kref_get
(
&
kobj
->
kref
);
atomic_inc
(
&
kobj
->
refcount
);
}
return
kobj
;
return
kobj
;
}
}
...
@@ -477,17 +474,21 @@ void kobject_cleanup(struct kobject * kobj)
...
@@ -477,17 +474,21 @@ void kobject_cleanup(struct kobject * kobj)
kobject_put
(
parent
);
kobject_put
(
parent
);
}
}
static
void
kobject_release
(
struct
kref
*
kref
)
{
kobject_cleanup
(
container_of
(
kref
,
struct
kobject
,
kref
));
}
/**
/**
* kobject_put - decrement refcount for object.
* kobject_put - decrement refcount for object.
* @kobj: object.
* @kobj: object.
*
*
* Decrement the refcount, and if 0, call kobject_cleanup().
* Decrement the refcount, and if 0, call kobject_cleanup().
*/
*/
void
kobject_put
(
struct
kobject
*
kobj
)
void
kobject_put
(
struct
kobject
*
kobj
)
{
{
if
(
atomic_dec_and_test
(
&
kobj
->
refcount
)
)
if
(
kobj
)
k
object_cleanup
(
kobj
);
k
ref_put
(
&
kobj
->
kref
,
kobject_release
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment