Commit e3dc27ee authored by Patrick Mochel's avatar Patrick Mochel

[kobject] Update Documentation and licenses.

- Make it very explicit that supplying an object desctructor is imperative
  if using the interface for object reference counting. 

- Add GPL statement to the source files. 

- Add GFL (http://www.fsf.org/licenses/fdl.html) statement to documentation.
parent 8f9dfd2c
...@@ -2,7 +2,18 @@ The kobject Infrastructure ...@@ -2,7 +2,18 @@ The kobject Infrastructure
Patrick Mochel <mochel@osdl.org> Patrick Mochel <mochel@osdl.org>
7 January 2003 Updated: 3 June 2003
Copyright (c) Patrick Mochel
Copyright (c) Open Source Development Labs
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU
Free Documentation License".
0. Introduction 0. Introduction
...@@ -102,6 +113,28 @@ kobj_type::release() (which the kobject's kset points to) is called. ...@@ -102,6 +113,28 @@ kobj_type::release() (which the kobject's kset points to) is called.
This allows any memory allocated for the object to be freed. This allows any memory allocated for the object to be freed.
NOTE!!!
It is _imperative_ that you supply a desctructor for dynamically
allocated kobjects to free them if you are using kobject reference
counts. The reference count controls the duration of the lifetime of
the object. If it goes to 0, then it is assumed that the object will
be freed and cannot be used.
More importantly, you must free the object there, and not immediately
after an unregister call. If someone else is referencing the object
(e.g. through a sysfs file), they will obtain a reference to the
object, assume it's valid and operate on it. If the object is
unregistered and freed in the meantime, the operation will then
reference freed memory and go boom.
This can be prevented, in the simplest case, by defining a release
method and freeing the object from there only. Note that this will not
secure reference count/object management models that use a dual
reference count or do other wacky things with the reference count
(like the networking layer).
1.4 sysfs 1.4 sysfs
Each kobject receives a directory in sysfs. This directory is created Each kobject receives a directory in sysfs. This directory is created
......
/* /*
* kobject.h - generic kernel object infrastructure. * kobject.h - generic kernel object infrastructure.
* *
* Copyright (c) 2002-2003 Patrick Mochel
* Copyright (c) 2002-2003 Open Source Development Labs
*
* This file is released under the GPLv2.
*
*
* Please read Documentation/kobject.txt before using the kobject
* interface, ESPECIALLY the parts about reference counts and object
* destructors.
*/ */
#if defined(__KERNEL__) && !defined(_KOBJECT_H_) #if defined(__KERNEL__) && !defined(_KOBJECT_H_)
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
* *
* Copyright (c) 2002-2003 Patrick Mochel <mochel@osdl.org> * Copyright (c) 2002-2003 Patrick Mochel <mochel@osdl.org>
* *
* This file is released under the GPLv2.
*
*
* Please see the file Documentation/kobject.txt for critical information
* about using the kobject interface.
*/ */
#undef DEBUG #undef DEBUG
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment