Skip to content

Commit

Permalink
ax25: Add missing dev_put in ax25_setsockopt
Browse files Browse the repository at this point in the history
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ralf Baechle authored and David S. Miller committed Sep 28, 2009
1 parent d1f8297 commit 2f72291
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,28 +641,29 @@ 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;
}

if (sk->sk_type == SOCK_SEQPACKET &&
(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:
Expand Down

0 comments on commit 2f72291

Please sign in to comment.