From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> To: netdev@vger.kernel.org Cc: linux-sctp@vger.kernel.org, Neil Horman <nhorman@tuxdriver.com>, Vlad Yasevich <vyasevich@gmail.com>, Xin Long <lucien.xin@gmail.com>, David Laight <David.Laight@ACULAB.COM> Subject: [PATCH net-next 03/10] sctp: factor out stream->in allocation Date: Thu, 28 Sep 2017 17:25:16 -0300 [thread overview] Message-ID: <a2d837095740147003164fe573794c140001ec71.1506536044.git.marcelo.leitner@gmail.com> (raw) In-Reply-To: <cover.1506536044.git.marcelo.leitner@gmail.com> Same idea as previous patch. Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> --- net/sctp/stream.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/net/sctp/stream.c b/net/sctp/stream.c index 6d0e997d301f89e165367106c02e82f8a6c3a877..952437d656cc71ad1c133a736c539eff9a8d80c2 100644 --- a/net/sctp/stream.c +++ b/net/sctp/stream.c @@ -59,6 +59,31 @@ static int sctp_stream_alloc_out(struct sctp_stream *stream, __u16 outcnt, 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, gfp_t gfp) { @@ -84,8 +109,8 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt, if (!incnt) return 0; - stream->in = kcalloc(incnt, sizeof(*stream->in), gfp); - if (!stream->in) { + i = sctp_stream_alloc_in(stream, incnt, gfp); + if (i) { kfree(stream->out); stream->out = NULL; return -ENOMEM; @@ -623,7 +648,6 @@ struct sctp_chunk *sctp_process_strreset_addstrm_out( struct sctp_strreset_addstrm *addstrm = param.v; struct sctp_stream *stream = &asoc->stream; __u32 result = SCTP_STRRESET_DENIED; - struct sctp_stream_in *streamin; __u32 request_seq, incnt; __u16 in, i; @@ -670,13 +694,9 @@ struct sctp_chunk *sctp_process_strreset_addstrm_out( if (!in || incnt > SCTP_MAX_STREAM) goto out; - streamin = krealloc(stream->in, incnt * sizeof(*streamin), - GFP_ATOMIC); - if (!streamin) + if (sctp_stream_alloc_in(stream, incnt, GFP_ATOMIC)) goto out; - memset(streamin + stream->incnt, 0, in * sizeof(*streamin)); - stream->in = streamin; stream->incnt = incnt; result = SCTP_STRRESET_PERFORMED; -- 2.13.5
WARNING: multiple messages have this Message-ID (diff)
From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> To: netdev@vger.kernel.org Cc: linux-sctp@vger.kernel.org, Neil Horman <nhorman@tuxdriver.com>, Vlad Yasevich <vyasevich@gmail.com>, Xin Long <lucien.xin@gmail.com>, David Laight <David.Laight@ACULAB.COM> Subject: [PATCH net-next 03/10] sctp: factor out stream->in allocation Date: Thu, 28 Sep 2017 20:25:16 +0000 [thread overview] Message-ID: <a2d837095740147003164fe573794c140001ec71.1506536044.git.marcelo.leitner@gmail.com> (raw) In-Reply-To: <cover.1506536044.git.marcelo.leitner@gmail.com> Same idea as previous patch. Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> --- net/sctp/stream.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/net/sctp/stream.c b/net/sctp/stream.c index 6d0e997d301f89e165367106c02e82f8a6c3a877..952437d656cc71ad1c133a736c539eff9a8d80c2 100644 --- a/net/sctp/stream.c +++ b/net/sctp/stream.c @@ -59,6 +59,31 @@ static int sctp_stream_alloc_out(struct sctp_stream *stream, __u16 outcnt, 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, gfp_t gfp) { @@ -84,8 +109,8 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt, if (!incnt) return 0; - stream->in = kcalloc(incnt, sizeof(*stream->in), gfp); - if (!stream->in) { + i = sctp_stream_alloc_in(stream, incnt, gfp); + if (i) { kfree(stream->out); stream->out = NULL; return -ENOMEM; @@ -623,7 +648,6 @@ struct sctp_chunk *sctp_process_strreset_addstrm_out( struct sctp_strreset_addstrm *addstrm = param.v; struct sctp_stream *stream = &asoc->stream; __u32 result = SCTP_STRRESET_DENIED; - struct sctp_stream_in *streamin; __u32 request_seq, incnt; __u16 in, i; @@ -670,13 +694,9 @@ struct sctp_chunk *sctp_process_strreset_addstrm_out( if (!in || incnt > SCTP_MAX_STREAM) goto out; - streamin = krealloc(stream->in, incnt * sizeof(*streamin), - GFP_ATOMIC); - if (!streamin) + if (sctp_stream_alloc_in(stream, incnt, GFP_ATOMIC)) goto out; - memset(streamin + stream->incnt, 0, in * sizeof(*streamin)); - stream->in = streamin; stream->incnt = incnt; result = SCTP_STRRESET_PERFORMED; -- 2.13.5
next prev parent reply other threads:[~2017-09-28 20:25 UTC|newest] Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-09-28 20:25 [PATCH net-next 00/10] Introduce SCTP Stream Schedulers Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner 2017-09-28 20:25 ` [PATCH net-next 01/10] sctp: silence warns on sctp_stream_init allocations Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner 2017-09-28 20:25 ` [PATCH net-next 02/10] sctp: factor out stream->out allocation Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner [this message] 2017-09-28 20:25 ` [PATCH net-next 03/10] sctp: factor out stream->in allocation Marcelo Ricardo Leitner 2017-09-29 10:04 ` David Laight 2017-09-29 13:05 ` 'Marcelo Ricardo Leitner' 2017-09-29 13:05 ` 'Marcelo Ricardo Leitner' 2017-09-28 20:25 ` [PATCH net-next 04/10] sctp: introduce struct sctp_stream_out_ext Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner 2017-09-28 20:25 ` [PATCH net-next 05/10] sctp: introduce sctp_chunk_stream_no Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner 2017-09-28 20:25 ` [PATCH net-next 06/10] sctp: introduce stream scheduler foundations Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner 2017-09-28 20:25 ` [PATCH net-next 07/10] sctp: add sockopt to get/set stream scheduler Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner 2017-09-29 16:47 ` Neil Horman 2017-09-29 16:47 ` Neil Horman 2017-09-29 17:14 ` Marcelo Ricardo Leitner 2017-09-29 17:14 ` Marcelo Ricardo Leitner 2017-09-28 20:25 ` [PATCH net-next 08/10] sctp: add sockopt to get/set stream scheduler parameters Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner 2017-09-28 20:25 ` [PATCH net-next 09/10] sctp: introduce priority based stream scheduler Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner 2017-09-29 16:54 ` Neil Horman 2017-09-29 16:54 ` Neil Horman 2017-09-29 17:10 ` Marcelo Ricardo Leitner 2017-09-29 17:10 ` Marcelo Ricardo Leitner 2017-09-28 20:25 ` [PATCH net-next 10/10] sctp: introduce round robin " Marcelo Ricardo Leitner 2017-09-28 20:25 ` Marcelo Ricardo Leitner 2017-09-30 16:52 ` [PATCH net-next 00/10] Introduce SCTP Stream Schedulers Xin Long 2017-09-30 16:52 ` Xin Long
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=a2d837095740147003164fe573794c140001ec71.1506536044.git.marcelo.leitner@gmail.com \ --to=marcelo.leitner@gmail.com \ --cc=David.Laight@ACULAB.COM \ --cc=linux-sctp@vger.kernel.org \ --cc=lucien.xin@gmail.com \ --cc=netdev@vger.kernel.org \ --cc=nhorman@tuxdriver.com \ --cc=vyasevich@gmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.