Patchwork NFC: only put local on destruction if it was created before

login
register
mail settings
Submitter Sasha Levin
Date June 12, 2012, 8:08 p.m.
Message ID <1339531699-7377-1-git-send-email-levinsasha928@gmail.com>
Download mbox | patch
Permalink /patch/164494/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Sasha Levin - June 12, 2012, 8:08 p.m.
Not having 'local' is a valid case when a socket was created but never
bound or connected to anything, so avoid putting 'local' if it was
never created.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 net/nfc/llcp/sock.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Sasha Levin - June 25, 2012, 5:15 p.m.
On Mon, 2012-06-25 at 19:17 +0200, Samuel Ortiz wrote:
> Hi Sasha,
> 
> On Tue, Jun 12, 2012 at 10:08:19PM +0200, Sasha Levin wrote:
> > Not having 'local' is a valid case when a socket was created but never
> > bound or connected to anything, so avoid putting 'local' if it was
> > never created.
> > 
> > Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> > ---
> >  net/nfc/llcp/sock.c |    3 ++-
> >  1 files changed, 2 insertions(+), 1 deletions(-)
> > 
> > diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
> > index 2c0b317..54daa10 100644
> > --- a/net/nfc/llcp/sock.c
> > +++ b/net/nfc/llcp/sock.c
> > @@ -710,7 +710,8 @@ void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
> >  
> >  	sock->parent = NULL;
> >  
> > -	nfc_llcp_local_put(sock->local);
> > +	if (sock->local)
> > +		nfc_llcp_local_put(sock->local);
> nfc_llcp_local_put() already checks for its argument being NULL or not.

nfc_llcp_local_put() triggers a warning in this case as well, which
means that this code path shouldn't be happening.

Should we remove the WARN_ON from nfc_llcp_local_put() instead?

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Samuel Ortiz - June 25, 2012, 5:17 p.m.
Hi Sasha,

On Tue, Jun 12, 2012 at 10:08:19PM +0200, Sasha Levin wrote:
> Not having 'local' is a valid case when a socket was created but never
> bound or connected to anything, so avoid putting 'local' if it was
> never created.
> 
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
>  net/nfc/llcp/sock.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
> index 2c0b317..54daa10 100644
> --- a/net/nfc/llcp/sock.c
> +++ b/net/nfc/llcp/sock.c
> @@ -710,7 +710,8 @@ void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
>  
>  	sock->parent = NULL;
>  
> -	nfc_llcp_local_put(sock->local);
> +	if (sock->local)
> +		nfc_llcp_local_put(sock->local);
nfc_llcp_local_put() already checks for its argument being NULL or not.

Cheers,
Samuel.
Samuel Ortiz - June 25, 2012, 5:29 p.m.
On Mon, Jun 25, 2012 at 07:15:46PM +0200, Sasha Levin wrote:
> On Mon, 2012-06-25 at 19:17 +0200, Samuel Ortiz wrote:
> > Hi Sasha,
> > 
> > On Tue, Jun 12, 2012 at 10:08:19PM +0200, Sasha Levin wrote:
> > > Not having 'local' is a valid case when a socket was created but never
> > > bound or connected to anything, so avoid putting 'local' if it was
> > > never created.
> > > 
> > > Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> > > ---
> > >  net/nfc/llcp/sock.c |    3 ++-
> > >  1 files changed, 2 insertions(+), 1 deletions(-)
> > > 
> > > diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
> > > index 2c0b317..54daa10 100644
> > > --- a/net/nfc/llcp/sock.c
> > > +++ b/net/nfc/llcp/sock.c
> > > @@ -710,7 +710,8 @@ void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
> > >  
> > >  	sock->parent = NULL;
> > >  
> > > -	nfc_llcp_local_put(sock->local);
> > > +	if (sock->local)
> > > +		nfc_llcp_local_put(sock->local);
> > nfc_llcp_local_put() already checks for its argument being NULL or not.
> 
> nfc_llcp_local_put() triggers a warning in this case as well, which
> means that this code path shouldn't be happening.
> 
> Should we remove the WARN_ON from nfc_llcp_local_put() instead?
Yes, that would be better.

Cheers,
Samuel.

Patch

diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
index 2c0b317..54daa10 100644
--- a/net/nfc/llcp/sock.c
+++ b/net/nfc/llcp/sock.c
@@ -710,7 +710,8 @@  void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
 
 	sock->parent = NULL;
 
-	nfc_llcp_local_put(sock->local);
+	if (sock->local)
+		nfc_llcp_local_put(sock->local);
 }
 
 static int llcp_sock_create(struct net *net, struct socket *sock,