Skip to content

Commit

Permalink
sctp: silence warns on sctp_stream_init allocations
Browse files Browse the repository at this point in the history
As SCTP supports up to 65535 streams, that can lead to very large
allocations in sctp_stream_init(). As Xin Long noticed, systems with
small amounts of memory are more prone to not have enough memory and
dump warnings on dmesg initiated by user actions. Thus, silence them.

Also, if the reallocation of stream->out is not necessary, skip it and
keep the memory we already have.

Reported-by: Xin Long <lucien.xin@gmail.com>
Tested-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Marcelo Ricardo Leitner authored and David S. Miller committed Oct 3, 2017
1 parent af14827 commit 1ae2eaa
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion net/sctp/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
{
int i;

gfp |= __GFP_NOWARN;

/* Initial stream->out size may be very big, so free it and alloc
* a new one with new outcnt to save memory.
* a new one with new outcnt to save memory if needed.
*/
if (outcnt == stream->outcnt)
goto in;

kfree(stream->out);

stream->out = kcalloc(outcnt, sizeof(*stream->out), gfp);
Expand All @@ -53,6 +58,7 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
for (i = 0; i < stream->outcnt; i++)
stream->out[i].state = SCTP_STREAM_OPEN;

in:
if (!incnt)
return 0;

Expand Down

0 comments on commit 1ae2eaa

Please sign in to comment.