aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2011-11-01 04:58:56 -0400
committerGustavo F. Padovan <padovan@profusion.mobi>2011-11-07 14:24:46 -0500
commit8035ded466049ca2fe8c04564a0fa00f222abe3f (patch)
treef589157028c85ebaa17be9f329405d1ccffa6304
parent457f48507deb0e8c8dd299c7d8dce7c2c0e291e8 (diff)
Bluetooth: replace list_for_each with list_for_each_entry whenever possible
When all items in the list have the same type there is no much of a point to use list_for_each except if you want to use the list pointer itself. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
-rw-r--r--net/bluetooth/bnep/core.c13
-rw-r--r--net/bluetooth/cmtp/core.c13
-rw-r--r--net/bluetooth/hci_conn.c14
-rw-r--r--net/bluetooth/hci_core.c46
-rw-r--r--net/bluetooth/hci_sysfs.c18
-rw-r--r--net/bluetooth/hidp/core.c1
-rw-r--r--net/bluetooth/mgmt.c32
-rw-r--r--net/bluetooth/rfcomm/core.c14
-rw-r--r--net/bluetooth/rfcomm/tty.c20
9 files changed, 51 insertions, 120 deletions
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index 91bcd3a961ec..a6cd856046ab 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -65,15 +65,13 @@ static DECLARE_RWSEM(bnep_session_sem);
65static struct bnep_session *__bnep_get_session(u8 *dst) 65static struct bnep_session *__bnep_get_session(u8 *dst)
66{ 66{
67 struct bnep_session *s; 67 struct bnep_session *s;
68 struct list_head *p;
69 68
70 BT_DBG(""); 69 BT_DBG("");
71 70
72 list_for_each(p, &bnep_session_list) { 71 list_for_each_entry(s, &bnep_session_list, list)
73 s = list_entry(p, struct bnep_session, list);
74 if (!compare_ether_addr(dst, s->eh.h_source)) 72 if (!compare_ether_addr(dst, s->eh.h_source))
75 return s; 73 return s;
76 } 74
77 return NULL; 75 return NULL;
78} 76}
79 77
@@ -667,17 +665,14 @@ static void __bnep_copy_ci(struct bnep_conninfo *ci, struct bnep_session *s)
667 665
668int bnep_get_connlist(struct bnep_connlist_req *req) 666int bnep_get_connlist(struct bnep_connlist_req *req)
669{ 667{
670 struct list_head *p; 668 struct bnep_session *s;
671 int err = 0, n = 0; 669 int err = 0, n = 0;
672 670
673 down_read(&bnep_session_sem); 671 down_read(&bnep_session_sem);
674 672
675 list_for_each(p, &bnep_session_list) { 673 list_for_each_entry(s, &bnep_session_list, list) {
676 struct bnep_session *s;
677 struct bnep_conninfo ci; 674 struct bnep_conninfo ci;
678 675
679 s = list_entry(p, struct bnep_session, list);
680
681 __bnep_copy_ci(&ci, s); 676 __bnep_copy_ci(&ci, s);
682 677
683 if (copy_to_user(req->ci, &ci, sizeof(ci))) { 678 if (copy_to_user(req->ci, &ci, sizeof(ci))) {
diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
index 7d00ddf9e9dc..9e8940b24bba 100644
--- a/net/bluetooth/cmtp/core.c
+++ b/net/bluetooth/cmtp/core.c
@@ -53,15 +53,13 @@ static LIST_HEAD(cmtp_session_list);
53static struct cmtp_session *__cmtp_get_session(bdaddr_t *bdaddr) 53static struct cmtp_session *__cmtp_get_session(bdaddr_t *bdaddr)
54{ 54{
55 struct cmtp_session *session; 55 struct cmtp_session *session;
56 struct list_head *p;
57 56
58 BT_DBG(""); 57 BT_DBG("");
59 58
60 list_for_each(p, &cmtp_session_list) { 59 list_for_each_entry(session, &cmtp_session_list, list)
61 session = list_entry(p, struct cmtp_session, list);
62 if (!bacmp(bdaddr, &session->bdaddr)) 60 if (!bacmp(bdaddr, &session->bdaddr))
63 return session; 61 return session;
64 } 62
65 return NULL; 63 return NULL;
66} 64}
67 65
@@ -431,19 +429,16 @@ int cmtp_del_connection(struct cmtp_conndel_req *req)
431 429
432int cmtp_get_connlist(struct cmtp_connlist_req *req) 430int cmtp_get_connlist(struct cmtp_connlist_req *req)
433{ 431{
434 struct list_head *p; 432 struct cmtp_session *session;
435 int err = 0, n = 0; 433 int err = 0, n = 0;
436 434
437 BT_DBG(""); 435 BT_DBG("");
438 436
439 down_read(&cmtp_session_sem); 437 down_read(&cmtp_session_sem);
440 438
441 list_for_each(p, &cmtp_session_list) { 439 list_for_each_entry(session, &cmtp_session_list, list) {
442 struct cmtp_session *session;
443 struct cmtp_conninfo ci; 440 struct cmtp_conninfo ci;
444 441
445 session = list_entry(p, struct cmtp_session, list);
446
447 __cmtp_copy_session(session, &ci); 442 __cmtp_copy_session(session, &ci);
448 443
449 if (copy_to_user(req->ci, &ci, sizeof(ci))) { 444 if (copy_to_user(req->ci, &ci, sizeof(ci))) {
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index c1c597e3e198..6e98ff3da2a4 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -453,16 +453,13 @@ int hci_conn_del(struct hci_conn *conn)
453struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src) 453struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)
454{ 454{
455 int use_src = bacmp(src, BDADDR_ANY); 455 int use_src = bacmp(src, BDADDR_ANY);
456 struct hci_dev *hdev = NULL; 456 struct hci_dev *hdev = NULL, *d;
457 struct list_head *p;
458 457
459 BT_DBG("%s -> %s", batostr(src), batostr(dst)); 458 BT_DBG("%s -> %s", batostr(src), batostr(dst));
460 459
461 read_lock_bh(&hci_dev_list_lock); 460 read_lock_bh(&hci_dev_list_lock);
462 461
463 list_for_each(p, &hci_dev_list) { 462 list_for_each_entry(d, &hci_dev_list, list) {
464 struct hci_dev *d = list_entry(p, struct hci_dev, list);
465
466 if (!test_bit(HCI_UP, &d->flags) || test_bit(HCI_RAW, &d->flags)) 463 if (!test_bit(HCI_UP, &d->flags) || test_bit(HCI_RAW, &d->flags))
467 continue; 464 continue;
468 465
@@ -855,10 +852,10 @@ EXPORT_SYMBOL(hci_conn_put_device);
855 852
856int hci_get_conn_list(void __user *arg) 853int hci_get_conn_list(void __user *arg)
857{ 854{
855 register struct hci_conn *c;
858 struct hci_conn_list_req req, *cl; 856 struct hci_conn_list_req req, *cl;
859 struct hci_conn_info *ci; 857 struct hci_conn_info *ci;
860 struct hci_dev *hdev; 858 struct hci_dev *hdev;
861 struct list_head *p;
862 int n = 0, size, err; 859 int n = 0, size, err;
863 860
864 if (copy_from_user(&req, arg, sizeof(req))) 861 if (copy_from_user(&req, arg, sizeof(req)))
@@ -882,10 +879,7 @@ int hci_get_conn_list(void __user *arg)
882 ci = cl->conn_info; 879 ci = cl->conn_info;
883 880
884 hci_dev_lock_bh(hdev); 881 hci_dev_lock_bh(hdev);
885 list_for_each(p, &hdev->conn_hash.list) { 882 list_for_each_entry(c, &hdev->conn_hash.list, list) {
886 register struct hci_conn *c;
887 c = list_entry(p, struct hci_conn, list);
888
889 bacpy(&(ci + n)->bdaddr, &c->dst); 883 bacpy(&(ci + n)->bdaddr, &c->dst);
890 (ci + n)->handle = c->handle; 884 (ci + n)->handle = c->handle;
891 (ci + n)->type = c->type; 885 (ci + n)->type = c->type;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 557ff90331b9..f04f2eca2028 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -319,8 +319,7 @@ static void hci_linkpol_req(struct hci_dev *hdev, unsigned long opt)
319 * Device is held on return. */ 319 * Device is held on return. */
320struct hci_dev *hci_dev_get(int index) 320struct hci_dev *hci_dev_get(int index)
321{ 321{
322 struct hci_dev *hdev = NULL; 322 struct hci_dev *hdev = NULL, *d;
323 struct list_head *p;
324 323
325 BT_DBG("%d", index); 324 BT_DBG("%d", index);
326 325
@@ -328,8 +327,7 @@ struct hci_dev *hci_dev_get(int index)
328 return NULL; 327 return NULL;
329 328
330 read_lock(&hci_dev_list_lock); 329 read_lock(&hci_dev_list_lock);
331 list_for_each(p, &hci_dev_list) { 330 list_for_each_entry(d, &hci_dev_list, list) {
332 struct hci_dev *d = list_entry(p, struct hci_dev, list);
333 if (d->id == index) { 331 if (d->id == index) {
334 hdev = hci_dev_hold(d); 332 hdev = hci_dev_hold(d);
335 break; 333 break;
@@ -794,9 +792,9 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
794 792
795int hci_get_dev_list(void __user *arg) 793int hci_get_dev_list(void __user *arg)
796{ 794{
795 struct hci_dev *hdev;
797 struct hci_dev_list_req *dl; 796 struct hci_dev_list_req *dl;
798 struct hci_dev_req *dr; 797 struct hci_dev_req *dr;
799 struct list_head *p;
800 int n = 0, size, err; 798 int n = 0, size, err;
801 __u16 dev_num; 799 __u16 dev_num;
802 800
@@ -815,11 +813,7 @@ int hci_get_dev_list(void __user *arg)
815 dr = dl->dev_req; 813 dr = dl->dev_req;
816 814
817 read_lock_bh(&hci_dev_list_lock); 815 read_lock_bh(&hci_dev_list_lock);
818 list_for_each(p, &hci_dev_list) { 816 list_for_each_entry(hdev, &hci_dev_list, list) {
819 struct hci_dev *hdev;
820
821 hdev = list_entry(p, struct hci_dev, list);
822
823 hci_del_off_timer(hdev); 817 hci_del_off_timer(hdev);
824 818
825 if (!test_bit(HCI_MGMT, &hdev->flags)) 819 if (!test_bit(HCI_MGMT, &hdev->flags))
@@ -1008,16 +1002,11 @@ int hci_link_keys_clear(struct hci_dev *hdev)
1008 1002
1009struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) 1003struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)
1010{ 1004{
1011 struct list_head *p; 1005 struct link_key *k;
1012
1013 list_for_each(p, &hdev->link_keys) {
1014 struct link_key *k;
1015
1016 k = list_entry(p, struct link_key, list);
1017 1006
1007 list_for_each_entry(k, &hdev->link_keys, list)
1018 if (bacmp(bdaddr, &k->bdaddr) == 0) 1008 if (bacmp(bdaddr, &k->bdaddr) == 0)
1019 return k; 1009 return k;
1020 }
1021 1010
1022 return NULL; 1011 return NULL;
1023} 1012}
@@ -1280,16 +1269,11 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
1280struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, 1269struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev,
1281 bdaddr_t *bdaddr) 1270 bdaddr_t *bdaddr)
1282{ 1271{
1283 struct list_head *p; 1272 struct bdaddr_list *b;
1284
1285 list_for_each(p, &hdev->blacklist) {
1286 struct bdaddr_list *b;
1287
1288 b = list_entry(p, struct bdaddr_list, list);
1289 1273
1274 list_for_each_entry(b, &hdev->blacklist, list)
1290 if (bacmp(bdaddr, &b->bdaddr) == 0) 1275 if (bacmp(bdaddr, &b->bdaddr) == 0)
1291 return b; 1276 return b;
1292 }
1293 1277
1294 return NULL; 1278 return NULL;
1295} 1279}
@@ -2031,16 +2015,12 @@ EXPORT_SYMBOL(hci_send_sco);
2031static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int *quote) 2015static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int *quote)
2032{ 2016{
2033 struct hci_conn_hash *h = &hdev->conn_hash; 2017 struct hci_conn_hash *h = &hdev->conn_hash;
2034 struct hci_conn *conn = NULL; 2018 struct hci_conn *conn = NULL, *c;
2035 int num = 0, min = ~0; 2019 int num = 0, min = ~0;
2036 struct list_head *p;
2037 2020
2038 /* We don't have to lock device here. Connections are always 2021 /* We don't have to lock device here. Connections are always
2039 * added and removed with TX task disabled. */ 2022 * added and removed with TX task disabled. */
2040 list_for_each(p, &h->list) { 2023 list_for_each_entry(c, &h->list, list) {
2041 struct hci_conn *c;
2042 c = list_entry(p, struct hci_conn, list);
2043
2044 if (c->type != type || skb_queue_empty(&c->data_q)) 2024 if (c->type != type || skb_queue_empty(&c->data_q))
2045 continue; 2025 continue;
2046 2026
@@ -2089,14 +2069,12 @@ static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int
2089static inline void hci_link_tx_to(struct hci_dev *hdev, __u8 type) 2069static inline void hci_link_tx_to(struct hci_dev *hdev, __u8 type)
2090{ 2070{
2091 struct hci_conn_hash *h = &hdev->conn_hash; 2071 struct hci_conn_hash *h = &hdev->conn_hash;
2092 struct list_head *p; 2072 struct hci_conn *c;
2093 struct hci_conn *c;
2094 2073
2095 BT_ERR("%s link tx timeout", hdev->name); 2074 BT_ERR("%s link tx timeout", hdev->name);
2096 2075
2097 /* Kill stalled connections */ 2076 /* Kill stalled connections */
2098 list_for_each(p, &h->list) { 2077 list_for_each_entry(c, &h->list, list) {
2099 c = list_entry(p, struct hci_conn, list);
2100 if (c->type == type && c->sent) { 2078 if (c->type == type && c->sent) {
2101 BT_ERR("%s killing stalled connection %s", 2079 BT_ERR("%s killing stalled connection %s",
2102 hdev->name, batostr(&c->dst)); 2080 hdev->name, batostr(&c->dst));
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 1f9f8769e130..f8e6aa386cef 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -435,17 +435,12 @@ static const struct file_operations inquiry_cache_fops = {
435static int blacklist_show(struct seq_file *f, void *p) 435static int blacklist_show(struct seq_file *f, void *p)
436{ 436{
437 struct hci_dev *hdev = f->private; 437 struct hci_dev *hdev = f->private;
438 struct list_head *l; 438 struct bdaddr_list *b;
439 439
440 hci_dev_lock_bh(hdev); 440 hci_dev_lock_bh(hdev);
441 441
442 list_for_each(l, &hdev->blacklist) { 442 list_for_each_entry(b, &hdev->blacklist, list)
443 struct bdaddr_list *b;
444
445 b = list_entry(l, struct bdaddr_list, list);
446
447 seq_printf(f, "%s\n", batostr(&b->bdaddr)); 443 seq_printf(f, "%s\n", batostr(&b->bdaddr));
448 }
449 444
450 hci_dev_unlock_bh(hdev); 445 hci_dev_unlock_bh(hdev);
451 446
@@ -484,17 +479,12 @@ static void print_bt_uuid(struct seq_file *f, u8 *uuid)
484static int uuids_show(struct seq_file *f, void *p) 479static int uuids_show(struct seq_file *f, void *p)
485{ 480{
486 struct hci_dev *hdev = f->private; 481 struct hci_dev *hdev = f->private;
487 struct list_head *l; 482 struct bt_uuid *uuid;
488 483
489 hci_dev_lock_bh(hdev); 484 hci_dev_lock_bh(hdev);
490 485
491 list_for_each(l, &hdev->uuids) { 486 list_for_each_entry(uuid, &hdev->uuids, list)
492 struct bt_uuid *uuid;
493
494 uuid = list_entry(l, struct bt_uuid, list);
495
496 print_bt_uuid(f, uuid->uuid); 487 print_bt_uuid(f, uuid->uuid);
497 }
498 488
499 hci_dev_unlock_bh(hdev); 489 hci_dev_unlock_bh(hdev);
500 490
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 217ef4761560..2efd6cc58b66 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -88,6 +88,7 @@ static struct hidp_session *__hidp_get_session(bdaddr_t *bdaddr)
88 if (!bacmp(bdaddr, &session->bdaddr)) 88 if (!bacmp(bdaddr, &session->bdaddr))
89 return session; 89 return session;
90 } 90 }
91
91 return NULL; 92 return NULL;
92} 93}
93 94
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 9ffd7c3dbb3e..7809aa979358 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -123,6 +123,7 @@ static int read_index_list(struct sock *sk)
123{ 123{
124 struct mgmt_rp_read_index_list *rp; 124 struct mgmt_rp_read_index_list *rp;
125 struct list_head *p; 125 struct list_head *p;
126 struct hci_dev *d;
126 size_t rp_len; 127 size_t rp_len;
127 u16 count; 128 u16 count;
128 int i, err; 129 int i, err;
@@ -146,9 +147,7 @@ static int read_index_list(struct sock *sk)
146 put_unaligned_le16(count, &rp->num_controllers); 147 put_unaligned_le16(count, &rp->num_controllers);
147 148
148 i = 0; 149 i = 0;
149 list_for_each(p, &hci_dev_list) { 150 list_for_each_entry(d, &hci_dev_list, list) {
150 struct hci_dev *d = list_entry(p, struct hci_dev, list);
151
152 hci_del_off_timer(d); 151 hci_del_off_timer(d);
153 152
154 set_bit(HCI_MGMT, &d->flags); 153 set_bit(HCI_MGMT, &d->flags);
@@ -277,13 +276,9 @@ static void mgmt_pending_foreach(u16 opcode, int index,
277 276
278static struct pending_cmd *mgmt_pending_find(u16 opcode, int index) 277static struct pending_cmd *mgmt_pending_find(u16 opcode, int index)
279{ 278{
280 struct list_head *p; 279 struct pending_cmd *cmd;
281
282 list_for_each(p, &cmd_list) {
283 struct pending_cmd *cmd;
284
285 cmd = list_entry(p, struct pending_cmd, list);
286 280
281 list_for_each_entry(cmd, &cmd_list, list) {
287 if (cmd->opcode != opcode) 282 if (cmd->opcode != opcode)
288 continue; 283 continue;
289 284
@@ -592,7 +587,7 @@ static void create_eir(struct hci_dev *hdev, u8 *data)
592 u16 eir_len = 0; 587 u16 eir_len = 0;
593 u16 uuid16_list[HCI_MAX_EIR_LENGTH / sizeof(u16)]; 588 u16 uuid16_list[HCI_MAX_EIR_LENGTH / sizeof(u16)];
594 int i, truncated = 0; 589 int i, truncated = 0;
595 struct list_head *p; 590 struct bt_uuid *uuid;
596 size_t name_len; 591 size_t name_len;
597 592
598 name_len = strlen(hdev->dev_name); 593 name_len = strlen(hdev->dev_name);
@@ -617,8 +612,7 @@ static void create_eir(struct hci_dev *hdev, u8 *data)
617 memset(uuid16_list, 0, sizeof(uuid16_list)); 612 memset(uuid16_list, 0, sizeof(uuid16_list));
618 613
619 /* Group all UUID16 types */ 614 /* Group all UUID16 types */
620 list_for_each(p, &hdev->uuids) { 615 list_for_each_entry(uuid, &hdev->uuids, list) {
621 struct bt_uuid *uuid = list_entry(p, struct bt_uuid, list);
622 u16 uuid16; 616 u16 uuid16;
623 617
624 uuid16 = get_uuid16(uuid->uuid); 618 uuid16 = get_uuid16(uuid->uuid);
@@ -1069,6 +1063,7 @@ static int get_connections(struct sock *sk, u16 index)
1069{ 1063{
1070 struct mgmt_rp_get_connections *rp; 1064 struct mgmt_rp_get_connections *rp;
1071 struct hci_dev *hdev; 1065 struct hci_dev *hdev;
1066 struct hci_conn *c;
1072 struct list_head *p; 1067 struct list_head *p;
1073 size_t rp_len; 1068 size_t rp_len;
1074 u16 count; 1069 u16 count;
@@ -1097,11 +1092,8 @@ static int get_connections(struct sock *sk, u16 index)
1097 put_unaligned_le16(count, &rp->conn_count); 1092 put_unaligned_le16(count, &rp->conn_count);
1098 1093
1099 i = 0; 1094 i = 0;
1100 list_for_each(p, &hdev->conn_hash.list) { 1095 list_for_each_entry(c, &hdev->conn_hash.list, list)
1101 struct hci_conn *c = list_entry(p, struct hci_conn, list);
1102
1103 bacpy(&rp->conn[i++], &c->dst); 1096 bacpy(&rp->conn[i++], &c->dst);
1104 }
1105 1097
1106 err = cmd_complete(sk, index, MGMT_OP_GET_CONNECTIONS, rp, rp_len); 1098 err = cmd_complete(sk, index, MGMT_OP_GET_CONNECTIONS, rp, rp_len);
1107 1099
@@ -1270,13 +1262,9 @@ static int set_io_capability(struct sock *sk, u16 index, unsigned char *data,
1270static inline struct pending_cmd *find_pairing(struct hci_conn *conn) 1262static inline struct pending_cmd *find_pairing(struct hci_conn *conn)
1271{ 1263{
1272 struct hci_dev *hdev = conn->hdev; 1264 struct hci_dev *hdev = conn->hdev;
1273 struct list_head *p; 1265 struct pending_cmd *cmd;
1274
1275 list_for_each(p, &cmd_list) {
1276 struct pending_cmd *cmd;
1277
1278 cmd = list_entry(p, struct pending_cmd, list);
1279 1266
1267 list_for_each_entry(cmd, &cmd_list, list) {
1280 if (cmd->opcode != MGMT_OP_PAIR_DEVICE) 1268 if (cmd->opcode != MGMT_OP_PAIR_DEVICE)
1281 continue; 1269 continue;
1282 1270
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index 38b618c96de6..3d35eba6d0cb 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -377,13 +377,11 @@ static void rfcomm_dlc_unlink(struct rfcomm_dlc *d)
377static struct rfcomm_dlc *rfcomm_dlc_get(struct rfcomm_session *s, u8 dlci) 377static struct rfcomm_dlc *rfcomm_dlc_get(struct rfcomm_session *s, u8 dlci)
378{ 378{
379 struct rfcomm_dlc *d; 379 struct rfcomm_dlc *d;
380 struct list_head *p;
381 380
382 list_for_each(p, &s->dlcs) { 381 list_for_each_entry(d, &s->dlcs, list)
383 d = list_entry(p, struct rfcomm_dlc, list);
384 if (d->dlci == dlci) 382 if (d->dlci == dlci)
385 return d; 383 return d;
386 } 384
387 return NULL; 385 return NULL;
388} 386}
389 387
@@ -2115,15 +2113,13 @@ static struct hci_cb rfcomm_cb = {
2115static int rfcomm_dlc_debugfs_show(struct seq_file *f, void *x) 2113static int rfcomm_dlc_debugfs_show(struct seq_file *f, void *x)
2116{ 2114{
2117 struct rfcomm_session *s; 2115 struct rfcomm_session *s;
2118 struct list_head *pp, *p;
2119 2116
2120 rfcomm_lock(); 2117 rfcomm_lock();
2121 2118
2122 list_for_each(p, &session_list) { 2119 list_for_each_entry(s, &session_list, list) {
2123 s = list_entry(p, struct rfcomm_session, list); 2120 struct rfcomm_dlc *d;
2124 list_for_each(pp, &s->dlcs) { 2121 list_for_each_entry(d, &s->dlcs, list) {
2125 struct sock *sk = s->sock->sk; 2122 struct sock *sk = s->sock->sk;
2126 struct rfcomm_dlc *d = list_entry(pp, struct rfcomm_dlc, list);
2127 2123
2128 seq_printf(f, "%s %s %ld %d %d %d %d\n", 2124 seq_printf(f, "%s %s %ld %d %d %d %d\n",
2129 batostr(&bt_sk(sk)->src), 2125 batostr(&bt_sk(sk)->src),
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 947f1b3afd15..fa8f4de53b99 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -134,13 +134,10 @@ static inline void rfcomm_dev_put(struct rfcomm_dev *dev)
134static struct rfcomm_dev *__rfcomm_dev_get(int id) 134static struct rfcomm_dev *__rfcomm_dev_get(int id)
135{ 135{
136 struct rfcomm_dev *dev; 136 struct rfcomm_dev *dev;
137 struct list_head *p;
138 137
139 list_for_each(p, &rfcomm_dev_list) { 138 list_for_each_entry(dev, &rfcomm_dev_list, list)
140 dev = list_entry(p, struct rfcomm_dev, list);
141 if (dev->id == id) 139 if (dev->id == id)
142 return dev; 140 return dev;
143 }
144 141
145 return NULL; 142 return NULL;
146} 143}
@@ -198,7 +195,7 @@ static DEVICE_ATTR(channel, S_IRUGO, show_channel, NULL);
198 195
199static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc) 196static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
200{ 197{
201 struct rfcomm_dev *dev; 198 struct rfcomm_dev *dev, *entry;
202 struct list_head *head = &rfcomm_dev_list, *p; 199 struct list_head *head = &rfcomm_dev_list, *p;
203 int err = 0; 200 int err = 0;
204 201
@@ -213,8 +210,8 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
213 if (req->dev_id < 0) { 210 if (req->dev_id < 0) {
214 dev->id = 0; 211 dev->id = 0;
215 212
216 list_for_each(p, &rfcomm_dev_list) { 213 list_for_each_entry(entry, &rfcomm_dev_list, list) {
217 if (list_entry(p, struct rfcomm_dev, list)->id != dev->id) 214 if (entry->id != dev->id)
218 break; 215 break;
219 216
220 dev->id++; 217 dev->id++;
@@ -223,9 +220,7 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
223 } else { 220 } else {
224 dev->id = req->dev_id; 221 dev->id = req->dev_id;
225 222
226 list_for_each(p, &rfcomm_dev_list) { 223 list_for_each_entry(entry, &rfcomm_dev_list, list) {
227 struct rfcomm_dev *entry = list_entry(p, struct rfcomm_dev, list);
228
229 if (entry->id == dev->id) { 224 if (entry->id == dev->id) {
230 err = -EADDRINUSE; 225 err = -EADDRINUSE;
231 goto out; 226 goto out;
@@ -456,9 +451,9 @@ static int rfcomm_release_dev(void __user *arg)
456 451
457static int rfcomm_get_dev_list(void __user *arg) 452static int rfcomm_get_dev_list(void __user *arg)
458{ 453{
454 struct rfcomm_dev *dev;
459 struct rfcomm_dev_list_req *dl; 455 struct rfcomm_dev_list_req *dl;
460 struct rfcomm_dev_info *di; 456 struct rfcomm_dev_info *di;
461 struct list_head *p;
462 int n = 0, size, err; 457 int n = 0, size, err;
463 u16 dev_num; 458 u16 dev_num;
464 459
@@ -480,8 +475,7 @@ static int rfcomm_get_dev_list(void __user *arg)
480 475
481 read_lock_bh(&rfcomm_dev_lock); 476 read_lock_bh(&rfcomm_dev_lock);
482 477
483 list_for_each(p, &rfcomm_dev_list) { 478 list_for_each_entry(dev, &rfcomm_dev_list, list) {
484 struct rfcomm_dev *dev = list_entry(p, struct rfcomm_dev, list);
485 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) 479 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags))
486 continue; 480 continue;
487 (di + n)->id = dev->id; 481 (di + n)->id = dev->id;