kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: chris@basementcode.com (Christopher Harvey)
To: kernelnewbies@lists.kernelnewbies.org
Subject: having trouble getting device from kobject
Date: Thu, 25 Oct 2012 10:22:31 -0500	[thread overview]
Message-ID: <dc1c9d6e216d0d24d9218848596e9b6e@basementcode.com> (raw)

I added an entry to a sysfs device (drivers/mtd/nand/omap2.c) like 
this:

static int __devinit omap_nand_probe(struct platform_device *pdev)
{
    ...
    ...

	ret = sysfs_create_group(&pdev->dev.kobj, &ef_group);
	if (ret) {
		err = -ENOMEM;
		goto out_free_info;
	}

    ...
    ...
}

that works, I get the following files:
/sys/devices/platform/omap2-nand.0/0xEF/set
/sys/devices/platform/omap2-nand.0/0xEF/unset
(I added the 0xEF directory and the set and unset files)

then in the store function of one of the attributes I do this, in an 
attempt to get the original pdev back:

static ssize_t EF_set_store(struct kobject *kobj, struct kobj_attribute 
*attr,
			 const char *buf, size_t count)
{
	struct kobject *nand_kobj = kobj->parent;
	struct device *dev = container_of(nand_kobj, struct device, kobj);
	struct platform_device *pdev = container_of(dev, struct 
platform_device, dev);

	printk(KERN_ALERT "pdev is 0x%x\n", (unsigned int)pdev);

	return count;
}

but I'm not getting the same address back. Not sure why.

thanks,
Chris

                 reply	other threads:[~2012-10-25 15:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=dc1c9d6e216d0d24d9218848596e9b6e@basementcode.com \
    --to=chris@basementcode.com \
    --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).