kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: arrao@cdac.in (Raghavendra)
To: kernelnewbies@lists.kernelnewbies.org
Subject: issues dealing with kobjects
Date: Fri, 20 Jun 2014 11:31:03 +0530	[thread overview]
Message-ID: <53A3CE1F.1070906@cdac.in> (raw)

Hello all,

I am facing a small issue dealing with kobjects.
I am writing a simple i2c driver for which I would like to export a few 
sysfs attributes(files).
The files are many, so I've decided to pack them into a directory in 
sysfs (inside the i2c device) and so I thought of kobjects.

My private data struture is something like this :
struct my_private {
     struct i2c_client *client;
     ...
     struct kobject kobj;
};

In my probe function, I am doing something like this :
int my_probe(struct i2c_client *client, ...)
{
     struct my_private *dev;

     dev = devm_kzalloc(...);
     pr_info("%x", dev);                    /* The address that I got is 
: 0xdbf94210 */

     ....

     /* Init. and add kboject */
     kobject_init(&dev->kobj, client->dev.kobj.ktype);
     kobject_add(&dev->kobj, &client->dev.kobj, "my_dir");

     /* Export sysfs group */
     sysfs_create_group(&dev->kobj, &my_attr_grp);

     ....
}

My show function for one of the attribute is something like this :
ssize_t show(struct kobject *kobj, ... )
{
     struct my_private *dev = container_of(kobj, struct my_private, kobj);
     pr_info("%x", dev);                    /* The address that I got is 
: 0xdbf94208 */

     ....
}

I tried to probe and remove the device mutilple times. Every time I am 
getting a difference of 2bytes for the 'dev'
pointer between probe and show functions.

Can anyone explain me where am I going wrong or is there any better way 
to create directories in sysfs?
I am building this module against 3.13.2 kernel.

Thank you.
Raghavendra.



-------------------------------------------------------------------------------------------------------------------------------
[ C-DAC is on Social-Media too. Kindly follow us at:
Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ]

This e-mail is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. If you are not the
intended recipient, please contact the sender by reply e-mail and destroy
all copies and the original message. Any unauthorized review, use,
disclosure, dissemination, forwarding, printing or copying of this email
is strictly prohibited and appropriate legal action will be taken.
-------------------------------------------------------------------------------------------------------------------------------

             reply	other threads:[~2014-06-20  6:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-20  6:01 Raghavendra [this message]
2014-06-20  6:22 ` issues dealing with kobjects enjoy mindful
2014-06-20  8:24 ` Raghavendra
2014-06-20 16: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=53A3CE1F.1070906@cdac.in \
    --to=arrao@cdac.in \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /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;
as well as URLs for NNTP newsgroup(s).