mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Randy Dunlap <randy.dunlap@oracle.com>
To: Greg KH <greg@kroah.com>
Cc: linux-kernel@vger.kernel.org, Kay Sievers <kay.sievers@vrfy.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Jonathan Corbet <corbet@lwn.net>
Subject: Re: [RFC] kobject/kset/ktype documentation and example code updated
Date: Thu, 20 Dec 2007 14:06:59 -0800	[thread overview]
Message-ID: <20071220140659.71f6cce6.randy.dunlap@oracle.com> (raw)
In-Reply-To: <20071220212700.GB5808@kroah.com>

On Thu, 20 Dec 2007 13:27:00 -0800 Greg KH wrote:

> On Wed, Dec 19, 2007 at 10:32:06PM -0800, Randy Dunlap wrote:
> > On Wed, 19 Dec 2007 16:30:31 -0800 Greg KH wrote:
> > 
> > ...
> > >  - A ktype is the type of object that embeds a kobject. Every structure
> > >    that embeds a kobject needs a corresponding ktype.  The ktype controls
> > >    what happens when a kobject is no longer referenced and the kobject's
> > >    default representation in sysfs.
> > 
> > I can't quite parse the last sentence above.  Is it:
> > 
> > The ktype controls (a) what happens ...
> > and (b) the kobject's default representation in sysfs.
> > 
> > ?
> 
> How about:
> 	- A ktype is the type of object that embeds a kobject.  Every
> 	  structure that embeds a kobject needs a corresponding ktype.
> 	  The ktype controls what happens to the kobject when it is
> 	  created and destroyed.

OK.

> > > Embedding kobjects
> > > 
> > > So, for example, the UIO code has a structure that defines the memory
> > > region associated with a uio device:
> > > 
> > > struct uio_mem {
> > > 	struct kobject kobj;
> > > 	unsigned long addr;
> > > 	unsigned long size;
> > > 	int memtype;
> > > 	void __iomem *internal_addr;
> > > };
> > > 
> > > If you have a struct uio_mem structure, finding its embedded kobject is
> > > just a matter of using the kobj structure.  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)
> > > 
> > > 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 to a struct kobject embedded
> > 
> > This is (still) confusing to me.  Is it:
> >                                    a pointer "kp" to a ...
> > or is struct uio_mem the "kp"?
> 
> How about:
> 	 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:

ack.

> > >     int kobject_uevent(struct kobject *kobj, enum kobject_action action);
> > > 
> > > Use the KOBJ_ADD action for when the kobject is first added to the kernel.
> > > This should be done only after any attributes or children of the kobject
> > > have been initialized properly, as userspace will instantly start to look
> > 
> > 		s/will/may/
> 
> No, it's usually a "will", as udev is damm fast these days :)

But that's the point.  It assumes that udev is being used.  :(


> > > Both types of attributes used here, with a kobject that has been created
> > > with the kobject_create_and_add() can be of type kobj_attribute, no special
> > > custom attribute is needed to be created.
> > 
> > ^ multi-run-on sentences....
> 
> Is this better:
> 	Both types of attributes used here, with a kobject that has been
> 	created with the kobject_create_and_add(), can be of type
> 	kobj_attribute, so no special custom attribute is needed to be
> 	created.
> 
> If not, any suggestions?

I'm lost in the twisty maze.  I suppose that will do until someone
can make it better.  ;)


Who is your spell checker?

---
~Randy

  parent reply	other threads:[~2007-12-20 22:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-20  0:30 Greg KH
2007-12-20  0:31 ` [RFC] sample kobject implementation code Greg KH
2007-12-20  0:31 ` [RFC] sample kset/ktype/kobject " Greg KH
2008-01-03 15:14   ` Cornelia Huck
2007-12-20  4:26 ` [RFC] kobject/kset/ktype documentation and example code updated Alan Stern
2007-12-20  7:27   ` Kay Sievers
2007-12-20 21:48   ` Greg KH
2007-12-20  6:32 ` Randy Dunlap
2007-12-20 21:27   ` Greg KH
2007-12-20 22:03     ` Robert P. J. Day
2007-12-20 22:20       ` Greg KH
2007-12-20 22:06     ` Randy Dunlap [this message]
2007-12-20 22:12       ` Greg KH
2007-12-20 22:29         ` Randy Dunlap
2007-12-20 22:42           ` Greg KH
2007-12-20 22:48             ` Randy Dunlap
2007-12-20 22:57     ` Alan Stern
2007-12-20  7:54 ` Dave Young
2007-12-20  8:02   ` Greg KH
2007-12-20  9:04 ` Jan Engelhardt
2007-12-20 21:16   ` 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=20071220140659.71f6cce6.randy.dunlap@oracle.com \
    --to=randy.dunlap@oracle.com \
    --cc=corbet@lwn.net \
    --cc=greg@kroah.com \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --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

Powered by JetHome