Skip to content

Commit 1ae2eaa

Browse files
marceloleitnerdavem330
authored andcommitted
sctp: silence warns on sctp_stream_init allocations
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 <[email protected]> Tested-by: Xin Long <[email protected]> Signed-off-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent af14827 commit 1ae2eaa

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

net/sctp/stream.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
4040
{
4141
int i;
4242

43+
gfp |= __GFP_NOWARN;
44+
4345
/* Initial stream->out size may be very big, so free it and alloc
44-
* a new one with new outcnt to save memory.
46+
* a new one with new outcnt to save memory if needed.
4547
*/
48+
if (outcnt == stream->outcnt)
49+
goto in;
50+
4651
kfree(stream->out);
4752

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

61+
in:
5662
if (!incnt)
5763
return 0;
5864

0 commit comments

Comments
 (0)