All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: "Robert P. J. Day" <rpjday@crashcourse.ca>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 08/12] kobject: documentation: Fix erroneous example in kobject doc.
Date: Fri, 19 Mar 2010 08:18:51 -0700	[thread overview]
Message-ID: <1269011935-8886-8-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20100319151311.GA8541@kroah.com>

From: Robert P. J. Day <rpjday@crashcourse.ca>

Replace uio_mem example for kobjects with uio_map, since the uio_mem
struct no longer contains a kobject.

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 Documentation/kobject.txt |   57 ++++++++++++++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt
index bdb1381..668cb83 100644
--- a/Documentation/kobject.txt
+++ b/Documentation/kobject.txt
@@ -59,37 +59,56 @@ nice to have in other objects.  The C language does not allow for the
 direct expression of inheritance, so other techniques - such as structure
 embedding - must be used.
 
-So, for example, the UIO code has a structure that defines the memory
-region associated with a uio device:
+(As an aside, for those familiar with the kernel linked list implementation,
+this is analogous as to how "list_head" structs are rarely useful on
+their own, but are invariably found embedded in the larger objects of
+interest.)
 
-struct uio_mem {
+So, for example, the UIO code in drivers/uio/uio.c has a structure that
+defines the memory region associated with a uio device:
+
+    struct uio_map {
 	struct kobject kobj;
-	unsigned long addr;
-	unsigned long size;
-	int memtype;
-	void __iomem *internal_addr;
-};
+	struct uio_mem *mem;
+    };
 
-If you have a struct uio_mem structure, finding its embedded kobject is
+If you have a struct uio_map structure, finding its embedded kobject is
 just a matter of using the kobj member.  Code that works with kobjects will
 often have the opposite problem, however: given a struct kobject pointer,
 what is the pointer to the containing structure?  You must avoid tricks
 (such as assuming that the kobject is at the beginning of the structure)
 and, instead, use the container_of() macro, found in <linux/kernel.h>:
 
-	container_of(pointer, type, member)
+    container_of(pointer, type, member)
+
+where:
+
+  * "pointer" is the pointer to the embedded kobject,
+  * "type" is the type of the containing structure, and
+  * "member" is the name of the structure field to which "pointer" points.
+
+The return value from container_of() is a pointer to the corresponding
+container type. So, for example, a pointer "kp" to a struct kobject
+embedded *within* a struct uio_map could be converted to a pointer to the
+*containing* uio_map structure with:
+
+    struct uio_map *u_map = container_of(kp, struct uio_map, kobj);
+
+For convenience, programmers often define a simple macro for "back-casting"
+kobject pointers to the containing type.  Exactly this happens in the
+earlier drivers/uio/uio.c, as you can see here:
+
+    struct uio_map {
+        struct kobject kobj;
+        struct uio_mem *mem;
+    };
 
-where pointer is the pointer to the embedded kobject, type is the type of
-the containing structure, and member is the name of the structure field to
-which pointer points.  The return value from container_of() is a pointer to
-the given type. So, for example, a pointer "kp" to a struct kobject
-embedded within a struct uio_mem could be converted to a pointer to the
-containing uio_mem structure with:
+    #define to_map(map) container_of(map, struct uio_map, kobj)
 
-    struct uio_mem *u_mem = container_of(kp, struct uio_mem, kobj);
+where the macro argument "map" is a pointer to the struct kobject in
+question.  That macro is subsequently invoked with:
 
-Programmers often define a simple macro for "back-casting" kobject pointers
-to the containing type.
+    struct uio_map *map = to_map(kobj);
 
 
 Initialization of kobjects
-- 
1.7.0.2


  parent reply	other threads:[~2010-03-19 15:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-19 15:13 [GIT PATCH] driver core fixes for 2.6.34-git Greg KH
2010-03-19 15:18 ` [PATCH 01/12] sysfs: use sysfs_bin_attr_init in firmware class driver Greg Kroah-Hartman
2010-03-19 15:18 ` [PATCH 02/12] sysfs: Initialised pci bus legacy_mem field before use Greg Kroah-Hartman
2010-03-19 15:18 ` [PATCH 03/12] sysfs: fix sysfs lockdep warning in ipmi code Greg Kroah-Hartman
2010-03-19 15:18 ` [PATCH 04/12] sysfs: fix sysfs lockdep warning in infiniband code Greg Kroah-Hartman
2010-03-19 15:18 ` [PATCH 05/12] sysfs: fix sysfs lockdep warning in mlx4 code Greg Kroah-Hartman
2010-03-19 15:18 ` [PATCH 06/12] Driver core: Early platform kernel-doc update Greg Kroah-Hartman
2010-03-19 15:18 ` [PATCH 07/12] driver-core: fix missing kernel-doc in firmware_class Greg Kroah-Hartman
2010-03-19 15:18 ` Greg Kroah-Hartman [this message]
2010-03-19 15:18 ` [PATCH 09/12] sysdev: the cpu probe/release attributes should be sysdev_class_attributes Greg Kroah-Hartman
2010-03-19 15:18 ` [PATCH 10/12] kobject: documentation: Update to refer to kset-example.c Greg Kroah-Hartman
2010-03-19 15:18 ` [PATCH 11/12] driver-core: document ERR_PTR() return values Greg Kroah-Hartman
2010-03-19 15:18 ` [PATCH 12/12] driver core: numa: fix BUILD_BUG_ON for node_read_distance Greg Kroah-Hartman

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=1269011935-8886-8-git-send-email-gregkh@suse.de \
    --to=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpjday@crashcourse.ca \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.