2015-12-18 15:34:31

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 01/14] Bluetooth: use list_for_each_entry*

Use list_for_each_entry*() instead of list_for_each*() to simplify
the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/bluetooth/af_bluetooth.c | 12 ++++++------
net/bluetooth/cmtp/capi.c | 8 ++------
net/bluetooth/hci_core.c | 8 +++-----
net/bluetooth/rfcomm/core.c | 46 ++++++++++++++------------------------------
4 files changed, 25 insertions(+), 49 deletions(-)

diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index cb4e8d4..955eda9 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -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))
diff --git a/net/bluetooth/cmtp/capi.c b/net/bluetooth/cmtp/capi.c
index 9a503387..46ac686 100644
--- a/net/bluetooth/cmtp/capi.c
+++ b/net/bluetooth/cmtp/capi.c
@@ -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);
}

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 9fb443a..47bcef7 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -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);
}
}
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index 29709fb..f7eb02f 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -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) {
--
2.5.0


2015-12-18 15:34:13

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 02/14] sctp: use list_for_each_entry*

Use list_for_each_entry*() instead of list_for_each*() to simplify
the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/sctp/associola.c | 24 +++++++++------------
net/sctp/chunk.c | 16 ++++++--------
net/sctp/outqueue.c | 56 +++++++++++++++++++-----------------------------
net/sctp/protocol.c | 12 ++++-------
net/sctp/sm_make_chunk.c | 11 +++++-----
net/sctp/sm_sideeffect.c | 8 +++----
net/sctp/socket.c | 7 ++----
7 files changed, 52 insertions(+), 82 deletions(-)

diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 559afd0..a7065ca 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -324,8 +324,7 @@ fail:
void sctp_association_free(struct sctp_association *asoc)
{
struct sock *sk = asoc->base.sk;
- struct sctp_transport *transport;
- struct list_head *pos, *temp;
+ struct sctp_transport *transport, *temp;
int i;

/* Only real associations count against the endpoint, so
@@ -380,9 +379,9 @@ void sctp_association_free(struct sctp_association *asoc)
kfree(asoc->peer.peer_hmacs);

/* Release the transport structures. */
- list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
- transport = list_entry(pos, struct sctp_transport, transports);
- list_del_rcu(pos);
+ list_for_each_entry_safe(transport, temp,
+ &asoc->peer.transport_addr_list, transports) {
+ list_del_rcu(&transport->transports);
sctp_transport_free(transport);
}

@@ -718,12 +717,10 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
void sctp_assoc_del_peer(struct sctp_association *asoc,
const union sctp_addr *addr)
{
- struct list_head *pos;
- struct list_head *temp;
- struct sctp_transport *transport;
+ struct sctp_transport *transport, *temp;

- list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
- transport = list_entry(pos, struct sctp_transport, transports);
+ list_for_each_entry_safe(transport, temp,
+ &asoc->peer.transport_addr_list, transports) {
if (sctp_cmp_addr_exact(addr, &transport->ipaddr)) {
/* Do book keeping for removing the peer and free it. */
sctp_assoc_rm_peer(asoc, transport);
@@ -1090,8 +1087,7 @@ void sctp_assoc_migrate(struct sctp_association *assoc, struct sock *newsk)
void sctp_assoc_update(struct sctp_association *asoc,
struct sctp_association *new)
{
- struct sctp_transport *trans;
- struct list_head *pos, *temp;
+ struct sctp_transport *trans, *temp;

/* Copy in new parameters of peer. */
asoc->c = new->c;
@@ -1103,8 +1099,8 @@ void sctp_assoc_update(struct sctp_association *asoc,
asoc->peer.i.initial_tsn, GFP_ATOMIC);

/* Remove any peer addresses not present in the new association. */
- list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
- trans = list_entry(pos, struct sctp_transport, transports);
+ list_for_each_entry_safe(trans, temp,
+ &asoc->peer.transport_addr_list, transports) {
if (!sctp_assoc_lookup_paddr(new, &trans->ipaddr)) {
sctp_assoc_rm_peer(asoc, trans);
continue;
diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
index a338091..b024109 100644
--- a/net/sctp/chunk.c
+++ b/net/sctp/chunk.c
@@ -86,8 +86,7 @@ void sctp_datamsg_free(struct sctp_datamsg *msg)
/* Final destructruction of datamsg memory. */
static void sctp_datamsg_destroy(struct sctp_datamsg *msg)
{
- struct list_head *pos, *temp;
- struct sctp_chunk *chunk;
+ struct sctp_chunk *chunk, *temp;
struct sctp_sock *sp;
struct sctp_ulpevent *ev;
struct sctp_association *asoc = NULL;
@@ -97,9 +96,8 @@ static void sctp_datamsg_destroy(struct sctp_datamsg *msg)
notify = msg->send_failed ? -1 : 0;

/* Release all references. */
- list_for_each_safe(pos, temp, &msg->chunks) {
- list_del_init(pos);
- chunk = list_entry(pos, struct sctp_chunk, frag_list);
+ list_for_each_entry_safe(chunk, temp, &msg->chunks, frag_list) {
+ list_del_init(&chunk->frag_list);
/* Check whether we _really_ need to notify. */
if (notify < 0) {
asoc = chunk->asoc;
@@ -169,9 +167,8 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
int max, whole, i, offset, over, err;
int len, first_len;
int max_data;
- struct sctp_chunk *chunk;
+ struct sctp_chunk *chunk, *temp;
struct sctp_datamsg *msg;
- struct list_head *pos, *temp;
size_t msg_len = iov_iter_count(from);
__u8 frag;

@@ -334,9 +331,8 @@ errout_chunk_free:
sctp_chunk_free(chunk);

errout:
- list_for_each_safe(pos, temp, &msg->chunks) {
- list_del_init(pos);
- chunk = list_entry(pos, struct sctp_chunk, frag_list);
+ list_for_each_entry_safe(chunk, temp, &msg->chunks, frag_list) {
+ list_del_init(&chunk->frag_list);
sctp_chunk_free(chunk);
}
sctp_datamsg_put(msg);
diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c
index 7e8f0a1..f72a443 100644
--- a/net/sctp/outqueue.c
+++ b/net/sctp/outqueue.c
@@ -214,7 +214,7 @@ void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
static void __sctp_outq_teardown(struct sctp_outq *q)
{
struct sctp_transport *transport;
- struct list_head *lchunk, *temp;
+ struct list_head *lchunk;
struct sctp_chunk *chunk, *tmp;

/* Throw away unacknowledged chunks. */
@@ -230,28 +230,22 @@ static void __sctp_outq_teardown(struct sctp_outq *q)
}

/* Throw away chunks that have been gap ACKed. */
- list_for_each_safe(lchunk, temp, &q->sacked) {
- list_del_init(lchunk);
- chunk = list_entry(lchunk, struct sctp_chunk,
- transmitted_list);
+ list_for_each_entry_safe(chunk, tmp, &q->sacked, transmitted_list) {
+ list_del_init(&chunk->transmitted_list);
sctp_chunk_fail(chunk, q->error);
sctp_chunk_free(chunk);
}

/* Throw away any chunks in the retransmit queue. */
- list_for_each_safe(lchunk, temp, &q->retransmit) {
- list_del_init(lchunk);
- chunk = list_entry(lchunk, struct sctp_chunk,
- transmitted_list);
+ list_for_each_entry_safe(chunk, tmp, &q->retransmit, transmitted_list) {
+ list_del_init(&chunk->transmitted_list);
sctp_chunk_fail(chunk, q->error);
sctp_chunk_free(chunk);
}

/* Throw away any chunks that are in the abandoned queue. */
- list_for_each_safe(lchunk, temp, &q->abandoned) {
- list_del_init(lchunk);
- chunk = list_entry(lchunk, struct sctp_chunk,
- transmitted_list);
+ list_for_each_entry_safe(chunk, tmp, &q->abandoned, transmitted_list) {
+ list_del_init(&chunk->transmitted_list);
sctp_chunk_fail(chunk, q->error);
sctp_chunk_free(chunk);
}
@@ -376,18 +370,16 @@ void sctp_retransmit_mark(struct sctp_outq *q,
struct sctp_transport *transport,
__u8 reason)
{
- struct list_head *lchunk, *ltemp;
- struct sctp_chunk *chunk;
+ struct sctp_chunk *chunk, *temp;

/* Walk through the specified transmitted queue. */
- list_for_each_safe(lchunk, ltemp, &transport->transmitted) {
- chunk = list_entry(lchunk, struct sctp_chunk,
- transmitted_list);
-
+ list_for_each_entry_safe(chunk, temp, &transport->transmitted,
+ transmitted_list) {
/* If the chunk is abandoned, move it to abandoned list. */
if (sctp_chunk_abandoned(chunk)) {
- list_del_init(lchunk);
- sctp_insert_list(&q->abandoned, lchunk);
+ list_del_init(&chunk->transmitted_list);
+ sctp_insert_list(&q->abandoned,
+ &chunk->transmitted_list);

/* If this chunk has not been previousely acked,
* stop considering it 'outstanding'. Our peer
@@ -447,8 +439,9 @@ void sctp_retransmit_mark(struct sctp_outq *q,
/* Move the chunk to the retransmit queue. The chunks
* on the retransmit queue are always kept in order.
*/
- list_del_init(lchunk);
- sctp_insert_list(&q->retransmit, lchunk);
+ list_del_init(&chunk->transmitted_list);
+ sctp_insert_list(&q->retransmit,
+ &chunk->transmitted_list);
}
}

@@ -1125,8 +1118,8 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
struct sctp_association *asoc = q->asoc;
struct sctp_sackhdr *sack = chunk->subh.sack_hdr;
struct sctp_transport *transport;
- struct sctp_chunk *tchunk = NULL;
- struct list_head *lchunk, *transport_list, *temp;
+ struct sctp_chunk *tchunk = NULL, *temp;
+ struct list_head *transport_list;
sctp_sack_variable_t *frags = sack->variable;
__u32 sack_ctsn, ctsn, tsn;
__u32 highest_tsn, highest_new_tsn;
@@ -1235,9 +1228,7 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
ctsn = asoc->ctsn_ack_point;

/* Throw away stuff rotting on the sack queue. */
- list_for_each_safe(lchunk, temp, &q->sacked) {
- tchunk = list_entry(lchunk, struct sctp_chunk,
- transmitted_list);
+ list_for_each_entry_safe(tchunk, temp, &q->sacked, transmitted_list) {
tsn = ntohl(tchunk->subh.data_hdr->tsn);
if (TSN_lte(tsn, ctsn)) {
list_del_init(&tchunk->transmitted_list);
@@ -1689,8 +1680,7 @@ static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
int nskips = 0;
int skip_pos = 0;
__u32 tsn;
- struct sctp_chunk *chunk;
- struct list_head *lchunk, *temp;
+ struct sctp_chunk *chunk, *temp;

if (!asoc->peer.prsctp_capable)
return;
@@ -1725,16 +1715,14 @@ static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
* In this example, the data sender successfully advanced the
* "Advanced.Peer.Ack.Point" from 102 to 104 locally.
*/
- list_for_each_safe(lchunk, temp, &q->abandoned) {
- chunk = list_entry(lchunk, struct sctp_chunk,
- transmitted_list);
+ list_for_each_entry_safe(chunk, temp, &q->abandoned, transmitted_list) {
tsn = ntohl(chunk->subh.data_hdr->tsn);

/* Remove any chunks in the abandoned queue that are acked by
* the ctsn.
*/
if (TSN_lte(tsn, ctsn)) {
- list_del_init(lchunk);
+ list_del_init(&chunk->transmitted_list);
sctp_chunk_free(chunk);
} else {
if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) {
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 010aced..bd41095 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -166,13 +166,11 @@ static void sctp_v4_copy_addrlist(struct list_head *addrlist,
static void sctp_get_local_addr_list(struct net *net)
{
struct net_device *dev;
- struct list_head *pos;
struct sctp_af *af;

rcu_read_lock();
for_each_netdev_rcu(net, dev) {
- list_for_each(pos, &sctp_address_families) {
- af = list_entry(pos, struct sctp_af, list);
+ list_for_each_entry(af, &sctp_address_families, list) {
af->copy_addrlist(&net->sctp.local_addr_list, dev);
}
}
@@ -182,12 +180,10 @@ static void sctp_get_local_addr_list(struct net *net)
/* Free the existing local addresses. */
static void sctp_free_local_addr_list(struct net *net)
{
- struct sctp_sockaddr_entry *addr;
- struct list_head *pos, *temp;
+ struct sctp_sockaddr_entry *addr, *temp;

- list_for_each_safe(pos, temp, &net->sctp.local_addr_list) {
- addr = list_entry(pos, struct sctp_sockaddr_entry, list);
- list_del(pos);
+ list_for_each_entry_safe(addr, temp, &net->sctp.local_addr_list, list) {
+ list_del(&addr->list);
kfree(addr);
}
}
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 763e06a..819bbc4 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -2293,8 +2293,7 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
{
struct net *net = sock_net(asoc->base.sk);
union sctp_params param;
- struct sctp_transport *transport;
- struct list_head *pos, *temp;
+ struct sctp_transport *transport, *temp;
struct sctp_af *af;
union sctp_addr addr;
char *cookie;
@@ -2358,8 +2357,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
}

/* Walk list of transports, removing transports in the UNKNOWN state. */
- list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
- transport = list_entry(pos, struct sctp_transport, transports);
+ list_for_each_entry_safe(transport, temp,
+ &asoc->peer.transport_addr_list, transports) {
if (transport->state == SCTP_UNKNOWN) {
sctp_assoc_rm_peer(asoc, transport);
}
@@ -2461,8 +2460,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,

clean_up:
/* Release the transport structures. */
- list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
- transport = list_entry(pos, struct sctp_transport, transports);
+ list_for_each_entry_safe(transport, temp,
+ &asoc->peer.transport_addr_list, transports) {
if (transport->state != SCTP_ACTIVE)
sctp_assoc_rm_peer(asoc, transport);
}
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index 05cd164..7521e56 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -953,12 +953,10 @@ static void sctp_cmd_process_fwdtsn(struct sctp_ulpq *ulpq,
*/
static void sctp_cmd_del_non_primary(struct sctp_association *asoc)
{
- struct sctp_transport *t;
- struct list_head *pos;
- struct list_head *temp;
+ struct sctp_transport *t, *temp;

- list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
- t = list_entry(pos, struct sctp_transport, transports);
+ list_for_each_entry_safe(t, temp, &asoc->peer.transport_addr_list,
+ transports) {
if (!sctp_cmp_addr_exact(&t->ipaddr,
&asoc->peer.primary_addr)) {
sctp_assoc_rm_peer(asoc, t);
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 106bb09..9272e7b 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -1474,8 +1474,7 @@ static void sctp_close(struct sock *sk, long timeout)
{
struct net *net = sock_net(sk);
struct sctp_endpoint *ep;
- struct sctp_association *asoc;
- struct list_head *pos, *temp;
+ struct sctp_association *asoc, *temp;
unsigned int data_was_unread;

pr_debug("%s: sk:%p, timeout:%ld\n", __func__, sk, timeout);
@@ -1491,9 +1490,7 @@ static void sctp_close(struct sock *sk, long timeout)
data_was_unread += sctp_queue_purge_ulpevents(&sctp_sk(sk)->pd_lobby);

/* Walk all associations on an endpoint. */
- list_for_each_safe(pos, temp, &ep->asocs) {
- asoc = list_entry(pos, struct sctp_association, asocs);
-
+ list_for_each_entry_safe(asoc, temp, &ep->asocs, asocs) {
if (sctp_style(sk, TCP)) {
/* A closed association can still be in the list if
* it belongs to a TCP-style listening socket that is
--
2.5.0

2015-12-18 15:34:39

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 03/14] ipv4, ipv6: use list_for_each_entry*

Use list_for_each_entry*() instead of list_for_each*() to simplify
the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/ipv4/af_inet.c | 6 ++----
net/ipv4/tcp_output.c | 6 ++----
net/ipv6/addrconf.c | 8 +++-----
net/ipv6/af_inet6.c | 7 ++-----
4 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 11c4ca1..bb11ec1 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1028,7 +1028,6 @@ static struct inet_protosw inetsw_array[] =

void inet_register_protosw(struct inet_protosw *p)
{
- struct list_head *lh;
struct inet_protosw *answer;
int protocol = p->protocol;
struct list_head *last_perm;
@@ -1040,14 +1039,13 @@ void inet_register_protosw(struct inet_protosw *p)

/* If we are trying to override a permanent protocol, bail. */
last_perm = &inetsw[p->type];
- list_for_each(lh, &inetsw[p->type]) {
- answer = list_entry(lh, struct inet_protosw, list);
+ list_for_each_entry(answer, &inetsw[p->type], list) {
/* Check only the non-wild match. */
if ((INET_PROTOSW_PERMANENT & answer->flags) == 0)
break;
if (protocol == answer->protocol)
goto out_permanent;
- last_perm = lh;
+ last_perm = &answer->list;
}

/* Add the new entry after the last permanent entry if any, so that
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index a800cee..8810694 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -751,16 +751,14 @@ static void tcp_tasklet_func(unsigned long data)
struct tsq_tasklet *tsq = (struct tsq_tasklet *)data;
LIST_HEAD(list);
unsigned long flags;
- struct list_head *q, *n;
- struct tcp_sock *tp;
+ struct tcp_sock *tp, *n;
struct sock *sk;

local_irq_save(flags);
list_splice_init(&tsq->head, &list);
local_irq_restore(flags);

- list_for_each_safe(q, n, &list) {
- tp = list_entry(q, struct tcp_sock, tsq_node);
+ list_for_each_entry_safe(tp, n, &list, tsq_node) {
list_del(&tp->tsq_node);

sk = (struct sock *)tp;
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 7082fb7..e293647 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -865,21 +865,19 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
static void
ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp)
{
- struct list_head *p;
+ struct inet6_ifaddr *ifa;
int ifp_scope = ipv6_addr_src_scope(&ifp->addr);

/*
* Each device address list is sorted in order of scope -
* global before linklocal.
*/
- list_for_each(p, &idev->addr_list) {
- struct inet6_ifaddr *ifa
- = list_entry(p, struct inet6_ifaddr, if_list);
+ list_for_each_entry(ifa, &idev->addr_list, if_list) {
if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr))
break;
}

- list_add_tail(&ifp->if_list, p);
+ list_add_tail(&ifp->if_list, &ifa->if_list);
}

static u32 inet6_addr_hash(const struct in6_addr *addr)
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 8ec0df7..a4fb172 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -568,7 +568,6 @@ static const struct net_proto_family inet6_family_ops = {

int inet6_register_protosw(struct inet_protosw *p)
{
- struct list_head *lh;
struct inet_protosw *answer;
struct list_head *last_perm;
int protocol = p->protocol;
@@ -584,14 +583,12 @@ int inet6_register_protosw(struct inet_protosw *p)
answer = NULL;
ret = -EPERM;
last_perm = &inetsw6[p->type];
- list_for_each(lh, &inetsw6[p->type]) {
- answer = list_entry(lh, struct inet_protosw, list);
-
+ list_for_each_entry(answer, &inetsw6[p->type], list) {
/* Check only the non-wild match. */
if (INET_PROTOSW_PERMANENT & answer->flags) {
if (protocol == answer->protocol)
break;
- last_perm = lh;
+ last_perm = &answer->list;
}

answer = NULL;
--
2.5.0

2015-12-18 15:34:09

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 04/14] x25: use list_for_each_entry*

Use list_for_each_entry*() instead of list_for_each*() to simplify
the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/x25/x25_forward.c | 20 ++++++--------------
net/x25/x25_link.c | 23 ++++++-----------------
net/x25/x25_route.c | 29 +++++++----------------------
3 files changed, 19 insertions(+), 53 deletions(-)

diff --git a/net/x25/x25_forward.c b/net/x25/x25_forward.c
index cf561f1..4394eb6 100644
--- a/net/x25/x25_forward.c
+++ b/net/x25/x25_forward.c
@@ -24,7 +24,6 @@ int x25_forward_call(struct x25_address *dest_addr, struct x25_neigh *from,
{
struct x25_route *rt;
struct x25_neigh *neigh_new = NULL;
- struct list_head *entry;
struct x25_forward *x25_frwd, *new_frwd;
struct sk_buff *skbn;
short same_lci = 0;
@@ -51,8 +50,7 @@ int x25_forward_call(struct x25_address *dest_addr, struct x25_neigh *from,
* established LCI? It shouldn't happen, just in case..
*/
read_lock_bh(&x25_forward_list_lock);
- list_for_each(entry, &x25_forward_list) {
- x25_frwd = list_entry(entry, struct x25_forward, node);
+ list_for_each_entry(x25_frwd, &x25_forward_list, node) {
if (x25_frwd->lci == lci) {
pr_warn("call request for lci which is already registered!, transmitting but not registering new pair\n");
same_lci = 1;
@@ -97,15 +95,13 @@ out_no_route:
int x25_forward_data(int lci, struct x25_neigh *from, struct sk_buff *skb) {

struct x25_forward *frwd;
- struct list_head *entry;
struct net_device *peer = NULL;
struct x25_neigh *nb;
struct sk_buff *skbn;
int rc = 0;

read_lock_bh(&x25_forward_list_lock);
- list_for_each(entry, &x25_forward_list) {
- frwd = list_entry(entry, struct x25_forward, node);
+ list_for_each_entry(frwd, &x25_forward_list, node) {
if (frwd->lci == lci) {
/* The call is established, either side can send */
if (from->dev == frwd->dev1) {
@@ -136,13 +132,11 @@ out:

void x25_clear_forward_by_lci(unsigned int lci)
{
- struct x25_forward *fwd;
- struct list_head *entry, *tmp;
+ struct x25_forward *fwd, *tmp;

write_lock_bh(&x25_forward_list_lock);

- list_for_each_safe(entry, tmp, &x25_forward_list) {
- fwd = list_entry(entry, struct x25_forward, node);
+ list_for_each_entry_safe(fwd, tmp, &x25_forward_list, node) {
if (fwd->lci == lci) {
list_del(&fwd->node);
kfree(fwd);
@@ -154,13 +148,11 @@ void x25_clear_forward_by_lci(unsigned int lci)

void x25_clear_forward_by_dev(struct net_device *dev)
{
- struct x25_forward *fwd;
- struct list_head *entry, *tmp;
+ struct x25_forward *fwd, *tmp;

write_lock_bh(&x25_forward_list_lock);

- list_for_each_safe(entry, tmp, &x25_forward_list) {
- fwd = list_entry(entry, struct x25_forward, node);
+ list_for_each_entry_safe(fwd, tmp, &x25_forward_list, node) {
if ((fwd->dev1 == dev) || (fwd->dev2 == dev)){
list_del(&fwd->node);
kfree(fwd);
diff --git a/net/x25/x25_link.c b/net/x25/x25_link.c
index fd5ffb2..61cc8a2 100644
--- a/net/x25/x25_link.c
+++ b/net/x25/x25_link.c
@@ -296,14 +296,11 @@ static void __x25_remove_neigh(struct x25_neigh *nb)
*/
void x25_link_device_down(struct net_device *dev)
{
- struct x25_neigh *nb;
- struct list_head *entry, *tmp;
+ struct x25_neigh *nb, *tmp;

write_lock_bh(&x25_neigh_list_lock);

- list_for_each_safe(entry, tmp, &x25_neigh_list) {
- nb = list_entry(entry, struct x25_neigh, node);
-
+ list_for_each_entry_safe(nb, tmp, &x25_neigh_list, node) {
if (nb->dev == dev) {
__x25_remove_neigh(nb);
dev_put(dev);
@@ -319,12 +316,9 @@ void x25_link_device_down(struct net_device *dev)
struct x25_neigh *x25_get_neigh(struct net_device *dev)
{
struct x25_neigh *nb, *use = NULL;
- struct list_head *entry;

read_lock_bh(&x25_neigh_list_lock);
- list_for_each(entry, &x25_neigh_list) {
- nb = list_entry(entry, struct x25_neigh, node);
-
+ list_for_each_entry(nb, &x25_neigh_list, node) {
if (nb->dev == dev) {
use = nb;
break;
@@ -394,18 +388,13 @@ out_dev_put:
*/
void __exit x25_link_free(void)
{
- struct x25_neigh *nb;
- struct list_head *entry, *tmp;
+ struct x25_neigh *nb, *tmp;

write_lock_bh(&x25_neigh_list_lock);

- list_for_each_safe(entry, tmp, &x25_neigh_list) {
- struct net_device *dev;
-
- nb = list_entry(entry, struct x25_neigh, node);
- dev = nb->dev;
+ list_for_each_entry_safe(nb, tmp, &x25_neigh_list, node) {
__x25_remove_neigh(nb);
- dev_put(dev);
+ dev_put(nb->dev);
}
write_unlock_bh(&x25_neigh_list_lock);
}
diff --git a/net/x25/x25_route.c b/net/x25/x25_route.c
index 277c8d2..50562d7 100644
--- a/net/x25/x25_route.c
+++ b/net/x25/x25_route.c
@@ -32,14 +32,11 @@ static int x25_add_route(struct x25_address *address, unsigned int sigdigits,
struct net_device *dev)
{
struct x25_route *rt;
- struct list_head *entry;
int rc = -EINVAL;

write_lock_bh(&x25_route_list_lock);

- list_for_each(entry, &x25_route_list) {
- rt = list_entry(entry, struct x25_route, node);
-
+ list_for_each_entry(rt, &x25_route_list, node) {
if (!memcmp(&rt->address, address, sigdigits) &&
rt->sigdigits == sigdigits)
goto out;
@@ -83,14 +80,11 @@ static int x25_del_route(struct x25_address *address, unsigned int sigdigits,
struct net_device *dev)
{
struct x25_route *rt;
- struct list_head *entry;
int rc = -EINVAL;

write_lock_bh(&x25_route_list_lock);

- list_for_each(entry, &x25_route_list) {
- rt = list_entry(entry, struct x25_route, node);
-
+ list_for_each_entry(rt, &x25_route_list, node) {
if (!memcmp(&rt->address, address, sigdigits) &&
rt->sigdigits == sigdigits && rt->dev == dev) {
__x25_remove_route(rt);
@@ -108,14 +102,11 @@ static int x25_del_route(struct x25_address *address, unsigned int sigdigits,
*/
void x25_route_device_down(struct net_device *dev)
{
- struct x25_route *rt;
- struct list_head *entry, *tmp;
+ struct x25_route *rt, *tmp;

write_lock_bh(&x25_route_list_lock);

- list_for_each_safe(entry, tmp, &x25_route_list) {
- rt = list_entry(entry, struct x25_route, node);
-
+ list_for_each_entry_safe(rt, tmp, &x25_route_list, node) {
if (rt->dev == dev)
__x25_remove_route(rt);
}
@@ -154,13 +145,10 @@ struct net_device *x25_dev_get(char *devname)
struct x25_route *x25_get_route(struct x25_address *addr)
{
struct x25_route *rt, *use = NULL;
- struct list_head *entry;

read_lock_bh(&x25_route_list_lock);

- list_for_each(entry, &x25_route_list) {
- rt = list_entry(entry, struct x25_route, node);
-
+ list_for_each_entry(rt, &x25_route_list, node) {
if (!memcmp(&rt->address, addr, rt->sigdigits)) {
if (!use)
use = rt;
@@ -214,13 +202,10 @@ out:
*/
void __exit x25_route_free(void)
{
- struct x25_route *rt;
- struct list_head *entry, *tmp;
+ struct x25_route *rt, *tmp;

write_lock_bh(&x25_route_list_lock);
- list_for_each_safe(entry, tmp, &x25_route_list) {
- rt = list_entry(entry, struct x25_route, node);
+ list_for_each_entry_safe(rt, tmp, &x25_route_list, node)
__x25_remove_route(rt);
- }
write_unlock_bh(&x25_route_list_lock);
}
--
2.5.0

2015-12-18 15:34:06

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 05/14] atm: use list_for_each_entry

Use list_for_each_entry() instead of list_for_each() to simplify
the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/atm/ioctl.c | 5 ++---
net/atm/resources.c | 8 ++------
2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/net/atm/ioctl.c b/net/atm/ioctl.c
index bbd3b63..9feb293 100644
--- a/net/atm/ioctl.c
+++ b/net/atm/ioctl.c
@@ -53,7 +53,7 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,
struct sock *sk = sock->sk;
struct atm_vcc *vcc;
int error;
- struct list_head *pos;
+ struct atm_ioctl *ic;
void __user *argp = (void __user *)arg;

vcc = ATM_SD(sock);
@@ -163,8 +163,7 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,
error = -ENOIOCTLCMD;

mutex_lock(&ioctl_mutex);
- list_for_each(pos, &ioctl_list) {
- struct atm_ioctl *ic = list_entry(pos, struct atm_ioctl, list);
+ list_for_each_entry(ic, &ioctl_list, list) {
if (try_module_get(ic->owner)) {
error = ic->ioctl(sock, cmd, arg);
module_put(ic->owner);
diff --git a/net/atm/resources.c b/net/atm/resources.c
index 0447d5d..413d919 100644
--- a/net/atm/resources.c
+++ b/net/atm/resources.c
@@ -51,10 +51,8 @@ static struct atm_dev *__alloc_atm_dev(const char *type)
static struct atm_dev *__atm_dev_lookup(int number)
{
struct atm_dev *dev;
- struct list_head *p;

- list_for_each(p, &atm_devs) {
- dev = list_entry(p, struct atm_dev, dev_list);
+ list_for_each_entry(dev, &atm_devs, dev_list) {
if (dev->number == number) {
atm_dev_hold(dev);
return dev;
@@ -238,10 +236,8 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat)
return -ENOMEM;
}
tmp_p = tmp_buf;
- list_for_each(p, &atm_devs) {
- dev = list_entry(p, struct atm_dev, dev_list);
+ list_for_each_entry(dev, &atm_devs, dev_list)
*tmp_p++ = dev->number;
- }
mutex_unlock(&atm_dev_mutex);
error = ((copy_to_user(buf, tmp_buf, size)) ||
put_user(size, iobuf_len))
--
2.5.0

2015-12-18 15:40:08

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 06/14] libceph: use list_for_each_entry_safe

Use list_for_each_entry_safe() instead of list_for_each_safe() to
simplify the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/ceph/messenger.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 9981039..c664b7f 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -3361,9 +3361,8 @@ static void ceph_msg_free(struct ceph_msg *m)
static void ceph_msg_release(struct kref *kref)
{
struct ceph_msg *m = container_of(kref, struct ceph_msg, kref);
- LIST_HEAD(data);
- struct list_head *links;
- struct list_head *next;
+ LIST_HEAD(head);
+ struct ceph_msg_data *data, *next;

dout("%s %p\n", __func__, m);
WARN_ON(!list_empty(&m->list_head));
@@ -3376,12 +3375,9 @@ static void ceph_msg_release(struct kref *kref)
m->middle = NULL;
}

- list_splice_init(&m->data, &data);
- list_for_each_safe(links, next, &data) {
- struct ceph_msg_data *data;
-
- data = list_entry(links, struct ceph_msg_data, links);
- list_del_init(links);
+ list_splice_init(&m->data, &head);
+ list_for_each_entry_safe(data, next, &head, links) {
+ list_del_init(&data->links);
ceph_msg_data_destroy(data);
}
m->data_length = 0;
--
2.5.0

2015-12-18 15:34:33

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 07/14] batman-adv: use list_for_each_entry_safe

Use list_for_each_entry_safe() instead of list_for_each_safe() to
simplify the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/batman-adv/icmp_socket.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c
index bcabb5e..841239c 100644
--- a/net/batman-adv/icmp_socket.c
+++ b/net/batman-adv/icmp_socket.c
@@ -104,25 +104,21 @@ static int batadv_socket_open(struct inode *inode, struct file *file)

static int batadv_socket_release(struct inode *inode, struct file *file)
{
- struct batadv_socket_client *socket_client = file->private_data;
- struct batadv_socket_packet *socket_packet;
- struct list_head *list_pos, *list_pos_tmp;
+ struct batadv_socket_client *client = file->private_data;
+ struct batadv_socket_packet *packet, *tmp;

- spin_lock_bh(&socket_client->lock);
+ spin_lock_bh(&client->lock);

/* for all packets in the queue ... */
- list_for_each_safe(list_pos, list_pos_tmp, &socket_client->queue_list) {
- socket_packet = list_entry(list_pos,
- struct batadv_socket_packet, list);
-
- list_del(list_pos);
- kfree(socket_packet);
+ list_for_each_entry_safe(packet, tmp, &client->queue_list, list) {
+ list_del(&packet->list);
+ kfree(packet);
}

- batadv_socket_client_hash[socket_client->index] = NULL;
- spin_unlock_bh(&socket_client->lock);
+ batadv_socket_client_hash[client->index] = NULL;
+ spin_unlock_bh(&client->lock);

- kfree(socket_client);
+ kfree(client);
module_put(THIS_MODULE);

return 0;
--
2.5.0

2015-12-18 15:34:15

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 08/14] caif: use list_for_each_entry_safe

Use list_for_each_entry_safe() instead of list_for_each_safe() to
simplify the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/caif/chnl_net.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
index 67a4a36..d3db77c 100644
--- a/net/caif/chnl_net.c
+++ b/net/caif/chnl_net.c
@@ -140,13 +140,10 @@ static int delete_device(struct chnl_net *dev)

static void close_work(struct work_struct *work)
{
- struct chnl_net *dev = NULL;
- struct list_head *list_node;
- struct list_head *_tmp;
+ struct chnl_net *dev = NULL, *tmp;

rtnl_lock();
- list_for_each_safe(list_node, _tmp, &chnl_net_list) {
- dev = list_entry(list_node, struct chnl_net, list_field);
+ list_for_each_entry_safe(dev, tmp, &chnl_net_list, list_field) {
if (dev->state == CAIF_SHUTDOWN)
dev_close(dev->netdev);
}
@@ -535,14 +532,11 @@ static int __init chnl_init_module(void)

static void __exit chnl_exit_module(void)
{
- struct chnl_net *dev = NULL;
- struct list_head *list_node;
- struct list_head *_tmp;
+ struct chnl_net *dev = NULL, *tmp;
rtnl_link_unregister(&ipcaif_link_ops);
rtnl_lock();
- list_for_each_safe(list_node, _tmp, &chnl_net_list) {
- dev = list_entry(list_node, struct chnl_net, list_field);
- list_del(list_node);
+ list_for_each_entry_safe(dev, tmp, &chnl_net_list, list_field) {
+ list_del(&dev->list_field);
delete_device(dev);
}
rtnl_unlock();
--
2.5.0

2015-12-18 15:36:04

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 09/14] net: dsa: use list_for_each_entry

Use list_for_each_entry() instead of list_for_each() to simplify
the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/dsa/dsa.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 208d1b2..2ab4a19 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -53,19 +53,14 @@ EXPORT_SYMBOL_GPL(unregister_switch_driver);
static struct dsa_switch_driver *
dsa_switch_probe(struct device *host_dev, int sw_addr, char **_name)
{
- struct dsa_switch_driver *ret;
- struct list_head *list;
+ struct dsa_switch_driver *ret, *drv;
char *name;

ret = NULL;
name = NULL;

mutex_lock(&dsa_switch_drivers_mutex);
- list_for_each(list, &dsa_switch_drivers) {
- struct dsa_switch_driver *drv;
-
- drv = list_entry(list, struct dsa_switch_driver, list);
-
+ list_for_each_entry(drv, &dsa_switch_drivers, list) {
name = drv->probe(host_dev, sw_addr);
if (name != NULL) {
ret = drv;
--
2.5.0

2015-12-18 15:39:28

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 10/14] lapb: use list_for_each_entry

Use list_for_each_entry() instead of list_for_each() to simplify
the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/lapb/lapb_iface.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
index fc60d9d..49abba7 100644
--- a/net/lapb/lapb_iface.c
+++ b/net/lapb/lapb_iface.c
@@ -86,11 +86,9 @@ static void __lapb_insert_cb(struct lapb_cb *lapb)

static struct lapb_cb *__lapb_devtostruct(struct net_device *dev)
{
- struct list_head *entry;
struct lapb_cb *lapb, *use = NULL;

- list_for_each(entry, &lapb_list) {
- lapb = list_entry(entry, struct lapb_cb, node);
+ list_for_each_entry(lapb, &lapb_list, node) {
if (lapb->dev == dev) {
use = lapb;
break;
--
2.5.0

2015-12-18 15:34:54

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 11/14] openvswitch: use list_for_each_entry

Use list_for_each_entry() instead of list_for_each() to simplify
the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/openvswitch/flow_table.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
index d073fff..9b5999ba 100644
--- a/net/openvswitch/flow_table.c
+++ b/net/openvswitch/flow_table.c
@@ -651,11 +651,9 @@ static bool mask_equal(const struct sw_flow_mask *a,
static struct sw_flow_mask *flow_mask_find(const struct flow_table *tbl,
const struct sw_flow_mask *mask)
{
- struct list_head *ml;
+ struct sw_flow_mask *m;

- list_for_each(ml, &tbl->mask_list) {
- struct sw_flow_mask *m;
- m = container_of(ml, struct sw_flow_mask, list);
+ list_for_each_entry(m, &tbl->mask_list, list) {
if (mask_equal(mask, m))
return m;
}
--
2.5.0

2015-12-18 15:36:06

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 12/14] net: sched: use list_for_each_entry

Use list_for_each_entry() instead of list_for_each() to simplify
the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/sched/sch_htb.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index 15ccd7f..5f7aa74 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -948,10 +948,9 @@ static unsigned int htb_drop(struct Qdisc *sch)
int prio;

for (prio = TC_HTB_NUMPRIO - 1; prio >= 0; prio--) {
- struct list_head *p;
- list_for_each(p, q->drops + prio) {
- struct htb_class *cl = list_entry(p, struct htb_class,
- un.leaf.drop_list);
+ struct htb_class *cl;
+
+ list_for_each_entry(cl, q->drops + prio, un.leaf.drop_list) {
unsigned int len;
if (cl->un.leaf.q->ops->drop &&
(len = cl->un.leaf.q->ops->drop(cl->un.leaf.q))) {
--
2.5.0

2015-12-18 15:35:12

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 13/14] sunrpc: use list_for_each_entry_safe

Use list_for_each_entry_safe() instead of list_for_each_safe() to
simplify the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/sunrpc/svc_xprt.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index a6cbb21..fe4f628 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -904,8 +904,7 @@ out:
static void svc_age_temp_xprts(unsigned long closure)
{
struct svc_serv *serv = (struct svc_serv *)closure;
- struct svc_xprt *xprt;
- struct list_head *le, *next;
+ struct svc_xprt *xprt, *next;

dprintk("svc_age_temp_xprts\n");

@@ -916,9 +915,7 @@ static void svc_age_temp_xprts(unsigned long closure)
return;
}

- list_for_each_safe(le, next, &serv->sv_tempsocks) {
- xprt = list_entry(le, struct svc_xprt, xpt_list);
-
+ list_for_each_entry_safe(xprt, next, &serv->sv_tempsocks, xpt_list) {
/* First time through, just mark it OLD. Second time
* through, close it. */
if (!test_and_set_bit(XPT_OLD, &xprt->xpt_flags))
@@ -926,7 +923,7 @@ static void svc_age_temp_xprts(unsigned long closure)
if (atomic_read(&xprt->xpt_ref.refcount) > 1 ||
test_bit(XPT_BUSY, &xprt->xpt_flags))
continue;
- list_del_init(le);
+ list_del_init(&xprt->xpt_list);
set_bit(XPT_CLOSE, &xprt->xpt_flags);
dprintk("queuing xprt %p for closing\n", xprt);

--
2.5.0

2015-12-18 15:34:23

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 14/14] net: pktgen: use list_for_each_entry_safe

Use list_for_each_entry_safe() instead of list_for_each_safe() to
simplify the code.

Signed-off-by: Geliang Tang <[email protected]>
---
net/core/pktgen.c | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 2be1444..1d8cffb 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -3293,14 +3293,11 @@ static void pktgen_stop(struct pktgen_thread *t)
*/
static void pktgen_rem_one_if(struct pktgen_thread *t)
{
- struct list_head *q, *n;
- struct pktgen_dev *cur;
+ struct pktgen_dev *cur, *n;

func_enter();

- list_for_each_safe(q, n, &t->if_list) {
- cur = list_entry(q, struct pktgen_dev, list);
-
+ list_for_each_entry_safe(cur, n, &t->if_list, list) {
if (!cur->removal_mark)
continue;

@@ -3315,16 +3312,13 @@ static void pktgen_rem_one_if(struct pktgen_thread *t)

static void pktgen_rem_all_ifs(struct pktgen_thread *t)
{
- struct list_head *q, *n;
- struct pktgen_dev *cur;
+ struct pktgen_dev *cur, *n;

func_enter();

/* Remove all devices, free mem */

- list_for_each_safe(q, n, &t->if_list) {
- cur = list_entry(q, struct pktgen_dev, list);
-
+ list_for_each_entry_safe(cur, n, &t->if_list, list) {
kfree_skb(cur->skb);
cur->skb = NULL;

@@ -3771,12 +3765,10 @@ static int __net_init pktgen_create_thread(int cpu, struct pktgen_net *pn)
static void _rem_dev_from_if_list(struct pktgen_thread *t,
struct pktgen_dev *pkt_dev)
{
- struct list_head *q, *n;
- struct pktgen_dev *p;
+ struct pktgen_dev *p, *n;

if_lock(t);
- list_for_each_safe(q, n, &t->if_list) {
- p = list_entry(q, struct pktgen_dev, list);
+ list_for_each_entry_safe(p, n, &t->if_list, list) {
if (p == pkt_dev)
list_del_rcu(&p->list);
}
@@ -3866,8 +3858,7 @@ remove:
static void __net_exit pg_net_exit(struct net *net)
{
struct pktgen_net *pn = net_generic(net, pg_net_id);
- struct pktgen_thread *t;
- struct list_head *q, *n;
+ struct pktgen_thread *t, *n;
LIST_HEAD(list);

/* Stop all interfaces & threads */
@@ -3877,8 +3868,7 @@ static void __net_exit pg_net_exit(struct net *net)
list_splice_init(&pn->pktgen_threads, &list);
mutex_unlock(&pktgen_thread_lock);

- list_for_each_safe(q, n, &list) {
- t = list_entry(q, struct pktgen_thread, th_list);
+ list_for_each_entry_safe(t, n, &list, th_list) {
list_del(&t->th_list);
kthread_stop(t->tsk);
put_task_struct(t->tsk);
--
2.5.0

2015-12-18 15:52:26

by Marcelo Ricardo Leitner

[permalink] [raw]
Subject: Re: [PATCH 02/14] sctp: use list_for_each_entry*

On Fri, Dec 18, 2015 at 11:33:26PM +0800, Geliang Tang wrote:
> Use list_for_each_entry*() instead of list_for_each*() to simplify
> the code.
>
> Signed-off-by: Geliang Tang <[email protected]>

Nice, thanks
Acked-by: Marcelo Ricardo Leitner <[email protected]>

> ---
> net/sctp/associola.c | 24 +++++++++------------
> net/sctp/chunk.c | 16 ++++++--------
> net/sctp/outqueue.c | 56 +++++++++++++++++++-----------------------------
> net/sctp/protocol.c | 12 ++++-------
> net/sctp/sm_make_chunk.c | 11 +++++-----
> net/sctp/sm_sideeffect.c | 8 +++----
> net/sctp/socket.c | 7 ++----
> 7 files changed, 52 insertions(+), 82 deletions(-)
>
> diff --git a/net/sctp/associola.c b/net/sctp/associola.c
> index 559afd0..a7065ca 100644
> --- a/net/sctp/associola.c
> +++ b/net/sctp/associola.c
> @@ -324,8 +324,7 @@ fail:
> void sctp_association_free(struct sctp_association *asoc)
> {
> struct sock *sk = asoc->base.sk;
> - struct sctp_transport *transport;
> - struct list_head *pos, *temp;
> + struct sctp_transport *transport, *temp;
> int i;
>
> /* Only real associations count against the endpoint, so
> @@ -380,9 +379,9 @@ void sctp_association_free(struct sctp_association *asoc)
> kfree(asoc->peer.peer_hmacs);
>
> /* Release the transport structures. */
> - list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
> - transport = list_entry(pos, struct sctp_transport, transports);
> - list_del_rcu(pos);
> + list_for_each_entry_safe(transport, temp,
> + &asoc->peer.transport_addr_list, transports) {
> + list_del_rcu(&transport->transports);
> sctp_transport_free(transport);
> }
>
> @@ -718,12 +717,10 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
> void sctp_assoc_del_peer(struct sctp_association *asoc,
> const union sctp_addr *addr)
> {
> - struct list_head *pos;
> - struct list_head *temp;
> - struct sctp_transport *transport;
> + struct sctp_transport *transport, *temp;
>
> - list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
> - transport = list_entry(pos, struct sctp_transport, transports);
> + list_for_each_entry_safe(transport, temp,
> + &asoc->peer.transport_addr_list, transports) {
> if (sctp_cmp_addr_exact(addr, &transport->ipaddr)) {
> /* Do book keeping for removing the peer and free it. */
> sctp_assoc_rm_peer(asoc, transport);
> @@ -1090,8 +1087,7 @@ void sctp_assoc_migrate(struct sctp_association *assoc, struct sock *newsk)
> void sctp_assoc_update(struct sctp_association *asoc,
> struct sctp_association *new)
> {
> - struct sctp_transport *trans;
> - struct list_head *pos, *temp;
> + struct sctp_transport *trans, *temp;
>
> /* Copy in new parameters of peer. */
> asoc->c = new->c;
> @@ -1103,8 +1099,8 @@ void sctp_assoc_update(struct sctp_association *asoc,
> asoc->peer.i.initial_tsn, GFP_ATOMIC);
>
> /* Remove any peer addresses not present in the new association. */
> - list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
> - trans = list_entry(pos, struct sctp_transport, transports);
> + list_for_each_entry_safe(trans, temp,
> + &asoc->peer.transport_addr_list, transports) {
> if (!sctp_assoc_lookup_paddr(new, &trans->ipaddr)) {
> sctp_assoc_rm_peer(asoc, trans);
> continue;
> diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
> index a338091..b024109 100644
> --- a/net/sctp/chunk.c
> +++ b/net/sctp/chunk.c
> @@ -86,8 +86,7 @@ void sctp_datamsg_free(struct sctp_datamsg *msg)
> /* Final destructruction of datamsg memory. */
> static void sctp_datamsg_destroy(struct sctp_datamsg *msg)
> {
> - struct list_head *pos, *temp;
> - struct sctp_chunk *chunk;
> + struct sctp_chunk *chunk, *temp;
> struct sctp_sock *sp;
> struct sctp_ulpevent *ev;
> struct sctp_association *asoc = NULL;
> @@ -97,9 +96,8 @@ static void sctp_datamsg_destroy(struct sctp_datamsg *msg)
> notify = msg->send_failed ? -1 : 0;
>
> /* Release all references. */
> - list_for_each_safe(pos, temp, &msg->chunks) {
> - list_del_init(pos);
> - chunk = list_entry(pos, struct sctp_chunk, frag_list);
> + list_for_each_entry_safe(chunk, temp, &msg->chunks, frag_list) {
> + list_del_init(&chunk->frag_list);
> /* Check whether we _really_ need to notify. */
> if (notify < 0) {
> asoc = chunk->asoc;
> @@ -169,9 +167,8 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
> int max, whole, i, offset, over, err;
> int len, first_len;
> int max_data;
> - struct sctp_chunk *chunk;
> + struct sctp_chunk *chunk, *temp;
> struct sctp_datamsg *msg;
> - struct list_head *pos, *temp;
> size_t msg_len = iov_iter_count(from);
> __u8 frag;
>
> @@ -334,9 +331,8 @@ errout_chunk_free:
> sctp_chunk_free(chunk);
>
> errout:
> - list_for_each_safe(pos, temp, &msg->chunks) {
> - list_del_init(pos);
> - chunk = list_entry(pos, struct sctp_chunk, frag_list);
> + list_for_each_entry_safe(chunk, temp, &msg->chunks, frag_list) {
> + list_del_init(&chunk->frag_list);
> sctp_chunk_free(chunk);
> }
> sctp_datamsg_put(msg);
> diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c
> index 7e8f0a1..f72a443 100644
> --- a/net/sctp/outqueue.c
> +++ b/net/sctp/outqueue.c
> @@ -214,7 +214,7 @@ void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
> static void __sctp_outq_teardown(struct sctp_outq *q)
> {
> struct sctp_transport *transport;
> - struct list_head *lchunk, *temp;
> + struct list_head *lchunk;
> struct sctp_chunk *chunk, *tmp;
>
> /* Throw away unacknowledged chunks. */
> @@ -230,28 +230,22 @@ static void __sctp_outq_teardown(struct sctp_outq *q)
> }
>
> /* Throw away chunks that have been gap ACKed. */
> - list_for_each_safe(lchunk, temp, &q->sacked) {
> - list_del_init(lchunk);
> - chunk = list_entry(lchunk, struct sctp_chunk,
> - transmitted_list);
> + list_for_each_entry_safe(chunk, tmp, &q->sacked, transmitted_list) {
> + list_del_init(&chunk->transmitted_list);
> sctp_chunk_fail(chunk, q->error);
> sctp_chunk_free(chunk);
> }
>
> /* Throw away any chunks in the retransmit queue. */
> - list_for_each_safe(lchunk, temp, &q->retransmit) {
> - list_del_init(lchunk);
> - chunk = list_entry(lchunk, struct sctp_chunk,
> - transmitted_list);
> + list_for_each_entry_safe(chunk, tmp, &q->retransmit, transmitted_list) {
> + list_del_init(&chunk->transmitted_list);
> sctp_chunk_fail(chunk, q->error);
> sctp_chunk_free(chunk);
> }
>
> /* Throw away any chunks that are in the abandoned queue. */
> - list_for_each_safe(lchunk, temp, &q->abandoned) {
> - list_del_init(lchunk);
> - chunk = list_entry(lchunk, struct sctp_chunk,
> - transmitted_list);
> + list_for_each_entry_safe(chunk, tmp, &q->abandoned, transmitted_list) {
> + list_del_init(&chunk->transmitted_list);
> sctp_chunk_fail(chunk, q->error);
> sctp_chunk_free(chunk);
> }
> @@ -376,18 +370,16 @@ void sctp_retransmit_mark(struct sctp_outq *q,
> struct sctp_transport *transport,
> __u8 reason)
> {
> - struct list_head *lchunk, *ltemp;
> - struct sctp_chunk *chunk;
> + struct sctp_chunk *chunk, *temp;
>
> /* Walk through the specified transmitted queue. */
> - list_for_each_safe(lchunk, ltemp, &transport->transmitted) {
> - chunk = list_entry(lchunk, struct sctp_chunk,
> - transmitted_list);
> -
> + list_for_each_entry_safe(chunk, temp, &transport->transmitted,
> + transmitted_list) {
> /* If the chunk is abandoned, move it to abandoned list. */
> if (sctp_chunk_abandoned(chunk)) {
> - list_del_init(lchunk);
> - sctp_insert_list(&q->abandoned, lchunk);
> + list_del_init(&chunk->transmitted_list);
> + sctp_insert_list(&q->abandoned,
> + &chunk->transmitted_list);
>
> /* If this chunk has not been previousely acked,
> * stop considering it 'outstanding'. Our peer
> @@ -447,8 +439,9 @@ void sctp_retransmit_mark(struct sctp_outq *q,
> /* Move the chunk to the retransmit queue. The chunks
> * on the retransmit queue are always kept in order.
> */
> - list_del_init(lchunk);
> - sctp_insert_list(&q->retransmit, lchunk);
> + list_del_init(&chunk->transmitted_list);
> + sctp_insert_list(&q->retransmit,
> + &chunk->transmitted_list);
> }
> }
>
> @@ -1125,8 +1118,8 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
> struct sctp_association *asoc = q->asoc;
> struct sctp_sackhdr *sack = chunk->subh.sack_hdr;
> struct sctp_transport *transport;
> - struct sctp_chunk *tchunk = NULL;
> - struct list_head *lchunk, *transport_list, *temp;
> + struct sctp_chunk *tchunk = NULL, *temp;
> + struct list_head *transport_list;
> sctp_sack_variable_t *frags = sack->variable;
> __u32 sack_ctsn, ctsn, tsn;
> __u32 highest_tsn, highest_new_tsn;
> @@ -1235,9 +1228,7 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
> ctsn = asoc->ctsn_ack_point;
>
> /* Throw away stuff rotting on the sack queue. */
> - list_for_each_safe(lchunk, temp, &q->sacked) {
> - tchunk = list_entry(lchunk, struct sctp_chunk,
> - transmitted_list);
> + list_for_each_entry_safe(tchunk, temp, &q->sacked, transmitted_list) {
> tsn = ntohl(tchunk->subh.data_hdr->tsn);
> if (TSN_lte(tsn, ctsn)) {
> list_del_init(&tchunk->transmitted_list);
> @@ -1689,8 +1680,7 @@ static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
> int nskips = 0;
> int skip_pos = 0;
> __u32 tsn;
> - struct sctp_chunk *chunk;
> - struct list_head *lchunk, *temp;
> + struct sctp_chunk *chunk, *temp;
>
> if (!asoc->peer.prsctp_capable)
> return;
> @@ -1725,16 +1715,14 @@ static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
> * In this example, the data sender successfully advanced the
> * "Advanced.Peer.Ack.Point" from 102 to 104 locally.
> */
> - list_for_each_safe(lchunk, temp, &q->abandoned) {
> - chunk = list_entry(lchunk, struct sctp_chunk,
> - transmitted_list);
> + list_for_each_entry_safe(chunk, temp, &q->abandoned, transmitted_list) {
> tsn = ntohl(chunk->subh.data_hdr->tsn);
>
> /* Remove any chunks in the abandoned queue that are acked by
> * the ctsn.
> */
> if (TSN_lte(tsn, ctsn)) {
> - list_del_init(lchunk);
> + list_del_init(&chunk->transmitted_list);
> sctp_chunk_free(chunk);
> } else {
> if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) {
> diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
> index 010aced..bd41095 100644
> --- a/net/sctp/protocol.c
> +++ b/net/sctp/protocol.c
> @@ -166,13 +166,11 @@ static void sctp_v4_copy_addrlist(struct list_head *addrlist,
> static void sctp_get_local_addr_list(struct net *net)
> {
> struct net_device *dev;
> - struct list_head *pos;
> struct sctp_af *af;
>
> rcu_read_lock();
> for_each_netdev_rcu(net, dev) {
> - list_for_each(pos, &sctp_address_families) {
> - af = list_entry(pos, struct sctp_af, list);
> + list_for_each_entry(af, &sctp_address_families, list) {
> af->copy_addrlist(&net->sctp.local_addr_list, dev);
> }
> }
> @@ -182,12 +180,10 @@ static void sctp_get_local_addr_list(struct net *net)
> /* Free the existing local addresses. */
> static void sctp_free_local_addr_list(struct net *net)
> {
> - struct sctp_sockaddr_entry *addr;
> - struct list_head *pos, *temp;
> + struct sctp_sockaddr_entry *addr, *temp;
>
> - list_for_each_safe(pos, temp, &net->sctp.local_addr_list) {
> - addr = list_entry(pos, struct sctp_sockaddr_entry, list);
> - list_del(pos);
> + list_for_each_entry_safe(addr, temp, &net->sctp.local_addr_list, list) {
> + list_del(&addr->list);
> kfree(addr);
> }
> }
> diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
> index 763e06a..819bbc4 100644
> --- a/net/sctp/sm_make_chunk.c
> +++ b/net/sctp/sm_make_chunk.c
> @@ -2293,8 +2293,7 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
> {
> struct net *net = sock_net(asoc->base.sk);
> union sctp_params param;
> - struct sctp_transport *transport;
> - struct list_head *pos, *temp;
> + struct sctp_transport *transport, *temp;
> struct sctp_af *af;
> union sctp_addr addr;
> char *cookie;
> @@ -2358,8 +2357,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
> }
>
> /* Walk list of transports, removing transports in the UNKNOWN state. */
> - list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
> - transport = list_entry(pos, struct sctp_transport, transports);
> + list_for_each_entry_safe(transport, temp,
> + &asoc->peer.transport_addr_list, transports) {
> if (transport->state == SCTP_UNKNOWN) {
> sctp_assoc_rm_peer(asoc, transport);
> }
> @@ -2461,8 +2460,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
>
> clean_up:
> /* Release the transport structures. */
> - list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
> - transport = list_entry(pos, struct sctp_transport, transports);
> + list_for_each_entry_safe(transport, temp,
> + &asoc->peer.transport_addr_list, transports) {
> if (transport->state != SCTP_ACTIVE)
> sctp_assoc_rm_peer(asoc, transport);
> }
> diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
> index 05cd164..7521e56 100644
> --- a/net/sctp/sm_sideeffect.c
> +++ b/net/sctp/sm_sideeffect.c
> @@ -953,12 +953,10 @@ static void sctp_cmd_process_fwdtsn(struct sctp_ulpq *ulpq,
> */
> static void sctp_cmd_del_non_primary(struct sctp_association *asoc)
> {
> - struct sctp_transport *t;
> - struct list_head *pos;
> - struct list_head *temp;
> + struct sctp_transport *t, *temp;
>
> - list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
> - t = list_entry(pos, struct sctp_transport, transports);
> + list_for_each_entry_safe(t, temp, &asoc->peer.transport_addr_list,
> + transports) {
> if (!sctp_cmp_addr_exact(&t->ipaddr,
> &asoc->peer.primary_addr)) {
> sctp_assoc_rm_peer(asoc, t);
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 106bb09..9272e7b 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1474,8 +1474,7 @@ static void sctp_close(struct sock *sk, long timeout)
> {
> struct net *net = sock_net(sk);
> struct sctp_endpoint *ep;
> - struct sctp_association *asoc;
> - struct list_head *pos, *temp;
> + struct sctp_association *asoc, *temp;
> unsigned int data_was_unread;
>
> pr_debug("%s: sk:%p, timeout:%ld\n", __func__, sk, timeout);
> @@ -1491,9 +1490,7 @@ static void sctp_close(struct sock *sk, long timeout)
> data_was_unread += sctp_queue_purge_ulpevents(&sctp_sk(sk)->pd_lobby);
>
> /* Walk all associations on an endpoint. */
> - list_for_each_safe(pos, temp, &ep->asocs) {
> - asoc = list_entry(pos, struct sctp_association, asocs);
> -
> + list_for_each_entry_safe(asoc, temp, &ep->asocs, asocs) {
> if (sctp_style(sk, TCP)) {
> /* A closed association can still be in the list if
> * it belongs to a TCP-style listening socket that is
> --
> 2.5.0
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2015-12-18 16:59:24

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 03/14] ipv4, ipv6: use list_for_each_entry*

I don't think this code can work. list_for_each_entry uses answer to get
from one element to the next.

julia

On Sat, 19 Dec 2015, kbuild test robot wrote:

> CC: [email protected]
> In-Reply-To: <0167bba2ecf8c4fcb6b0b3135a4e957309986498.1450451516.git.geliangtang@163.com>
> TO: Geliang Tang <[email protected]>
> CC: "David S. Miller" <[email protected]>, Alexey Kuznetsov <[email protected]>, James Morris <[email protected]>, Hideaki YOSHIFUJI <[email protected]>, Patrick McHardy <[email protected]>
> CC: Geliang Tang <[email protected]>, [email protected], [email protected]
>
> Hi Geliang,
>
> [auto build test WARNING on net/master]
> [also build test WARNING on v4.4-rc5 next-20151218]
>
> url: https://github.com/0day-ci/linux/commits/Geliang-Tang/Bluetooth-use-list_for_each_entry/20151218-234306
> :::::: branch date: 69 minutes ago
> :::::: commit date: 69 minutes ago
>
> >> net/ipv6/af_inet6.c:589:1-20: iterator with update on line 597
>
> git remote add linux-review https://github.com/0day-ci/linux
> git remote update linux-review
> git checkout c5e8d791cacac62eeec48e00a1a14a6a350670f4
> vim +589 net/ipv6/af_inet6.c
>
> ^1da177e Linus Torvalds 2005-04-16 583 goto out_illegal;
> ^1da177e Linus Torvalds 2005-04-16 584
> ^1da177e Linus Torvalds 2005-04-16 585 /* If we are trying to override a permanent protocol, bail. */
> ^1da177e Linus Torvalds 2005-04-16 586 answer = NULL;
> 87c3efbf Daniel Lezcano 2007-12-11 587 ret = -EPERM;
> ^1da177e Linus Torvalds 2005-04-16 588 last_perm = &inetsw6[p->type];
> c5e8d791 Geliang Tang 2015-12-18 @589 list_for_each_entry(answer, &inetsw6[p->type], list) {
> ^1da177e Linus Torvalds 2005-04-16 590 /* Check only the non-wild match. */
> ^1da177e Linus Torvalds 2005-04-16 591 if (INET_PROTOSW_PERMANENT & answer->flags) {
> ^1da177e Linus Torvalds 2005-04-16 592 if (protocol == answer->protocol)
> ^1da177e Linus Torvalds 2005-04-16 593 break;
> c5e8d791 Geliang Tang 2015-12-18 594 last_perm = &answer->list;
> ^1da177e Linus Torvalds 2005-04-16 595 }
> ^1da177e Linus Torvalds 2005-04-16 596
> ^1da177e Linus Torvalds 2005-04-16 @597 answer = NULL;
> ^1da177e Linus Torvalds 2005-04-16 598 }
> ^1da177e Linus Torvalds 2005-04-16 599 if (answer)
> ^1da177e Linus Torvalds 2005-04-16 600 goto out_permanent;
>
> ---
> 0-DAY kernel test infrastructure Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all Intel Corporation
>

2015-12-19 14:46:10

by Geliang Tang

[permalink] [raw]
Subject: [PATCH 03/14 v2] ipv4, ipv6: use list_for_each_entry*

Use list_for_each_entry*() instead of list_for_each*() to simplify
the code.

Signed-off-by: Geliang Tang <[email protected]>
---
Changes in v2:
- bugfix for inet6_register_protosw in v1.
---
net/ipv4/af_inet.c | 11 ++++-------
net/ipv4/tcp_output.c | 6 ++----
net/ipv6/addrconf.c | 8 +++-----
net/ipv6/af_inet6.c | 19 +++++--------------
4 files changed, 14 insertions(+), 30 deletions(-)

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 11c4ca1..eedf814 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1028,10 +1028,8 @@ static struct inet_protosw inetsw_array[] =

void inet_register_protosw(struct inet_protosw *p)
{
- struct list_head *lh;
- struct inet_protosw *answer;
+ struct inet_protosw *answer, *last_perm;
int protocol = p->protocol;
- struct list_head *last_perm;

spin_lock_bh(&inetsw_lock);

@@ -1040,14 +1038,13 @@ void inet_register_protosw(struct inet_protosw *p)

/* If we are trying to override a permanent protocol, bail. */
last_perm = &inetsw[p->type];
- list_for_each(lh, &inetsw[p->type]) {
- answer = list_entry(lh, struct inet_protosw, list);
+ list_for_each_entry(answer, &inetsw[p->type], list) {
/* Check only the non-wild match. */
if ((INET_PROTOSW_PERMANENT & answer->flags) == 0)
break;
if (protocol == answer->protocol)
goto out_permanent;
- last_perm = lh;
+ last_perm = answer;
}

/* Add the new entry after the last permanent entry if any, so that
@@ -1056,7 +1053,7 @@ void inet_register_protosw(struct inet_protosw *p)
* non-permanent entry. This means that when we remove this entry, the
* system automatically returns to the old behavior.
*/
- list_add_rcu(&p->list, last_perm);
+ list_add_rcu(&p->list, &last_perm->list);
out:
spin_unlock_bh(&inetsw_lock);

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index a800cee..8810694 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -751,16 +751,14 @@ static void tcp_tasklet_func(unsigned long data)
struct tsq_tasklet *tsq = (struct tsq_tasklet *)data;
LIST_HEAD(list);
unsigned long flags;
- struct list_head *q, *n;
- struct tcp_sock *tp;
+ struct tcp_sock *tp, *n;
struct sock *sk;

local_irq_save(flags);
list_splice_init(&tsq->head, &list);
local_irq_restore(flags);

- list_for_each_safe(q, n, &list) {
- tp = list_entry(q, struct tcp_sock, tsq_node);
+ list_for_each_entry_safe(tp, n, &list, tsq_node) {
list_del(&tp->tsq_node);

sk = (struct sock *)tp;
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 7082fb7..e293647 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -865,21 +865,19 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
static void
ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp)
{
- struct list_head *p;
+ struct inet6_ifaddr *ifa;
int ifp_scope = ipv6_addr_src_scope(&ifp->addr);

/*
* Each device address list is sorted in order of scope -
* global before linklocal.
*/
- list_for_each(p, &idev->addr_list) {
- struct inet6_ifaddr *ifa
- = list_entry(p, struct inet6_ifaddr, if_list);
+ list_for_each_entry(ifa, &idev->addr_list, if_list) {
if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr))
break;
}

- list_add_tail(&ifp->if_list, p);
+ list_add_tail(&ifp->if_list, &ifa->if_list);
}

static u32 inet6_addr_hash(const struct in6_addr *addr)
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 8ec0df7..437a500 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -568,9 +568,7 @@ static const struct net_proto_family inet6_family_ops = {

int inet6_register_protosw(struct inet_protosw *p)
{
- struct list_head *lh;
- struct inet_protosw *answer;
- struct list_head *last_perm;
+ struct inet_protosw *answer, *last_perm;
int protocol = p->protocol;
int ret;

@@ -581,23 +579,16 @@ int inet6_register_protosw(struct inet_protosw *p)
goto out_illegal;

/* If we are trying to override a permanent protocol, bail. */
- answer = NULL;
ret = -EPERM;
last_perm = &inetsw6[p->type];
- list_for_each(lh, &inetsw6[p->type]) {
- answer = list_entry(lh, struct inet_protosw, list);
-
+ list_for_each_entry(answer, &inetsw6[p->type], list) {
/* Check only the non-wild match. */
if (INET_PROTOSW_PERMANENT & answer->flags) {
if (protocol == answer->protocol)
- break;
- last_perm = lh;
+ goto out_permanent;
+ last_perm = answer;
}
-
- answer = NULL;
}
- if (answer)
- goto out_permanent;

/* Add the new entry after the last permanent entry if any, so that
* the new entry does not override a permanent entry when matched with
@@ -605,7 +596,7 @@ int inet6_register_protosw(struct inet_protosw *p)
* non-permanent entry. This means that when we remove this entry, the
* system automatically returns to the old behavior.
*/
- list_add_rcu(&p->list, last_perm);
+ list_add_rcu(&p->list, &last_perm->list);
ret = 0;
out:
spin_unlock_bh(&inetsw6_lock);
--
2.5.0

2015-12-19 14:58:35

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 03/14 v2] ipv4, ipv6: use list_for_each_entry*



On Sat, 19 Dec 2015, Geliang Tang wrote:

> Use list_for_each_entry*() instead of list_for_each*() to simplify
> the code.

Is the code really simpler? At least in the case of net/ipv6/addrconf.c,
I have the impression that there can be an access from a pointer that is
not really pointing to the thing indicated by its type. The code seems to
work, but this doesn't seem like a good property for it to have. In these
cases, you need access to both the list and to the entry. The original
code seemed like a reasonable way to express that.

julia

> Signed-off-by: Geliang Tang <[email protected]>
> ---
> Changes in v2:
> - bugfix for inet6_register_protosw in v1.
> ---
> net/ipv4/af_inet.c | 11 ++++-------
> net/ipv4/tcp_output.c | 6 ++----
> net/ipv6/addrconf.c | 8 +++-----
> net/ipv6/af_inet6.c | 19 +++++--------------
> 4 files changed, 14 insertions(+), 30 deletions(-)
>
> diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
> index 11c4ca1..eedf814 100644
> --- a/net/ipv4/af_inet.c
> +++ b/net/ipv4/af_inet.c
> @@ -1028,10 +1028,8 @@ static struct inet_protosw inetsw_array[] =
>
> void inet_register_protosw(struct inet_protosw *p)
> {
> - struct list_head *lh;
> - struct inet_protosw *answer;
> + struct inet_protosw *answer, *last_perm;
> int protocol = p->protocol;
> - struct list_head *last_perm;
>
> spin_lock_bh(&inetsw_lock);
>
> @@ -1040,14 +1038,13 @@ void inet_register_protosw(struct inet_protosw *p)
>
> /* If we are trying to override a permanent protocol, bail. */
> last_perm = &inetsw[p->type];
> - list_for_each(lh, &inetsw[p->type]) {
> - answer = list_entry(lh, struct inet_protosw, list);
> + list_for_each_entry(answer, &inetsw[p->type], list) {
> /* Check only the non-wild match. */
> if ((INET_PROTOSW_PERMANENT & answer->flags) == 0)
> break;
> if (protocol == answer->protocol)
> goto out_permanent;
> - last_perm = lh;
> + last_perm = answer;
> }
>
> /* Add the new entry after the last permanent entry if any, so that
> @@ -1056,7 +1053,7 @@ void inet_register_protosw(struct inet_protosw *p)
> * non-permanent entry. This means that when we remove this entry, the
> * system automatically returns to the old behavior.
> */
> - list_add_rcu(&p->list, last_perm);
> + list_add_rcu(&p->list, &last_perm->list);
> out:
> spin_unlock_bh(&inetsw_lock);
>
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index a800cee..8810694 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -751,16 +751,14 @@ static void tcp_tasklet_func(unsigned long data)
> struct tsq_tasklet *tsq = (struct tsq_tasklet *)data;
> LIST_HEAD(list);
> unsigned long flags;
> - struct list_head *q, *n;
> - struct tcp_sock *tp;
> + struct tcp_sock *tp, *n;
> struct sock *sk;
>
> local_irq_save(flags);
> list_splice_init(&tsq->head, &list);
> local_irq_restore(flags);
>
> - list_for_each_safe(q, n, &list) {
> - tp = list_entry(q, struct tcp_sock, tsq_node);
> + list_for_each_entry_safe(tp, n, &list, tsq_node) {
> list_del(&tp->tsq_node);
>
> sk = (struct sock *)tp;
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index 7082fb7..e293647 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -865,21 +865,19 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
> static void
> ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp)
> {
> - struct list_head *p;
> + struct inet6_ifaddr *ifa;
> int ifp_scope = ipv6_addr_src_scope(&ifp->addr);
>
> /*
> * Each device address list is sorted in order of scope -
> * global before linklocal.
> */
> - list_for_each(p, &idev->addr_list) {
> - struct inet6_ifaddr *ifa
> - = list_entry(p, struct inet6_ifaddr, if_list);
> + list_for_each_entry(ifa, &idev->addr_list, if_list) {
> if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr))
> break;
> }
>
> - list_add_tail(&ifp->if_list, p);
> + list_add_tail(&ifp->if_list, &ifa->if_list);
> }
>
> static u32 inet6_addr_hash(const struct in6_addr *addr)
> diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
> index 8ec0df7..437a500 100644
> --- a/net/ipv6/af_inet6.c
> +++ b/net/ipv6/af_inet6.c
> @@ -568,9 +568,7 @@ static const struct net_proto_family inet6_family_ops = {
>
> int inet6_register_protosw(struct inet_protosw *p)
> {
> - struct list_head *lh;
> - struct inet_protosw *answer;
> - struct list_head *last_perm;
> + struct inet_protosw *answer, *last_perm;
> int protocol = p->protocol;
> int ret;
>
> @@ -581,23 +579,16 @@ int inet6_register_protosw(struct inet_protosw *p)
> goto out_illegal;
>
> /* If we are trying to override a permanent protocol, bail. */
> - answer = NULL;
> ret = -EPERM;
> last_perm = &inetsw6[p->type];
> - list_for_each(lh, &inetsw6[p->type]) {
> - answer = list_entry(lh, struct inet_protosw, list);
> -
> + list_for_each_entry(answer, &inetsw6[p->type], list) {
> /* Check only the non-wild match. */
> if (INET_PROTOSW_PERMANENT & answer->flags) {
> if (protocol == answer->protocol)
> - break;
> - last_perm = lh;
> + goto out_permanent;
> + last_perm = answer;
> }
> -
> - answer = NULL;
> }
> - if (answer)
> - goto out_permanent;
>
> /* Add the new entry after the last permanent entry if any, so that
> * the new entry does not override a permanent entry when matched with
> @@ -605,7 +596,7 @@ int inet6_register_protosw(struct inet_protosw *p)
> * non-permanent entry. This means that when we remove this entry, the
> * system automatically returns to the old behavior.
> */
> - list_add_rcu(&p->list, last_perm);
> + list_add_rcu(&p->list, &last_perm->list);
> ret = 0;
> out:
> spin_unlock_bh(&inetsw6_lock);
> --
> 2.5.0
>
>
>

2015-12-20 07:13:16

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 01/14] Bluetooth: use list_for_each_entry*

Hi Geliang,

> Use list_for_each_entry*() instead of list_for_each*() to simplify
> the code.
>
> Signed-off-by: Geliang Tang <[email protected]>
> ---
> net/bluetooth/af_bluetooth.c | 12 ++++++------
> net/bluetooth/cmtp/capi.c | 8 ++------
> net/bluetooth/hci_core.c | 8 +++-----
> net/bluetooth/rfcomm/core.c | 46 ++++++++++++++------------------------------
> 4 files changed, 25 insertions(+), 49 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

2015-12-21 15:05:32

by Antonio Quartulli

[permalink] [raw]
Subject: Re: [PATCH 07/14] batman-adv: use list_for_each_entry_safe

Hi Geliang,

> static int batadv_socket_release(struct inode *inode, struct file *file)
> {
> - struct batadv_socket_client *socket_client = file->private_data;
> - struct batadv_socket_packet *socket_packet;
> - struct list_head *list_pos, *list_pos_tmp;
> + struct batadv_socket_client *client = file->private_data;
> + struct batadv_socket_packet *packet, *tmp;
>

[...]


> + list_for_each_entry_safe(packet, tmp, &client->queue_list, list) {

I guess you renamed those variables to make sure that the statement
above would fit in 80 chars.. in that case the patch looks good.


Acked-by: Antonio Quartulli <[email protected]>


--
Antonio Quartulli


Attachments:
signature.asc (819.00 B)
OpenPGP digital signature

2016-03-28 15:37:20

by Marek Lindner

[permalink] [raw]
Subject: Re: [B.A.T.M.A.N.] [PATCH 07/14] batman-adv: use list_for_each_entry_safe

On Friday, December 18, 2015 23:33:31 Geliang Tang wrote:
> Use list_for_each_entry_safe() instead of list_for_each_safe() to
> simplify the code.
>
> Signed-off-by: Geliang Tang <[email protected]>
> ---
> net/batman-adv/icmp_socket.c | 22 +++++++++-------------
> 1 file changed, 9 insertions(+), 13 deletions(-)

Applied in the batman tree (revision 1557404).

Thanks,
Marek


Attachments:
signature.asc (473.00 B)
This is a digitally signed message part.