Linux kernel module reference count.

Need to check Linux kernel module reference count. So add a dump_stack to places (here and here) when get a reference on module.

If a Linux kernel module export a character device (similarly for block device), and a user space application open the device, how many reference count will add? I thought it will be one, but answer is two.

[<c0103350>] show_trace+0xd/0xf
[<c0103422>] dump_stack+0x17/0x19
[<c0155d16>] cdev_get+0x13/0x4d
[<c0155f55>] exact_lock+0xa/0x11
[<c023c7cd>] kobj_lookup+0xb3/0x133
[<c0155dc6>] chrdev_open+0x49/0x142
[<c014daaa>] __dentry_open+0xbc/0x182
[<c014dc39>] nameidata_to_filp+0x1c/0x2e
[<c014db9e>] do_filp_open+0x2e/0x35
[<c014de1e>] do_sys_open+0x38/0x6d
[<c014de69>] sys_open+0x16/0x18
[<c0102579>] sysenter_past_esp+0x56/0x8d

http://lxr.linux.no/source/fs/char_dev.c?v=2.6.11#L289

[<c0103350>] show_trace+0xd/0xf
[<c0103422>] dump_stack+0x17/0x19
[<c0155e6c>] chrdev_open+0xef/0x142
[<c014daaa>] __dentry_open+0xbc/0x182
[<c014dc39>] nameidata_to_filp+0x1c/0x2e
[<c014db9e>] do_filp_open+0x2e/0x35
[<c014de1e>] do_sys_open+0x38/0x6d
[<c014de69>] sys_open+0x16/0x18
[<c0102579>] sysenter_past_esp+0x56/0x8d

http://lxr.linux.no/source/fs/char_dev.c?v=2.6.11#L308

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: