Kyle Moffett a écrit :On Jan 30, 2006, at 00:19, Eric Dumazet wrote:- if (atomic_dec_and_test(&kref->refcount)) {Uhh, I think you got this test reversed. Didn't you mean != 1? Otherwise you only do the dec_and_test when the refcount is one, which means that you leak everything kref-ed.
+ /*
+ * if current count is one, we are the last user and can release object
+ * right now, avoiding an atomic operation on 'refcount'
+ */
+ if ((atomic_read(&kref->refcount) == 1) ||
Not at all :)
Your mail is just another proof why kref is a good abstraction :)
If you are the last user of a kref, (refcount = 1), then
you are sure that nobody else but you is using the object, and as we are kref_put() this object, the atomic_dec_and-test *will* set the count the object and you are going to release() object.
The release() function is not going to look at kref_count again, just free the resources and the object.