Commit 53fa1036 authored by Xin Long's avatar Xin Long Committed by David S. Miller

sctp: fix some rhashtable functions using in sctp proc/diag

When rhashtable_walk_init return err, no release function should be
called, and when rhashtable_walk_start return err, we should only invoke
rhashtable_walk_exit to release the source.

But now when sctp_transport_walk_start return err, we just call
rhashtable_walk_stop/exit, and never care about if rhashtable_walk_init
or start return err, which is so bad.

We will fix it by calling rhashtable_walk_exit if rhashtable_walk_start
return err in sctp_transport_walk_start, and if sctp_transport_walk_start
return err, we do not need to call sctp_transport_walk_stop any more.

For sctp proc, we will use 'iter->start_fail' to decide if we will call
rhashtable_walk_stop/exit.
Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b5e2f4e6
...@@ -280,6 +280,7 @@ void sctp_eps_proc_exit(struct net *net) ...@@ -280,6 +280,7 @@ void sctp_eps_proc_exit(struct net *net)
struct sctp_ht_iter { struct sctp_ht_iter {
struct seq_net_private p; struct seq_net_private p;
struct rhashtable_iter hti; struct rhashtable_iter hti;
int start_fail;
}; };
static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos) static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos)
...@@ -287,8 +288,10 @@ static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos) ...@@ -287,8 +288,10 @@ static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos)
struct sctp_ht_iter *iter = seq->private; struct sctp_ht_iter *iter = seq->private;
int err = sctp_transport_walk_start(&iter->hti); int err = sctp_transport_walk_start(&iter->hti);
if (err) if (err) {
iter->start_fail = 1;
return ERR_PTR(err); return ERR_PTR(err);
}
return sctp_transport_get_idx(seq_file_net(seq), &iter->hti, *pos); return sctp_transport_get_idx(seq_file_net(seq), &iter->hti, *pos);
} }
...@@ -297,6 +300,8 @@ static void sctp_transport_seq_stop(struct seq_file *seq, void *v) ...@@ -297,6 +300,8 @@ static void sctp_transport_seq_stop(struct seq_file *seq, void *v)
{ {
struct sctp_ht_iter *iter = seq->private; struct sctp_ht_iter *iter = seq->private;
if (iter->start_fail)
return;
sctp_transport_walk_stop(&iter->hti); sctp_transport_walk_stop(&iter->hti);
} }
......
...@@ -4299,8 +4299,12 @@ int sctp_transport_walk_start(struct rhashtable_iter *iter) ...@@ -4299,8 +4299,12 @@ int sctp_transport_walk_start(struct rhashtable_iter *iter)
return err; return err;
err = rhashtable_walk_start(iter); err = rhashtable_walk_start(iter);
if (err && err != -EAGAIN) {
rhashtable_walk_exit(iter);
return err;
}
return err == -EAGAIN ? 0 : err; return 0;
} }
void sctp_transport_walk_stop(struct rhashtable_iter *iter) void sctp_transport_walk_stop(struct rhashtable_iter *iter)
...@@ -4389,11 +4393,12 @@ EXPORT_SYMBOL_GPL(sctp_transport_lookup_process); ...@@ -4389,11 +4393,12 @@ EXPORT_SYMBOL_GPL(sctp_transport_lookup_process);
int sctp_for_each_transport(int (*cb)(struct sctp_transport *, void *), int sctp_for_each_transport(int (*cb)(struct sctp_transport *, void *),
struct net *net, int pos, void *p) { struct net *net, int pos, void *p) {
struct rhashtable_iter hti; struct rhashtable_iter hti;
int err = 0;
void *obj; void *obj;
int err;
if (sctp_transport_walk_start(&hti)) err = sctp_transport_walk_start(&hti);
goto out; if (err)
return err;
sctp_transport_get_idx(net, &hti, pos); sctp_transport_get_idx(net, &hti, pos);
obj = sctp_transport_get_next(net, &hti); obj = sctp_transport_get_next(net, &hti);
...@@ -4407,8 +4412,8 @@ int sctp_for_each_transport(int (*cb)(struct sctp_transport *, void *), ...@@ -4407,8 +4412,8 @@ int sctp_for_each_transport(int (*cb)(struct sctp_transport *, void *),
if (err) if (err)
break; break;
} }
out:
sctp_transport_walk_stop(&hti); sctp_transport_walk_stop(&hti);
return err; return err;
} }
EXPORT_SYMBOL_GPL(sctp_for_each_transport); EXPORT_SYMBOL_GPL(sctp_for_each_transport);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment