]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
sctp: merge sctp_stream_new and sctp_stream_init
authorXin Long <lucien.xin@gmail.com>
Wed, 31 May 2017 08:36:32 +0000 (16:36 +0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 2 Jun 2017 17:56:26 +0000 (13:56 -0400)
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>
include/net/sctp/structs.h
net/sctp/associola.c
net/sctp/sm_make_chunk.c
net/sctp/stream.c

index c8dbf410c4f5863e654a291a81db7075bf4c8571..5051317162dff09b1922d73680acea6c323bfc64 100644 (file)
@@ -377,8 +377,8 @@ typedef struct sctp_sender_hb_info {
        __u64 hb_nonce;
 } sctp_sender_hb_info_t;
 
-int sctp_stream_new(struct sctp_association *asoc, gfp_t gfp);
-int sctp_stream_init(struct sctp_association *asoc, gfp_t gfp);
+int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
+                    gfp_t gfp);
 void sctp_stream_free(struct sctp_stream *stream);
 void sctp_stream_clear(struct sctp_stream *stream);
 void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new);
index 6625b15ab81ac3f11455006678d818d180a6acb7..288c5e0cda5d1f89fffe40279ae8a1610acd56b8 100644 (file)
@@ -246,7 +246,8 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
        if (!sctp_ulpq_init(&asoc->ulpq, asoc))
                goto fail_init;
 
-       if (sctp_stream_new(asoc, gfp))
+       if (sctp_stream_init(&asoc->stream, asoc->c.sinit_num_ostreams,
+                            0, gfp))
                goto fail_init;
 
        /* Assume that peer would support both address types unless we are
index 244181413bcad88c98f6360d817abe64056f6af7..bd439edf2d8ab6486438e5c405cd1d9038f3a713 100644 (file)
@@ -2454,7 +2454,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
         * stream sequence number shall be set to 0.
         */
 
-       if (sctp_stream_init(asoc, gfp))
+       if (sctp_stream_init(&asoc->stream, asoc->c.sinit_num_ostreams,
+                            asoc->c.sinit_max_instreams, gfp))
                goto clean_up;
 
        if (!asoc->temp && sctp_assoc_set_id(asoc, gfp))
index af6b49850344da04ad5ca7c5b42c48409a1fda0c..82e6d40052a8dd9ad2049ec506d132ab1305a64f 100644 (file)
 #include <net/sctp/sctp.h>
 #include <net/sctp/sm.h>
 
-int sctp_stream_new(struct sctp_association *asoc, gfp_t gfp)
+int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
+                    gfp_t gfp)
 {
-       struct sctp_stream *stream = &asoc->stream;
-       int i;
-
-       stream->outcnt = asoc->c.sinit_num_ostreams;
-       stream->out = kcalloc(stream->outcnt, sizeof(*stream->out), gfp);
-       if (!stream->out)
-               return -ENOMEM;
-
-       for (i = 0; i < stream->outcnt; i++)
-               stream->out[i].state = SCTP_STREAM_OPEN;
-
-       return 0;
-}
-
-int sctp_stream_init(struct sctp_association *asoc, gfp_t gfp)
-{
-       struct sctp_stream *stream = &asoc->stream;
        int i;
 
        /* Initial stream->out size may be very big, so free it and alloc
         * a new one with new outcnt to save memory.
         */
        kfree(stream->out);
-       stream->outcnt = asoc->c.sinit_num_ostreams;
-       stream->out = kcalloc(stream->outcnt, sizeof(*stream->out), gfp);
+
+       stream->out = kcalloc(outcnt, sizeof(*stream->out), gfp);
        if (!stream->out)
                return -ENOMEM;
 
+       stream->outcnt = outcnt;
        for (i = 0; i < stream->outcnt; i++)
                stream->out[i].state = SCTP_STREAM_OPEN;
 
-       stream->incnt = asoc->c.sinit_max_instreams;
-       stream->in = kcalloc(stream->incnt, sizeof(*stream->in), gfp);
+       if (!incnt)
+               return 0;
+
+       stream->in = kcalloc(incnt, sizeof(*stream->in), gfp);
        if (!stream->in) {
                kfree(stream->out);
                stream->out = NULL;
                return -ENOMEM;
        }
 
+       stream->incnt = incnt;
+
        return 0;
 }