diff mbox

ax25: Add missing dev_put in ax25_setsockopt

Message ID 20090928125313.GA14250@linux-mips.org
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Ralf Baechle Sept. 28, 2009, 12:53 p.m. UTC
ax25_setsockopt SO_BINDTODEVICE is missing a dev_put call in case of
success.  Re-order code to fix this bug.  While at it also reformat two
lines of code to comply with the Linux coding style.

Initial patch by Jarek Poplawski <jarkao2@gmail.com>.

Reported-by: Bernard Pidoux F6BVP <f6bvp@free.fr>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

---
Counter-proposal.  Reordering all the code avoids the need for a 2nd dev_put
and is more readable.

   Ralf

 net/ax25/af_ax25.c |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

--
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

Comments

Bernard Pidoux Sept. 28, 2009, 5:46 p.m. UTC | #1
Hi take this one too. Hi.
Applied.

Thanks Ralf.

Bernard

Ralf Baechle a écrit :
> ax25_setsockopt SO_BINDTODEVICE is missing a dev_put call in case of
> success.  Re-order code to fix this bug.  While at it also reformat two
> lines of code to comply with the Linux coding style.
> 
> Initial patch by Jarek Poplawski <jarkao2@gmail.com>.
> 
> Reported-by: Bernard Pidoux F6BVP <f6bvp@free.fr>
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
> 
> ---
> Counter-proposal.  Reordering all the code avoids the need for a 2nd dev_put
> and is more readable.
> 
>    Ralf
> 
>  net/ax25/af_ax25.c |   19 ++++++++++---------
>  1 files changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
> index fbcac76..4102de1 100644
> --- a/net/ax25/af_ax25.c
> +++ b/net/ax25/af_ax25.c
> @@ -641,15 +641,10 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
>  
>  	case SO_BINDTODEVICE:
>  		if (optlen > IFNAMSIZ)
> -			optlen=IFNAMSIZ;
> -		if (copy_from_user(devname, optval, optlen)) {
> -		res = -EFAULT;
> -			break;
> -		}
> +			optlen = IFNAMSIZ;
>  
> -		dev = dev_get_by_name(&init_net, devname);
> -		if (dev == NULL) {
> -			res = -ENODEV;
> +		if (copy_from_user(devname, optval, optlen)) {
> +			res = -EFAULT;
>  			break;
>  		}
>  
> @@ -657,12 +652,18 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
>  		   (sock->state != SS_UNCONNECTED ||
>  		    sk->sk_state == TCP_LISTEN)) {
>  			res = -EADDRNOTAVAIL;
> -			dev_put(dev);
> +			break;
> +		}
> +
> +		dev = dev_get_by_name(&init_net, devname);
> +		if (!dev) {
> +			res = -ENODEV;
>  			break;
>  		}
>  
>  		ax25->ax25_dev = ax25_dev_ax25dev(dev);
>  		ax25_fillin_cb(ax25, ax25->ax25_dev);
> +		dev_put(dev);
>  		break;
>  
>  	default:
> 

--
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
David Miller Sept. 28, 2009, 7:26 p.m. UTC | #2
From: Ralf Baechle <ralf@linux-mips.org>
Date: Mon, 28 Sep 2009 13:53:13 +0100

> ax25_setsockopt SO_BINDTODEVICE is missing a dev_put call in case of
> success.  Re-order code to fix this bug.  While at it also reformat two
> lines of code to comply with the Linux coding style.
> 
> Initial patch by Jarek Poplawski <jarkao2@gmail.com>.
> 
> Reported-by: Bernard Pidoux F6BVP <f6bvp@free.fr>
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
> 
> ---
> Counter-proposal.  Reordering all the code avoids the need for a 2nd dev_put
> and is more readable.

Looks good to me, applied.
--
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
diff mbox

Patch

diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index fbcac76..4102de1 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -641,15 +641,10 @@  static int ax25_setsockopt(struct socket *sock, int level, int optname,
 
 	case SO_BINDTODEVICE:
 		if (optlen > IFNAMSIZ)
-			optlen=IFNAMSIZ;
-		if (copy_from_user(devname, optval, optlen)) {
-		res = -EFAULT;
-			break;
-		}
+			optlen = IFNAMSIZ;
 
-		dev = dev_get_by_name(&init_net, devname);
-		if (dev == NULL) {
-			res = -ENODEV;
+		if (copy_from_user(devname, optval, optlen)) {
+			res = -EFAULT;
 			break;
 		}
 
@@ -657,12 +652,18 @@  static int ax25_setsockopt(struct socket *sock, int level, int optname,
 		   (sock->state != SS_UNCONNECTED ||
 		    sk->sk_state == TCP_LISTEN)) {
 			res = -EADDRNOTAVAIL;
-			dev_put(dev);
+			break;
+		}
+
+		dev = dev_get_by_name(&init_net, devname);
+		if (!dev) {
+			res = -ENODEV;
 			break;
 		}
 
 		ax25->ax25_dev = ax25_dev_ax25dev(dev);
 		ax25_fillin_cb(ax25, ax25->ax25_dev);
+		dev_put(dev);
 		break;
 
 	default: