Bluetooth: use list_for_each_entry*
authorGeliang Tang <geliangtang@163.com>
Fri, 18 Dec 2015 15:33:25 +0000 (23:33 +0800)
committerMarcel Holtmann <marcel@holtmann.org>
Sun, 20 Dec 2015 07:11:10 +0000 (08:11 +0100)
Use list_for_each_entry*() instead of list_for_each*() to simplify
the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/af_bluetooth.c
net/bluetooth/cmtp/capi.c
net/bluetooth/hci_core.c
net/bluetooth/rfcomm/core.c

index cb4e8d4f7c25b9488f89a1259baa730f4efabaf6..955eda93e66f32b055277a93226ca66b0075fbaf 100644 (file)
@@ -174,13 +174,13 @@ EXPORT_SYMBOL(bt_accept_unlink);
 
 struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock)
 {
-       struct list_head *p, *n;
+       struct bt_sock *s, *n;
        struct sock *sk;
 
        BT_DBG("parent %p", parent);
 
-       list_for_each_safe(p, n, &bt_sk(parent)->accept_q) {
-               sk = (struct sock *) list_entry(p, struct bt_sock, accept_q);
+       list_for_each_entry_safe(s, n, &bt_sk(parent)->accept_q, accept_q) {
+               sk = (struct sock *)s;
 
                lock_sock(sk);
 
@@ -388,11 +388,11 @@ EXPORT_SYMBOL(bt_sock_stream_recvmsg);
 
 static inline unsigned int bt_accept_poll(struct sock *parent)
 {
-       struct list_head *p, *n;
+       struct bt_sock *s, *n;
        struct sock *sk;
 
-       list_for_each_safe(p, n, &bt_sk(parent)->accept_q) {
-               sk = (struct sock *) list_entry(p, struct bt_sock, accept_q);
+       list_for_each_entry_safe(s, n, &bt_sk(parent)->accept_q, accept_q) {
+               sk = (struct sock *)s;
                if (sk->sk_state == BT_CONNECTED ||
                    (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags) &&
                     sk->sk_state == BT_CONNECT2))
index 9a50338772f3af9875c83f628e110ffa6458781a..46ac686c8911e70d46341d046c56ff896d554ccf 100644 (file)
@@ -100,10 +100,8 @@ static void cmtp_application_del(struct cmtp_session *session, struct cmtp_appli
 static struct cmtp_application *cmtp_application_get(struct cmtp_session *session, int pattern, __u16 value)
 {
        struct cmtp_application *app;
-       struct list_head *p;
 
-       list_for_each(p, &session->applications) {
-               app = list_entry(p, struct cmtp_application, list);
+       list_for_each_entry(app, &session->applications, list) {
                switch (pattern) {
                case CMTP_MSGNUM:
                        if (app->msgnum == value)
@@ -511,14 +509,12 @@ static int cmtp_proc_show(struct seq_file *m, void *v)
        struct capi_ctr *ctrl = m->private;
        struct cmtp_session *session = ctrl->driverdata;
        struct cmtp_application *app;
-       struct list_head *p;
 
        seq_printf(m, "%s\n\n", cmtp_procinfo(ctrl));
        seq_printf(m, "addr %s\n", session->name);
        seq_printf(m, "ctrl %d\n", session->num);
 
-       list_for_each(p, &session->applications) {
-               app = list_entry(p, struct cmtp_application, list);
+       list_for_each_entry(app, &session->applications, list) {
                seq_printf(m, "appl %d -> %d\n", app->appl, app->mapping);
        }
 
index 9fb443a5473a23981de4bbd99819590fda7304ce..47bcef7547967ce544ff0cf5ea7dabecdd080d90 100644 (file)
@@ -2713,12 +2713,10 @@ struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *bdaddr_list,
 
 void hci_bdaddr_list_clear(struct list_head *bdaddr_list)
 {
-       struct list_head *p, *n;
+       struct bdaddr_list *b, *n;
 
-       list_for_each_safe(p, n, bdaddr_list) {
-               struct bdaddr_list *b = list_entry(p, struct bdaddr_list, list);
-
-               list_del(p);
+       list_for_each_entry_safe(b, n, bdaddr_list, list) {
+               list_del(&b->list);
                kfree(b);
        }
 }
index 29709fbfd1f509326fd3fdcfdd6bfbd51edaf82f..f7eb02f09b54055c9b8c17b6fdcf53ec5041aa11 100644 (file)
@@ -692,11 +692,9 @@ static struct rfcomm_session *rfcomm_session_del(struct rfcomm_session *s)
 
 static struct rfcomm_session *rfcomm_session_get(bdaddr_t *src, bdaddr_t *dst)
 {
-       struct rfcomm_session *s;
-       struct list_head *p, *n;
+       struct rfcomm_session *s, *n;
        struct l2cap_chan *chan;
-       list_for_each_safe(p, n, &session_list) {
-               s = list_entry(p, struct rfcomm_session, list);
+       list_for_each_entry_safe(s, n, &session_list, list) {
                chan = l2cap_pi(s->sock->sk)->chan;
 
                if ((!bacmp(src, BDADDR_ANY) || !bacmp(&chan->src, src)) &&
@@ -709,16 +707,14 @@ static struct rfcomm_session *rfcomm_session_get(bdaddr_t *src, bdaddr_t *dst)
 static struct rfcomm_session *rfcomm_session_close(struct rfcomm_session *s,
                                                   int err)
 {
-       struct rfcomm_dlc *d;
-       struct list_head *p, *n;
+       struct rfcomm_dlc *d, *n;
 
        s->state = BT_CLOSED;
 
        BT_DBG("session %p state %ld err %d", s, s->state, err);
 
        /* Close all dlcs */
-       list_for_each_safe(p, n, &s->dlcs) {
-               d = list_entry(p, struct rfcomm_dlc, list);
+       list_for_each_entry_safe(d, n, &s->dlcs, list) {
                d->state = BT_CLOSED;
                __rfcomm_dlc_close(d, err);
        }
@@ -1771,13 +1767,11 @@ static struct rfcomm_session *rfcomm_recv_frame(struct rfcomm_session *s,
 
 static void rfcomm_process_connect(struct rfcomm_session *s)
 {
-       struct rfcomm_dlc *d;
-       struct list_head *p, *n;
+       struct rfcomm_dlc *d, *n;
 
        BT_DBG("session %p state %ld", s, s->state);
 
-       list_for_each_safe(p, n, &s->dlcs) {
-               d = list_entry(p, struct rfcomm_dlc, list);
+       list_for_each_entry_safe(d, n, &s->dlcs, list) {
                if (d->state == BT_CONFIG) {
                        d->mtu = s->mtu;
                        if (rfcomm_check_security(d)) {
@@ -1843,14 +1837,11 @@ static int rfcomm_process_tx(struct rfcomm_dlc *d)
 
 static void rfcomm_process_dlcs(struct rfcomm_session *s)
 {
-       struct rfcomm_dlc *d;
-       struct list_head *p, *n;
+       struct rfcomm_dlc *d, *n;
 
        BT_DBG("session %p state %ld", s, s->state);
 
-       list_for_each_safe(p, n, &s->dlcs) {
-               d = list_entry(p, struct rfcomm_dlc, list);
-
+       list_for_each_entry_safe(d, n, &s->dlcs, list) {
                if (test_bit(RFCOMM_TIMED_OUT, &d->flags)) {
                        __rfcomm_dlc_close(d, ETIMEDOUT);
                        continue;
@@ -1985,14 +1976,11 @@ static struct rfcomm_session *rfcomm_check_connection(struct rfcomm_session *s)
 
 static void rfcomm_process_sessions(void)
 {
-       struct list_head *p, *n;
+       struct rfcomm_session *s, *n;
 
        rfcomm_lock();
 
-       list_for_each_safe(p, n, &session_list) {
-               struct rfcomm_session *s;
-               s = list_entry(p, struct rfcomm_session, list);
-
+       list_for_each_entry_safe(s, n, &session_list, list) {
                if (test_and_clear_bit(RFCOMM_TIMED_OUT, &s->flags)) {
                        s->state = BT_DISCONN;
                        rfcomm_send_disc(s, 0);
@@ -2075,15 +2063,12 @@ failed:
 
 static void rfcomm_kill_listener(void)
 {
-       struct rfcomm_session *s;
-       struct list_head *p, *n;
+       struct rfcomm_session *s, *n;
 
        BT_DBG("");
 
-       list_for_each_safe(p, n, &session_list) {
-               s = list_entry(p, struct rfcomm_session, list);
+       list_for_each_entry_safe(s, n, &session_list, list)
                rfcomm_session_del(s);
-       }
 }
 
 static int rfcomm_run(void *unused)
@@ -2113,8 +2098,7 @@ static int rfcomm_run(void *unused)
 static void rfcomm_security_cfm(struct hci_conn *conn, u8 status, u8 encrypt)
 {
        struct rfcomm_session *s;
-       struct rfcomm_dlc *d;
-       struct list_head *p, *n;
+       struct rfcomm_dlc *d, *n;
 
        BT_DBG("conn %p status 0x%02x encrypt 0x%02x", conn, status, encrypt);
 
@@ -2122,9 +2106,7 @@ static void rfcomm_security_cfm(struct hci_conn *conn, u8 status, u8 encrypt)
        if (!s)
                return;
 
-       list_for_each_safe(p, n, &s->dlcs) {
-               d = list_entry(p, struct rfcomm_dlc, list);
-
+       list_for_each_entry_safe(d, n, &s->dlcs, list) {
                if (test_and_clear_bit(RFCOMM_SEC_PENDING, &d->flags)) {
                        rfcomm_dlc_clear_timer(d);
                        if (status || encrypt == 0x00) {