mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Artem B. Bityutskiy" <dedekind@oktetlabs.ru>
To: linux-kernel@vger.kernel.org
Cc: greg@kroah.com
Subject: [QUESTION/sysfs] strange refcounting
Date: Fri, 03 Feb 2006 17:16:22 +0300	[thread overview]
Message-ID: <43E365B6.4060005@oktetlabs.ru> (raw)

Hello folks,

I'm writing a simple device driver and want to expose some of its 
attributes to userspace via sysfs.

As usually, I have main device description structure "struct 
mydev_info". I've embedded a struct device object there. What I do is:

struct mydev_info mydev
{
	struct device *dev;
	... bla bla bla ...
} mydev;


mydev->dev=kzalloc(sizeof(struct device), GFP_KERNEL);
mydev->dev->bus_id = "mydev";
mydev->dev->release = mydev_release;
err = device_register(&mydev->dev);

Then, I see /sys/devices/mydev/ in sysfs. I open pre-defined 
/sys/devices/mydev/power/state in userspace and don't close it.

Then I run lsmod, and see zero refcount to my module. Well, I run rmmod 
mymod, module is unloaded.

Then I close /sys/devices/mydev/power/state, and enjoy segfault.

I thought sysfs subsystem have to increase module refcount when one 
opens its sysfs files. Well, there is a release function, but it is also 
unloaded with the module.

May be there is a problem because of I have mydev->dev->parent == NULL, 
mydev->dev->bus == NULL, mydev->dev->driver == NULL? But I really don't 
have any bus, any parent and I don't want to introduce struct 
device_driver ...

Kernel is 2.6.15.1.

Although this is my first meet with sysfs, this looks strange.

Thanks.

-- 
Best regards, Artem B. Bityutskiy
Oktet Labs (St. Petersburg), Software Engineer.
+78124286709 (office) +79112449030 (mobile)
E-mail: dedekind@oktetlabs.ru, web: http://www.oktetlabs.ru

             reply	other threads:[~2006-02-03 14:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-03 14:16 Artem B. Bityutskiy [this message]
2006-02-03 17:08 ` Greg KH
2006-02-04  8:13 Artem B. Bityutskiy
2006-02-04 12:04 ` Artem B. Bityutskiy
2006-02-04 13:33   ` Artem B. Bityutskiy
2006-02-06  9:58     ` Artem B. Bityutskiy
2006-02-06 17:20       ` Artem B. Bityutskiy

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=43E365B6.4060005@oktetlabs.ru \
    --to=dedekind@oktetlabs.ru \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®