aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>2012-10-05 09:56:55 -0400
committerGustavo Padovan <gustavo.padovan@collabora.co.uk>2012-10-07 18:19:04 -0400
commitfa4ebc66c432d0e0ec947cb754d4144c4a681f28 (patch)
treece31c236f663a249276883413f19dba534569738
parent85e34368dea6fc8a2d16464e01c85d3b7bd682bd (diff)
Bluetooth: AMP: Factor out amp_ctrl_add
Add ctrl_id parameter to amp_ctrl_add since we always set it after function ctrl is created. Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
-rw-r--r--include/net/bluetooth/amp.h2
-rw-r--r--net/bluetooth/a2mp.c8
-rw-r--r--net/bluetooth/amp.c7
3 files changed, 7 insertions, 10 deletions
diff --git a/include/net/bluetooth/amp.h b/include/net/bluetooth/amp.h
index b1e54903dd42..ae2c3e536473 100644
--- a/include/net/bluetooth/amp.h
+++ b/include/net/bluetooth/amp.h
@@ -26,7 +26,7 @@ struct amp_ctrl {
26 26
27int amp_ctrl_put(struct amp_ctrl *ctrl); 27int amp_ctrl_put(struct amp_ctrl *ctrl);
28void amp_ctrl_get(struct amp_ctrl *ctrl); 28void amp_ctrl_get(struct amp_ctrl *ctrl);
29struct amp_ctrl *amp_ctrl_add(struct amp_mgr *mgr); 29struct amp_ctrl *amp_ctrl_add(struct amp_mgr *mgr, u8 id);
30struct amp_ctrl *amp_ctrl_lookup(struct amp_mgr *mgr, u8 id); 30struct amp_ctrl *amp_ctrl_lookup(struct amp_mgr *mgr, u8 id);
31void amp_ctrl_list_flush(struct amp_mgr *mgr); 31void amp_ctrl_list_flush(struct amp_mgr *mgr);
32 32
diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
index d4946b591b71..88a4b583d218 100644
--- a/net/bluetooth/a2mp.c
+++ b/net/bluetooth/a2mp.c
@@ -316,12 +316,10 @@ static int a2mp_getinfo_rsp(struct amp_mgr *mgr, struct sk_buff *skb,
316 if (rsp->status) 316 if (rsp->status)
317 return -EINVAL; 317 return -EINVAL;
318 318
319 ctrl = amp_ctrl_add(mgr); 319 ctrl = amp_ctrl_add(mgr, rsp->id);
320 if (!ctrl) 320 if (!ctrl)
321 return -ENOMEM; 321 return -ENOMEM;
322 322
323 ctrl->id = rsp->id;
324
325 req.id = rsp->id; 323 req.id = rsp->id;
326 a2mp_send(mgr, A2MP_GETAMPASSOC_REQ, __next_ident(mgr), sizeof(req), 324 a2mp_send(mgr, A2MP_GETAMPASSOC_REQ, __next_ident(mgr), sizeof(req),
327 &req); 325 &req);
@@ -461,7 +459,7 @@ static int a2mp_createphyslink_req(struct amp_mgr *mgr, struct sk_buff *skb,
461 459
462 ctrl = amp_ctrl_lookup(mgr, rsp.remote_id); 460 ctrl = amp_ctrl_lookup(mgr, rsp.remote_id);
463 if (!ctrl) { 461 if (!ctrl) {
464 ctrl = amp_ctrl_add(mgr); 462 ctrl = amp_ctrl_add(mgr, rsp.remote_id);
465 if (ctrl) { 463 if (ctrl) {
466 amp_ctrl_get(ctrl); 464 amp_ctrl_get(ctrl);
467 } else { 465 } else {
@@ -474,8 +472,6 @@ static int a2mp_createphyslink_req(struct amp_mgr *mgr, struct sk_buff *skb,
474 size_t assoc_len = le16_to_cpu(hdr->len) - sizeof(*req); 472 size_t assoc_len = le16_to_cpu(hdr->len) - sizeof(*req);
475 u8 *assoc; 473 u8 *assoc;
476 474
477 ctrl->id = rsp.remote_id;
478
479 assoc = kzalloc(assoc_len, GFP_KERNEL); 475 assoc = kzalloc(assoc_len, GFP_KERNEL);
480 if (!assoc) { 476 if (!assoc) {
481 amp_ctrl_put(ctrl); 477 amp_ctrl_put(ctrl);
diff --git a/net/bluetooth/amp.c b/net/bluetooth/amp.c
index b6e1c3ac74f1..2fc5562a84b9 100644
--- a/net/bluetooth/amp.c
+++ b/net/bluetooth/amp.c
@@ -45,7 +45,7 @@ int amp_ctrl_put(struct amp_ctrl *ctrl)
45 return kref_put(&ctrl->kref, &amp_ctrl_destroy); 45 return kref_put(&ctrl->kref, &amp_ctrl_destroy);
46} 46}
47 47
48struct amp_ctrl *amp_ctrl_add(struct amp_mgr *mgr) 48struct amp_ctrl *amp_ctrl_add(struct amp_mgr *mgr, u8 id)
49{ 49{
50 struct amp_ctrl *ctrl; 50 struct amp_ctrl *ctrl;
51 51
@@ -53,12 +53,13 @@ struct amp_ctrl *amp_ctrl_add(struct amp_mgr *mgr)
53 if (!ctrl) 53 if (!ctrl)
54 return NULL; 54 return NULL;
55 55
56 kref_init(&ctrl->kref);
57 ctrl->id = id;
58
56 mutex_lock(&mgr->amp_ctrls_lock); 59 mutex_lock(&mgr->amp_ctrls_lock);
57 list_add(&ctrl->list, &mgr->amp_ctrls); 60 list_add(&ctrl->list, &mgr->amp_ctrls);
58 mutex_unlock(&mgr->amp_ctrls_lock); 61 mutex_unlock(&mgr->amp_ctrls_lock);
59 62
60 kref_init(&ctrl->kref);
61
62 BT_DBG("mgr %p ctrl %p", mgr, ctrl); 63 BT_DBG("mgr %p ctrl %p", mgr, ctrl);
63 64
64 return ctrl; 65 return ctrl;