diff options
author | Xin Long <lucien.xin@gmail.com> | 2017-05-31 04:36:32 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-06-02 13:56:26 -0400 |
commit | ff356414dc006170153c79434eb81d130c03beec (patch) | |
tree | 55ec0eab1ade81782ef50358fb2ae2739c57251f /net/sctp/stream.c | |
parent | cee360ab4dd66fc1de33a5fa1cb418fa21c27ce3 (diff) |
sctp: merge sctp_stream_new and sctp_stream_init
Since last patch, sctp doesn't need to alloc memory for asoc->stream any
more. sctp_stream_new and sctp_stream_init both are used to alloc memory
for stream.in or stream.out, and their names are also confusing.
This patch is to merge them into sctp_stream_init, and only pass stream
and streamcnt parameters into it, instead of the whole asoc.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sctp/stream.c')
-rw-r--r-- | net/sctp/stream.c | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/net/sctp/stream.c b/net/sctp/stream.c index af6b49850344..82e6d40052a8 100644 --- a/net/sctp/stream.c +++ b/net/sctp/stream.c | |||
@@ -35,47 +35,36 @@ | |||
35 | #include <net/sctp/sctp.h> | 35 | #include <net/sctp/sctp.h> |
36 | #include <net/sctp/sm.h> | 36 | #include <net/sctp/sm.h> |
37 | 37 | ||
38 | int sctp_stream_new(struct sctp_association *asoc, gfp_t gfp) | 38 | int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt, |
39 | gfp_t gfp) | ||
39 | { | 40 | { |
40 | struct sctp_stream *stream = &asoc->stream; | ||
41 | int i; | ||
42 | |||
43 | stream->outcnt = asoc->c.sinit_num_ostreams; | ||
44 | stream->out = kcalloc(stream->outcnt, sizeof(*stream->out), gfp); | ||
45 | if (!stream->out) | ||
46 | return -ENOMEM; | ||
47 | |||
48 | for (i = 0; i < stream->outcnt; i++) | ||
49 | stream->out[i].state = SCTP_STREAM_OPEN; | ||
50 | |||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | int sctp_stream_init(struct sctp_association *asoc, gfp_t gfp) | ||
55 | { | ||
56 | struct sctp_stream *stream = &asoc->stream; | ||
57 | int i; | 41 | int i; |
58 | 42 | ||
59 | /* Initial stream->out size may be very big, so free it and alloc | 43 | /* Initial stream->out size may be very big, so free it and alloc |
60 | * a new one with new outcnt to save memory. | 44 | * a new one with new outcnt to save memory. |
61 | */ | 45 | */ |
62 | kfree(stream->out); | 46 | kfree(stream->out); |
63 | stream->outcnt = asoc->c.sinit_num_ostreams; | 47 | |
64 | stream->out = kcalloc(stream->outcnt, sizeof(*stream->out), gfp); | 48 | stream->out = kcalloc(outcnt, sizeof(*stream->out), gfp); |
65 | if (!stream->out) | 49 | if (!stream->out) |
66 | return -ENOMEM; | 50 | return -ENOMEM; |
67 | 51 | ||
52 | stream->outcnt = outcnt; | ||
68 | for (i = 0; i < stream->outcnt; i++) | 53 | for (i = 0; i < stream->outcnt; i++) |
69 | stream->out[i].state = SCTP_STREAM_OPEN; | 54 | stream->out[i].state = SCTP_STREAM_OPEN; |
70 | 55 | ||
71 | stream->incnt = asoc->c.sinit_max_instreams; | 56 | if (!incnt) |
72 | stream->in = kcalloc(stream->incnt, sizeof(*stream->in), gfp); | 57 | return 0; |
58 | |||
59 | stream->in = kcalloc(incnt, sizeof(*stream->in), gfp); | ||
73 | if (!stream->in) { | 60 | if (!stream->in) { |
74 | kfree(stream->out); | 61 | kfree(stream->out); |
75 | stream->out = NULL; | 62 | stream->out = NULL; |
76 | return -ENOMEM; | 63 | return -ENOMEM; |
77 | } | 64 | } |
78 | 65 | ||
66 | stream->incnt = incnt; | ||
67 | |||
79 | return 0; | 68 | return 0; |
80 | } | 69 | } |
81 | 70 | ||