All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: maowenan <maowenan@huawei.com>,
	vyasevich@gmail.com, nhorman@tuxdriver.com, davem@davemloft.net,
	linux-sctp@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH net 1/2] sctp: remove redundant assignment when call sctp_get_port_local
Date: Wed, 11 Sep 2019 11:39:23 -0300	[thread overview]
Message-ID: <20190911143923.GE3499@localhost.localdomain> (raw)
In-Reply-To: <20190911143008.GD3499@localhost.localdomain>

On Wed, Sep 11, 2019 at 11:30:08AM -0300, Marcelo Ricardo Leitner wrote:
> On Wed, Sep 11, 2019 at 11:30:38AM +0300, Dan Carpenter wrote:
> > On Wed, Sep 11, 2019 at 09:30:47AM +0800, maowenan wrote:
> > > 
> > > 
> > > On 2019/9/11 3:22, Dan Carpenter wrote:
> > > > On Tue, Sep 10, 2019 at 09:57:10PM +0300, Dan Carpenter wrote:
> > > >> On Tue, Sep 10, 2019 at 03:13:42PM +0800, Mao Wenan wrote:
> > > >>> There are more parentheses in if clause when call sctp_get_port_local
> > > >>> in sctp_do_bind, and redundant assignment to 'ret'. This patch is to
> > > >>> do cleanup.
> > > >>>
> > > >>> Signed-off-by: Mao Wenan <maowenan@huawei.com>
> > > >>> ---
> > > >>>  net/sctp/socket.c | 3 +--
> > > >>>  1 file changed, 1 insertion(+), 2 deletions(-)
> > > >>>
> > > >>> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> > > >>> index 9d1f83b10c0a..766b68b55ebe 100644
> > > >>> --- a/net/sctp/socket.c
> > > >>> +++ b/net/sctp/socket.c
> > > >>> @@ -399,9 +399,8 @@ static int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
> > > >>>  	 * detection.
> > > >>>  	 */
> > > >>>  	addr->v4.sin_port = htons(snum);
> > > >>> -	if ((ret = sctp_get_port_local(sk, addr))) {
> > > >>> +	if (sctp_get_port_local(sk, addr))
> > > >>>  		return -EADDRINUSE;
> > > >>
> > > >> sctp_get_port_local() returns a long which is either 0,1 or a pointer
> > > >> casted to long.  It's not documented what it means and neither of the
> > > >> callers use the return since commit 62208f12451f ("net: sctp: simplify
> > > >> sctp_get_port").
> > > > 
> > > > Actually it was commit 4e54064e0a13 ("sctp: Allow only 1 listening
> > > > socket with SO_REUSEADDR") from 11 years ago.  That patch fixed a bug,
> > > > because before the code assumed that a pointer casted to an int was the
> > > > same as a pointer casted to a long.
> > > 
> > > commit 4e54064e0a13 treated non-zero return value as unexpected, so the current
> > > cleanup is ok?
> > 
> > Yeah.  It's fine, I was just confused why we weren't preserving the
> > error code and then I saw that we didn't return errors at all and got
> > confused.
> 
> But please lets seize the moment and do the change Dean suggested.

*Dan*, sorry.

> This was the last place saving this return value somewhere. It makes
> sense to cleanup sctp_get_port_local() now and remove that masked
> pointer return.
> 
> Then you may also cleanup:
> socket.c:       return !!sctp_get_port_local(sk, &addr);
> as it will be a direct map.
> 
>   Marcelo
> 

WARNING: multiple messages have this Message-ID (diff)
From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: maowenan <maowenan@huawei.com>,
	vyasevich@gmail.com, nhorman@tuxdriver.com, davem@davemloft.net,
	linux-sctp@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH net 1/2] sctp: remove redundant assignment when call sctp_get_port_local
Date: Wed, 11 Sep 2019 14:39:23 +0000	[thread overview]
Message-ID: <20190911143923.GE3499@localhost.localdomain> (raw)
In-Reply-To: <20190911143008.GD3499@localhost.localdomain>

On Wed, Sep 11, 2019 at 11:30:08AM -0300, Marcelo Ricardo Leitner wrote:
> On Wed, Sep 11, 2019 at 11:30:38AM +0300, Dan Carpenter wrote:
> > On Wed, Sep 11, 2019 at 09:30:47AM +0800, maowenan wrote:
> > > 
> > > 
> > > On 2019/9/11 3:22, Dan Carpenter wrote:
> > > > On Tue, Sep 10, 2019 at 09:57:10PM +0300, Dan Carpenter wrote:
> > > >> On Tue, Sep 10, 2019 at 03:13:42PM +0800, Mao Wenan wrote:
> > > >>> There are more parentheses in if clause when call sctp_get_port_local
> > > >>> in sctp_do_bind, and redundant assignment to 'ret'. This patch is to
> > > >>> do cleanup.
> > > >>>
> > > >>> Signed-off-by: Mao Wenan <maowenan@huawei.com>
> > > >>> ---
> > > >>>  net/sctp/socket.c | 3 +--
> > > >>>  1 file changed, 1 insertion(+), 2 deletions(-)
> > > >>>
> > > >>> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> > > >>> index 9d1f83b10c0a..766b68b55ebe 100644
> > > >>> --- a/net/sctp/socket.c
> > > >>> +++ b/net/sctp/socket.c
> > > >>> @@ -399,9 +399,8 @@ static int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
> > > >>>  	 * detection.
> > > >>>  	 */
> > > >>>  	addr->v4.sin_port = htons(snum);
> > > >>> -	if ((ret = sctp_get_port_local(sk, addr))) {
> > > >>> +	if (sctp_get_port_local(sk, addr))
> > > >>>  		return -EADDRINUSE;
> > > >>
> > > >> sctp_get_port_local() returns a long which is either 0,1 or a pointer
> > > >> casted to long.  It's not documented what it means and neither of the
> > > >> callers use the return since commit 62208f12451f ("net: sctp: simplify
> > > >> sctp_get_port").
> > > > 
> > > > Actually it was commit 4e54064e0a13 ("sctp: Allow only 1 listening
> > > > socket with SO_REUSEADDR") from 11 years ago.  That patch fixed a bug,
> > > > because before the code assumed that a pointer casted to an int was the
> > > > same as a pointer casted to a long.
> > > 
> > > commit 4e54064e0a13 treated non-zero return value as unexpected, so the current
> > > cleanup is ok?
> > 
> > Yeah.  It's fine, I was just confused why we weren't preserving the
> > error code and then I saw that we didn't return errors at all and got
> > confused.
> 
> But please lets seize the moment and do the change Dean suggested.

*Dan*, sorry.

> This was the last place saving this return value somewhere. It makes
> sense to cleanup sctp_get_port_local() now and remove that masked
> pointer return.
> 
> Then you may also cleanup:
> socket.c:       return !!sctp_get_port_local(sk, &addr);
> as it will be a direct map.
> 
>   Marcelo
> 

  reply	other threads:[~2019-09-11 14:39 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-10  6:56 [PATCH net 0/2] fix memory leak for sctp_do_bind Mao Wenan
2019-09-10  7:13 ` Mao Wenan
2019-09-10  6:56 ` [PATCH net 1/2] sctp: remove redundant assignment when call sctp_get_port_local Mao Wenan
2019-09-10  7:13   ` Mao Wenan
2019-09-10  6:56   ` Mao Wenan
2019-09-10 18:57   ` Dan Carpenter
2019-09-10 18:57     ` Dan Carpenter
2019-09-10 19:22     ` Dan Carpenter
2019-09-10 19:22       ` Dan Carpenter
2019-09-11  1:30       ` maowenan
2019-09-11  1:30         ` maowenan
2019-09-11  8:30         ` Dan Carpenter
2019-09-11  8:30           ` Dan Carpenter
2019-09-11 14:30           ` Marcelo Ricardo Leitner
2019-09-11 14:30             ` Marcelo Ricardo Leitner
2019-09-11 14:39             ` Marcelo Ricardo Leitner [this message]
2019-09-11 14:39               ` Marcelo Ricardo Leitner
2019-09-12  2:05               ` maowenan
2019-09-12  2:05                 ` maowenan
2019-09-12  3:45                 ` [PATCH v2 net 0/3] fix memory leak for sctp_do_bind Mao Wenan
2019-09-12  4:02                   ` Mao Wenan
2019-09-12  3:45                   ` [PATCH v2 net 1/3] sctp: change return type of sctp_get_port_local Mao Wenan
2019-09-12  4:02                     ` Mao Wenan
2019-09-12  3:45                     ` Mao Wenan
2019-09-12 14:51                     ` Marcelo Ricardo Leitner
2019-09-12 14:51                       ` Marcelo Ricardo Leitner
2019-09-12  3:45                   ` [PATCH v2 net 2/3] sctp: remove redundant assignment when call sctp_get_port_local Mao Wenan
2019-09-12  4:02                     ` Mao Wenan
2019-09-12  3:45                     ` Mao Wenan
2019-09-12 14:52                     ` Marcelo Ricardo Leitner
2019-09-12 14:52                       ` Marcelo Ricardo Leitner
2019-09-12  3:45                   ` [PATCH v2 net 3/3] sctp: destroy bucket if failed to bind addr Mao Wenan
2019-09-12  4:02                     ` Mao Wenan
2019-09-12  3:45                     ` Mao Wenan
2019-09-12 14:52                     ` Marcelo Ricardo Leitner
2019-09-12 14:52                       ` Marcelo Ricardo Leitner
2019-09-13 20:06                   ` [PATCH v2 net 0/3] fix memory leak for sctp_do_bind David Miller
2019-09-13 20:06                     ` David Miller
2019-09-10  6:56 ` [PATCH net 2/2] sctp: destroy bucket if failed to bind addr Mao Wenan
2019-09-10  7:13   ` Mao Wenan
2019-09-10  6:56   ` Mao Wenan
2019-09-10  7:16 ` [PATCH net 0/2] fix memory leak for sctp_do_bind Neil Horman
2019-09-10  7:16   ` Neil Horman

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=20190911143923.GE3499@localhost.localdomain \
    --to=marcelo.leitner@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sctp@vger.kernel.org \
    --cc=maowenan@huawei.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: link
Be 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.