Skip to content

Commit 8035ded

Browse files
VudentzGustavo F. Padovan
authored andcommitted
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>
1 parent 457f485 commit 8035ded

9 files changed

Lines changed: 51 additions & 120 deletions

File tree

‎net/bluetooth/bnep/core.c‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ static DECLARE_RWSEM(bnep_session_sem);
6565
static struct bnep_session *__bnep_get_session(u8 *dst)
6666
{
6767
struct bnep_session *s;
68-
struct list_head *p;
6968

7069
BT_DBG("");
7170

72-
list_for_each(p, &bnep_session_list) {
73-
s = list_entry(p, struct bnep_session, list);
71+
list_for_each_entry(s, &bnep_session_list, list)
7472
if (!compare_ether_addr(dst, s->eh.h_source))
7573
return s;
76-
}
74+
7775
return NULL;
7876
}
7977

@@ -667,17 +665,14 @@ static void __bnep_copy_ci(struct bnep_conninfo *ci, struct bnep_session *s)
667665

668666
int bnep_get_connlist(struct bnep_connlist_req *req)
669667
{
670-
struct list_head *p;
668+
struct bnep_session *s;
671669
int err = 0, n = 0;
672670

673671
down_read(&bnep_session_sem);
674672

675-
list_for_each(p, &bnep_session_list) {
676-
struct bnep_session *s;
673+
list_for_each_entry(s, &bnep_session_list, list) {
677674
struct bnep_conninfo ci;
678675

679-
s = list_entry(p, struct bnep_session, list);
680-
681676
__bnep_copy_ci(&ci, s);
682677

683678
if (copy_to_user(req->ci, &ci, sizeof(ci))) {

‎net/bluetooth/cmtp/core.c‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,13 @@ static LIST_HEAD(cmtp_session_list);
5353
static struct cmtp_session *__cmtp_get_session(bdaddr_t *bdaddr)
5454
{
5555
struct cmtp_session *session;
56-
struct list_head *p;
5756

5857
BT_DBG("");
5958

60-
list_for_each(p, &cmtp_session_list) {
61-
session = list_entry(p, struct cmtp_session, list);
59+
list_for_each_entry(session, &cmtp_session_list, list)
6260
if (!bacmp(bdaddr, &session->bdaddr))
6361
return session;
64-
}
62+
6563
return NULL;
6664
}
6765

@@ -431,19 +429,16 @@ int cmtp_del_connection(struct cmtp_conndel_req *req)
431429

432430
int cmtp_get_connlist(struct cmtp_connlist_req *req)
433431
{
434-
struct list_head *p;
432+
struct cmtp_session *session;
435433
int err = 0, n = 0;
436434

437435
BT_DBG("");
438436

439437
down_read(&cmtp_session_sem);
440438

441-
list_for_each(p, &cmtp_session_list) {
442-
struct cmtp_session *session;
439+
list_for_each_entry(session, &cmtp_session_list, list) {
443440
struct cmtp_conninfo ci;
444441

445-
session = list_entry(p, struct cmtp_session, list);
446-
447442
__cmtp_copy_session(session, &ci);
448443

449444
if (copy_to_user(req->ci, &ci, sizeof(ci))) {

‎net/bluetooth/hci_conn.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,13 @@ int hci_conn_del(struct hci_conn *conn)
453453
struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)
454454
{
455455
int use_src = bacmp(src, BDADDR_ANY);
456-
struct hci_dev *hdev = NULL;
457-
struct list_head *p;
456+
struct hci_dev *hdev = NULL, *d;
458457

459458
BT_DBG("%s -> %s", batostr(src), batostr(dst));
460459

461460
read_lock_bh(&hci_dev_list_lock);
462461

463-
list_for_each(p, &hci_dev_list) {
464-
struct hci_dev *d = list_entry(p, struct hci_dev, list);
465-
462+
list_for_each_entry(d, &hci_dev_list, list) {
466463
if (!test_bit(HCI_UP, &d->flags) || test_bit(HCI_RAW, &d->flags))
467464
continue;
468465

@@ -855,10 +852,10 @@ EXPORT_SYMBOL(hci_conn_put_device);
855852

856853
int hci_get_conn_list(void __user *arg)
857854
{
855+
register struct hci_conn *c;
858856
struct hci_conn_list_req req, *cl;
859857
struct hci_conn_info *ci;
860858
struct hci_dev *hdev;
861-
struct list_head *p;
862859
int n = 0, size, err;
863860

864861
if (copy_from_user(&req, arg, sizeof(req)))
@@ -882,10 +879,7 @@ int hci_get_conn_list(void __user *arg)
882879
ci = cl->conn_info;
883880

884881
hci_dev_lock_bh(hdev);
885-
list_for_each(p, &hdev->conn_hash.list) {
886-
register struct hci_conn *c;
887-
c = list_entry(p, struct hci_conn, list);
888-
882+
list_for_each_entry(c, &hdev->conn_hash.list, list) {
889883
bacpy(&(ci + n)->bdaddr, &c->dst);
890884
(ci + n)->handle = c->handle;
891885
(ci + n)->type = c->type;

‎net/bluetooth/hci_core.c‎

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,15 @@ static void hci_linkpol_req(struct hci_dev *hdev, unsigned long opt)
319319
* Device is held on return. */
320320
struct hci_dev *hci_dev_get(int index)
321321
{
322-
struct hci_dev *hdev = NULL;
323-
struct list_head *p;
322+
struct hci_dev *hdev = NULL, *d;
324323

325324
BT_DBG("%d", index);
326325

327326
if (index < 0)
328327
return NULL;
329328

330329
read_lock(&hci_dev_list_lock);
331-
list_for_each(p, &hci_dev_list) {
332-
struct hci_dev *d = list_entry(p, struct hci_dev, list);
330+
list_for_each_entry(d, &hci_dev_list, list) {
333331
if (d->id == index) {
334332
hdev = hci_dev_hold(d);
335333
break;
@@ -794,9 +792,9 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
794792

795793
int hci_get_dev_list(void __user *arg)
796794
{
795+
struct hci_dev *hdev;
797796
struct hci_dev_list_req *dl;
798797
struct hci_dev_req *dr;
799-
struct list_head *p;
800798
int n = 0, size, err;
801799
__u16 dev_num;
802800

@@ -815,11 +813,7 @@ int hci_get_dev_list(void __user *arg)
815813
dr = dl->dev_req;
816814

817815
read_lock_bh(&hci_dev_list_lock);
818-
list_for_each(p, &hci_dev_list) {
819-
struct hci_dev *hdev;
820-
821-
hdev = list_entry(p, struct hci_dev, list);
822-
816+
list_for_each_entry(hdev, &hci_dev_list, list) {
823817
hci_del_off_timer(hdev);
824818

825819
if (!test_bit(HCI_MGMT, &hdev->flags))
@@ -1008,16 +1002,11 @@ int hci_link_keys_clear(struct hci_dev *hdev)
10081002

10091003
struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)
10101004
{
1011-
struct list_head *p;
1012-
1013-
list_for_each(p, &hdev->link_keys) {
1014-
struct link_key *k;
1015-
1016-
k = list_entry(p, struct link_key, list);
1005+
struct link_key *k;
10171006

1007+
list_for_each_entry(k, &hdev->link_keys, list)
10181008
if (bacmp(bdaddr, &k->bdaddr) == 0)
10191009
return k;
1020-
}
10211010

10221011
return NULL;
10231012
}
@@ -1280,16 +1269,11 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
12801269
struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev,
12811270
bdaddr_t *bdaddr)
12821271
{
1283-
struct list_head *p;
1284-
1285-
list_for_each(p, &hdev->blacklist) {
1286-
struct bdaddr_list *b;
1287-
1288-
b = list_entry(p, struct bdaddr_list, list);
1272+
struct bdaddr_list *b;
12891273

1274+
list_for_each_entry(b, &hdev->blacklist, list)
12901275
if (bacmp(bdaddr, &b->bdaddr) == 0)
12911276
return b;
1292-
}
12931277

12941278
return NULL;
12951279
}
@@ -2031,16 +2015,12 @@ EXPORT_SYMBOL(hci_send_sco);
20312015
static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int *quote)
20322016
{
20332017
struct hci_conn_hash *h = &hdev->conn_hash;
2034-
struct hci_conn *conn = NULL;
2018+
struct hci_conn *conn = NULL, *c;
20352019
int num = 0, min = ~0;
2036-
struct list_head *p;
20372020

20382021
/* We don't have to lock device here. Connections are always
20392022
* added and removed with TX task disabled. */
2040-
list_for_each(p, &h->list) {
2041-
struct hci_conn *c;
2042-
c = list_entry(p, struct hci_conn, list);
2043-
2023+
list_for_each_entry(c, &h->list, list) {
20442024
if (c->type != type || skb_queue_empty(&c->data_q))
20452025
continue;
20462026

@@ -2089,14 +2069,12 @@ static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int
20892069
static inline void hci_link_tx_to(struct hci_dev *hdev, __u8 type)
20902070
{
20912071
struct hci_conn_hash *h = &hdev->conn_hash;
2092-
struct list_head *p;
2093-
struct hci_conn *c;
2072+
struct hci_conn *c;
20942073

20952074
BT_ERR("%s link tx timeout", hdev->name);
20962075

20972076
/* Kill stalled connections */
2098-
list_for_each(p, &h->list) {
2099-
c = list_entry(p, struct hci_conn, list);
2077+
list_for_each_entry(c, &h->list, list) {
21002078
if (c->type == type && c->sent) {
21012079
BT_ERR("%s killing stalled connection %s",
21022080
hdev->name, batostr(&c->dst));

‎net/bluetooth/hci_sysfs.c‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -435,17 +435,12 @@ static const struct file_operations inquiry_cache_fops = {
435435
static int blacklist_show(struct seq_file *f, void *p)
436436
{
437437
struct hci_dev *hdev = f->private;
438-
struct list_head *l;
438+
struct bdaddr_list *b;
439439

440440
hci_dev_lock_bh(hdev);
441441

442-
list_for_each(l, &hdev->blacklist) {
443-
struct bdaddr_list *b;
444-
445-
b = list_entry(l, struct bdaddr_list, list);
446-
442+
list_for_each_entry(b, &hdev->blacklist, list)
447443
seq_printf(f, "%s\n", batostr(&b->bdaddr));
448-
}
449444

450445
hci_dev_unlock_bh(hdev);
451446

@@ -484,17 +479,12 @@ static void print_bt_uuid(struct seq_file *f, u8 *uuid)
484479
static int uuids_show(struct seq_file *f, void *p)
485480
{
486481
struct hci_dev *hdev = f->private;
487-
struct list_head *l;
482+
struct bt_uuid *uuid;
488483

489484
hci_dev_lock_bh(hdev);
490485

491-
list_for_each(l, &hdev->uuids) {
492-
struct bt_uuid *uuid;
493-
494-
uuid = list_entry(l, struct bt_uuid, list);
495-
486+
list_for_each_entry(uuid, &hdev->uuids, list)
496487
print_bt_uuid(f, uuid->uuid);
497-
}
498488

499489
hci_dev_unlock_bh(hdev);
500490

‎net/bluetooth/hidp/core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static struct hidp_session *__hidp_get_session(bdaddr_t *bdaddr)
8888
if (!bacmp(bdaddr, &session->bdaddr))
8989
return session;
9090
}
91+
9192
return NULL;
9293
}
9394

‎net/bluetooth/mgmt.c‎

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ static int read_index_list(struct sock *sk)
123123
{
124124
struct mgmt_rp_read_index_list *rp;
125125
struct list_head *p;
126+
struct hci_dev *d;
126127
size_t rp_len;
127128
u16 count;
128129
int i, err;
@@ -146,9 +147,7 @@ static int read_index_list(struct sock *sk)
146147
put_unaligned_le16(count, &rp->num_controllers);
147148

148149
i = 0;
149-
list_for_each(p, &hci_dev_list) {
150-
struct hci_dev *d = list_entry(p, struct hci_dev, list);
151-
150+
list_for_each_entry(d, &hci_dev_list, list) {
152151
hci_del_off_timer(d);
153152

154153
set_bit(HCI_MGMT, &d->flags);
@@ -277,13 +276,9 @@ static void mgmt_pending_foreach(u16 opcode, int index,
277276

278277
static struct pending_cmd *mgmt_pending_find(u16 opcode, int index)
279278
{
280-
struct list_head *p;
281-
282-
list_for_each(p, &cmd_list) {
283-
struct pending_cmd *cmd;
284-
285-
cmd = list_entry(p, struct pending_cmd, list);
279+
struct pending_cmd *cmd;
286280

281+
list_for_each_entry(cmd, &cmd_list, list) {
287282
if (cmd->opcode != opcode)
288283
continue;
289284

@@ -592,7 +587,7 @@ static void create_eir(struct hci_dev *hdev, u8 *data)
592587
u16 eir_len = 0;
593588
u16 uuid16_list[HCI_MAX_EIR_LENGTH / sizeof(u16)];
594589
int i, truncated = 0;
595-
struct list_head *p;
590+
struct bt_uuid *uuid;
596591
size_t name_len;
597592

598593
name_len = strlen(hdev->dev_name);
@@ -617,8 +612,7 @@ static void create_eir(struct hci_dev *hdev, u8 *data)
617612
memset(uuid16_list, 0, sizeof(uuid16_list));
618613

619614
/* Group all UUID16 types */
620-
list_for_each(p, &hdev->uuids) {
621-
struct bt_uuid *uuid = list_entry(p, struct bt_uuid, list);
615+
list_for_each_entry(uuid, &hdev->uuids, list) {
622616
u16 uuid16;
623617

624618
uuid16 = get_uuid16(uuid->uuid);
@@ -1069,6 +1063,7 @@ static int get_connections(struct sock *sk, u16 index)
10691063
{
10701064
struct mgmt_rp_get_connections *rp;
10711065
struct hci_dev *hdev;
1066+
struct hci_conn *c;
10721067
struct list_head *p;
10731068
size_t rp_len;
10741069
u16 count;
@@ -1097,11 +1092,8 @@ static int get_connections(struct sock *sk, u16 index)
10971092
put_unaligned_le16(count, &rp->conn_count);
10981093

10991094
i = 0;
1100-
list_for_each(p, &hdev->conn_hash.list) {
1101-
struct hci_conn *c = list_entry(p, struct hci_conn, list);
1102-
1095+
list_for_each_entry(c, &hdev->conn_hash.list, list)
11031096
bacpy(&rp->conn[i++], &c->dst);
1104-
}
11051097

11061098
err = cmd_complete(sk, index, MGMT_OP_GET_CONNECTIONS, rp, rp_len);
11071099

@@ -1270,13 +1262,9 @@ static int set_io_capability(struct sock *sk, u16 index, unsigned char *data,
12701262
static inline struct pending_cmd *find_pairing(struct hci_conn *conn)
12711263
{
12721264
struct hci_dev *hdev = conn->hdev;
1273-
struct list_head *p;
1274-
1275-
list_for_each(p, &cmd_list) {
1276-
struct pending_cmd *cmd;
1277-
1278-
cmd = list_entry(p, struct pending_cmd, list);
1265+
struct pending_cmd *cmd;
12791266

1267+
list_for_each_entry(cmd, &cmd_list, list) {
12801268
if (cmd->opcode != MGMT_OP_PAIR_DEVICE)
12811269
continue;
12821270

0 commit comments

Comments
 (0)