]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
sctp: shrink stream outq only when new outcnt < old outcnt
authorXin Long <lucien.xin@gmail.com>
Wed, 22 Jul 2020 15:52:11 +0000 (23:52 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 31 Jul 2020 16:39:31 +0000 (18:39 +0200)
[ Upstream commit 8f13399db22f909a35735bf8ae2f932e0c8f0e30 ]

It's not necessary to go list_for_each for outq->out_chunk_list
when new outcnt >= old outcnt, as no chunk with higher sid than
new (outcnt - 1) exists in the outqueue.

While at it, also move the list_for_each code in a new function
sctp_stream_shrink_out(), which will be used in the next patch.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/sctp/stream.c

index c1a100d2fed39c2d831487e05fcbf5e8d507d470..9caa0f6e31bd3cd95c82edffb83680fccfd7122c 100644 (file)
 #include <net/sctp/sm.h>
 #include <net/sctp/stream_sched.h>
 
-/* Migrates chunks from stream queues to new stream queues if needed,
- * but not across associations. Also, removes those chunks to streams
- * higher than the new max.
- */
-static void sctp_stream_outq_migrate(struct sctp_stream *stream,
-                                    struct sctp_stream *new, __u16 outcnt)
+static void sctp_stream_shrink_out(struct sctp_stream *stream, __u16 outcnt)
 {
        struct sctp_association *asoc;
        struct sctp_chunk *ch, *temp;
        struct sctp_outq *outq;
-       int i;
 
        asoc = container_of(stream, struct sctp_association, stream);
        outq = &asoc->outqueue;
@@ -56,6 +50,19 @@ static void sctp_stream_outq_migrate(struct sctp_stream *stream,
 
                sctp_chunk_free(ch);
        }
+}
+
+/* Migrates chunks from stream queues to new stream queues if needed,
+ * but not across associations. Also, removes those chunks to streams
+ * higher than the new max.
+ */
+static void sctp_stream_outq_migrate(struct sctp_stream *stream,
+                                    struct sctp_stream *new, __u16 outcnt)
+{
+       int i;
+
+       if (stream->outcnt > outcnt)
+               sctp_stream_shrink_out(stream, outcnt);
 
        if (new) {
                /* Here we actually move the old ext stuff into the new