Commit 144ad330 authored by Syam Sidhardhan's avatar Syam Sidhardhan Committed by Gustavo Padovan

Bluetooth: Use kref for l2cap channel reference counting

This patch changes the struct l2cap_chan and associated code to use
kref api for object refcounting and freeing.
Suggested-by: default avatarAndrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: default avatarJaganath Kanakkassery <jaganath.k@samsung.com>
Signed-off-by: default avatarSyam Sidhardhan <s.syam@samsung.com>
Signed-off-by: default avatarGustavo Padovan <gustavo.padovan@collabora.co.uk>
parent ab19516a
...@@ -433,11 +433,10 @@ struct l2cap_chan { ...@@ -433,11 +433,10 @@ struct l2cap_chan {
struct sock *sk; struct sock *sk;
struct l2cap_conn *conn; struct l2cap_conn *conn;
struct kref kref;
__u8 state; __u8 state;
atomic_t refcnt;
__le16 psm; __le16 psm;
__u16 dcid; __u16 dcid;
__u16 scid; __u16 scid;
......
...@@ -406,7 +406,7 @@ struct l2cap_chan *l2cap_chan_create(void) ...@@ -406,7 +406,7 @@ struct l2cap_chan *l2cap_chan_create(void)
chan->state = BT_OPEN; chan->state = BT_OPEN;
atomic_set(&chan->refcnt, 1); kref_init(&chan->kref);
/* This flag is cleared in l2cap_chan_ready() */ /* This flag is cleared in l2cap_chan_ready() */
set_bit(CONF_NOT_COMPLETE, &chan->conf_state); set_bit(CONF_NOT_COMPLETE, &chan->conf_state);
...@@ -416,8 +416,10 @@ struct l2cap_chan *l2cap_chan_create(void) ...@@ -416,8 +416,10 @@ struct l2cap_chan *l2cap_chan_create(void)
return chan; return chan;
} }
static void l2cap_chan_destroy(struct l2cap_chan *chan) static void l2cap_chan_destroy(struct kref *kref)
{ {
struct l2cap_chan *chan = container_of(kref, struct l2cap_chan, kref);
BT_DBG("chan %p", chan); BT_DBG("chan %p", chan);
write_lock(&chan_list_lock); write_lock(&chan_list_lock);
...@@ -429,17 +431,16 @@ static void l2cap_chan_destroy(struct l2cap_chan *chan) ...@@ -429,17 +431,16 @@ static void l2cap_chan_destroy(struct l2cap_chan *chan)
void l2cap_chan_hold(struct l2cap_chan *c) void l2cap_chan_hold(struct l2cap_chan *c)
{ {
BT_DBG("chan %p orig refcnt %d", c, atomic_read(&c->refcnt)); BT_DBG("chan %p orig refcnt %d", c, atomic_read(&c->kref.refcount));
atomic_inc(&c->refcnt); kref_get(&c->kref);
} }
void l2cap_chan_put(struct l2cap_chan *c) void l2cap_chan_put(struct l2cap_chan *c)
{ {
BT_DBG("chan %p orig refcnt %d", c, atomic_read(&c->refcnt)); BT_DBG("chan %p orig refcnt %d", c, atomic_read(&c->kref.refcount));
if (atomic_dec_and_test(&c->refcnt)) kref_put(&c->kref, l2cap_chan_destroy);
l2cap_chan_destroy(c);
} }
void l2cap_chan_set_defaults(struct l2cap_chan *chan) void l2cap_chan_set_defaults(struct l2cap_chan *chan)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment