* Freeing a dynamic struct cdev
@ 2005-08-06 13:26 James C. Georgas
2005-08-06 19:21 ` Randy.Dunlap
0 siblings, 1 reply; 5+ messages in thread
From: James C. Georgas @ 2005-08-06 13:26 UTC (permalink / raw)
To: linux-kernel
If I allocate a struct cdev using cdev_alloc(), what function do I call
to free it when I'm done with it?
--
James C. Georgas <jgeorgas@rogers.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Freeing a dynamic struct cdev
2005-08-06 13:26 Freeing a dynamic struct cdev James C. Georgas
@ 2005-08-06 19:21 ` Randy.Dunlap
2005-08-06 19:26 ` James C. Georgas
0 siblings, 1 reply; 5+ messages in thread
From: Randy.Dunlap @ 2005-08-06 19:21 UTC (permalink / raw)
To: James C. Georgas; +Cc: linux-kernel
On Sat, 06 Aug 2005 09:26:15 -0400 James C. Georgas wrote:
> If I allocate a struct cdev using cdev_alloc(), what function do I call
> to free it when I'm done with it?
Should be cdev_put(), which calls kobject_put(), which implements
ref counting (using krefs), so that when the last reference is
going away, the object will be removed.
---
~Randy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Freeing a dynamic struct cdev
2005-08-06 19:21 ` Randy.Dunlap
@ 2005-08-06 19:26 ` James C. Georgas
2005-08-06 19:28 ` Randy.Dunlap
0 siblings, 1 reply; 5+ messages in thread
From: James C. Georgas @ 2005-08-06 19:26 UTC (permalink / raw)
To: Randy.Dunlap; +Cc: linux-kernel
On Sat, 2005-08-06 at 12:21 -0700, Randy.Dunlap wrote:
> On Sat, 06 Aug 2005 09:26:15 -0400 James C. Georgas wrote:
>
> > If I allocate a struct cdev using cdev_alloc(), what function do I call
> > to free it when I'm done with it?
>
> Should be cdev_put(), which calls kobject_put(), which implements
> ref counting (using krefs), so that when the last reference is
> going away, the object will be removed.
>
> ---
> ~Randy
cdev_put() is not an exported symbol in the fs/char_dev.c file. Should
it be?
--
James C. Georgas <jgeorgas@rogers.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Freeing a dynamic struct cdev
2005-08-06 19:26 ` James C. Georgas
@ 2005-08-06 19:28 ` Randy.Dunlap
[not found] ` <1123362724.13845.11.camel@Tachyon.home>
0 siblings, 1 reply; 5+ messages in thread
From: Randy.Dunlap @ 2005-08-06 19:28 UTC (permalink / raw)
To: James C. Georgas; +Cc: linux-kernel
On Sat, 06 Aug 2005 15:26:18 -0400 James C. Georgas wrote:
> On Sat, 2005-08-06 at 12:21 -0700, Randy.Dunlap wrote:
> > On Sat, 06 Aug 2005 09:26:15 -0400 James C. Georgas wrote:
> >
> > > If I allocate a struct cdev using cdev_alloc(), what function do I call
> > > to free it when I'm done with it?
> >
> > Should be cdev_put(), which calls kobject_put(), which implements
> > ref counting (using krefs), so that when the last reference is
> > going away, the object will be removed.
> >
> > ---
> > ~Randy
>
> cdev_put() is not an exported symbol in the fs/char_dev.c file. Should
> it be?
Sorry about that, typo on my part. It's cdev_del().
---
~Randy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Freeing a dynamic struct cdev
[not found] ` <20050806155958.5f3092bc.rdunlap@xenotime.net>
@ 2005-08-07 2:47 ` James C. Georgas
0 siblings, 0 replies; 5+ messages in thread
From: James C. Georgas @ 2005-08-07 2:47 UTC (permalink / raw)
To: Randy.Dunlap; +Cc: linux-kernel
Ok, I really blew it with that last post:
>
> cdev_add() calls:
> kobj_map()
> kobject_get() [indirectly]
>
This is wrong. When I first looked at it, I saw:
cdev_add() -> kobj_map() -> exact_lock() -> cdev_get() -> kobject_get()
but exact_lock() isn't called here; it is only passed as a function
pointer to kobj_map(), and so calling cdev_add() does /not/ increment
the reference count of the struct cdev.
I guess what threw me for a loop here was that I was expecting separate
functions: one to undo cdev_add() and one to undo cdev_alloc(), but
cdev_del() accomplishes both tasks in one function, with the
kobj_unmap() part having no effect, if the cdev is not mapped at the
time of the call.
--
James C. Georgas <jgeorgas@rogers.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-08-07 2:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-06 13:26 Freeing a dynamic struct cdev James C. Georgas
2005-08-06 19:21 ` Randy.Dunlap
2005-08-06 19:26 ` James C. Georgas
2005-08-06 19:28 ` Randy.Dunlap
[not found] ` <1123362724.13845.11.camel@Tachyon.home>
[not found] ` <20050806155958.5f3092bc.rdunlap@xenotime.net>
2005-08-07 2:47 ` James C. Georgas
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).