mbox series

[net-next,0/2] sctp: unify sctp_make_op_error_fixed and sctp_make_op_error_space

Message ID cover.1525017179.git.marcelo.leitner@gmail.com
Headers show
Series sctp: unify sctp_make_op_error_fixed and sctp_make_op_error_space | expand

Message

Marcelo Ricardo Leitner April 29, 2018, 3:56 p.m. UTC
These two variants are very close to each other and can be merged
to avoid code duplication. That's what this patchset does.

First, we allow sctp_init_cause to return errors, which then allow us to
add sctp_make_op_error_limited that handles both situations.

Marcelo Ricardo Leitner (2):
  sctp: allow sctp_init_cause to return errors
  sctp: add sctp_make_op_error_limited and reuse inner functions

 include/net/sctp/sm.h    |   2 +-
 net/sctp/sm_make_chunk.c | 134 ++++++++++++++++++-----------------------------
 2 files changed, 52 insertions(+), 84 deletions(-)

--
2.14.3

Comments

David Miller May 1, 2018, 4:13 p.m. UTC | #1
From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Date: Sun, 29 Apr 2018 12:56:30 -0300

> These two variants are very close to each other and can be merged
> to avoid code duplication. That's what this patchset does.
> 
> First, we allow sctp_init_cause to return errors, which then allow us to
> add sctp_make_op_error_limited that handles both situations.

Series applied.

But generally, there are a lot of smtp_init_cause() call sites with non-zero
payload length that should start checking the return value now.
Marcelo Ricardo Leitner May 1, 2018, 11:28 p.m. UTC | #2
On Tue, May 01, 2018 at 12:13:53PM -0400, David Miller wrote:
> From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> Date: Sun, 29 Apr 2018 12:56:30 -0300
>
> > These two variants are very close to each other and can be merged
> > to avoid code duplication. That's what this patchset does.
> >
> > First, we allow sctp_init_cause to return errors, which then allow us to
> > add sctp_make_op_error_limited that handles both situations.
>
> Series applied.

Thanks.

>
> But generally, there are a lot of smtp_init_cause() call sites with non-zero
> payload length that should start checking the return value now.

They are safe as is, because they follow the pattern:
- sctp_make_abort(...., somesize)
- sctp_init_cause(size)
where size is considered in somesize, so sctp_init_cause cannot fail
in there.

This new usage in sctp_make_op_error_limited is the only one where it
allocates a buffer without knowing how much data will actually be
pushed into it.

  Marcelo