    ,     -
,   ,   ,    -
 release  ktype  .

 kref

       
kref,     <linux/kref . h>  .

struct kref {

atomic_t refcount;

};

      ,   
  .     ,  -
  .    kref,   -
    kref_init ().

void kref init(struct kref *kref)
{

atomic set(&kref->refcount, 1);

)

   ,      -
  atomic_t  ,  .

,  kref      -
,       kobject.

       kref,  
 kref_get().

void kref get(struct kref *kref)
(

WARN_ON(!atomic_read(&kref->refcount)) ;

atomic inc(&kref->refcount);

}

       .   -
  .      kref, 
  kref_put ().

void kref put(struct kref *kref, void (*release) (struct kref *kref))
{

WARN_ON(release == NULL);

WARN_ON(release == (void (*)(struct kref *))kfree);

if (atomic_dec_and_test(&kref->refcount) )
release (kref);

t

          -
 release (),      ,   -
    .     
WARN_ON () ,  release ()       kfree () ,

362  17