};
struct capiminor {
+ struct kref kref;
+
struct capincci *nccip;
unsigned int minor;
struct dentry *capifs_dentry;
return NULL;
}
+ kref_init(&mp->kref);
+
mp->ap = ap;
mp->ncci = ncci;
mp->msgid = 0;
return NULL;
}
-static void capiminor_free(struct capiminor *mp)
+static void capiminor_destroy(struct kref *kref)
{
- unsigned long flags;
-
- tty_unregister_device(capinc_tty_driver, mp->minor);
-
- write_lock_irqsave(&capiminors_lock, flags);
- capiminors[mp->minor] = NULL;
- write_unlock_irqrestore(&capiminors_lock, flags);
+ struct capiminor *mp = container_of(kref, struct capiminor, kref);
kfree_skb(mp->ttyskb);
- mp->ttyskb = NULL;
skb_queue_purge(&mp->inqueue);
skb_queue_purge(&mp->outqueue);
capiminor_del_all_ack(mp);
read_lock(&capiminors_lock);
mp = capiminors[minor];
+ if (mp)
+ kref_get(&mp->kref);
read_unlock(&capiminors_lock);
return mp;
}
+static inline void capiminor_put(struct capiminor *mp)
+{
+ kref_put(&mp->kref, capiminor_destroy);
+}
+
+static void capiminor_free(struct capiminor *mp)
+{
+ unsigned long flags;
+
+ tty_unregister_device(capinc_tty_driver, mp->minor);
+
+ write_lock_irqsave(&capiminors_lock, flags);
+ capiminors[mp->minor] = NULL;
+ write_unlock_irqrestore(&capiminors_lock, flags);
+
+ capiminor_put(mp);
+}
+
/* -------- struct capincci ----------------------------------------- */
static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np)
#endif
if (mp->nccip == NULL)
capiminor_free(mp);
+
+ capiminor_put(mp);
}
#ifdef _DEBUG_REFCOUNT