Commit 1fdb8d8f authored by Marcelo Ricardo Leitner's avatar Marcelo Ricardo Leitner Committed by David S. Miller

sctp: factor out stream->in allocation

There is 1 place allocating it and another reallocating. Move such
procedures to a common function.

v2: updated changelog
Tested-by: default avatarXin Long <lucien.xin@gmail.com>
Signed-off-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e090abd0
...@@ -59,6 +59,31 @@ static int sctp_stream_alloc_out(struct sctp_stream *stream, __u16 outcnt, ...@@ -59,6 +59,31 @@ static int sctp_stream_alloc_out(struct sctp_stream *stream, __u16 outcnt,
return 0; return 0;
} }
static int sctp_stream_alloc_in(struct sctp_stream *stream, __u16 incnt,
gfp_t gfp)
{
struct sctp_stream_in *in;
in = kmalloc_array(incnt, sizeof(*stream->in), gfp);
if (!in)
return -ENOMEM;
if (stream->in) {
memcpy(in, stream->in, min(incnt, stream->incnt) *
sizeof(*in));
kfree(stream->in);
}
if (incnt > stream->incnt)
memset(in + stream->incnt, 0,
(incnt - stream->incnt) * sizeof(*in));
stream->in = in;
return 0;
}
int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt, int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
gfp_t gfp) gfp_t gfp)
{ {
...@@ -84,8 +109,8 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt, ...@@ -84,8 +109,8 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
if (!incnt) if (!incnt)
return 0; return 0;
stream->in = kcalloc(incnt, sizeof(*stream->in), gfp); i = sctp_stream_alloc_in(stream, incnt, gfp);
if (!stream->in) { if (i) {
kfree(stream->out); kfree(stream->out);
stream->out = NULL; stream->out = NULL;
return -ENOMEM; return -ENOMEM;
...@@ -623,7 +648,6 @@ struct sctp_chunk *sctp_process_strreset_addstrm_out( ...@@ -623,7 +648,6 @@ struct sctp_chunk *sctp_process_strreset_addstrm_out(
struct sctp_strreset_addstrm *addstrm = param.v; struct sctp_strreset_addstrm *addstrm = param.v;
struct sctp_stream *stream = &asoc->stream; struct sctp_stream *stream = &asoc->stream;
__u32 result = SCTP_STRRESET_DENIED; __u32 result = SCTP_STRRESET_DENIED;
struct sctp_stream_in *streamin;
__u32 request_seq, incnt; __u32 request_seq, incnt;
__u16 in, i; __u16 in, i;
...@@ -670,13 +694,9 @@ struct sctp_chunk *sctp_process_strreset_addstrm_out( ...@@ -670,13 +694,9 @@ struct sctp_chunk *sctp_process_strreset_addstrm_out(
if (!in || incnt > SCTP_MAX_STREAM) if (!in || incnt > SCTP_MAX_STREAM)
goto out; goto out;
streamin = krealloc(stream->in, incnt * sizeof(*streamin), if (sctp_stream_alloc_in(stream, incnt, GFP_ATOMIC))
GFP_ATOMIC);
if (!streamin)
goto out; goto out;
memset(streamin + stream->incnt, 0, in * sizeof(*streamin));
stream->in = streamin;
stream->incnt = incnt; stream->incnt = incnt;
result = SCTP_STRRESET_PERFORMED; result = SCTP_STRRESET_PERFORMED;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment