]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: ipmr: make ip_mroute_getsockopt more understandable
authorNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Sat, 21 Nov 2015 14:57:28 +0000 (15:57 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 23 Nov 2015 20:06:38 +0000 (15:06 -0500)
Use a switch to determine if optname is correct and set val accordingly.
This produces a much more straight-forward and readable code.

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ipmr.c

index 286ede3716ee0644db75d57742d0c148af807fa8..694fecf7838e668e72c7d0d94c56db8d9c55726b 100644 (file)
@@ -1443,29 +1443,29 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int
        if (!mrt)
                return -ENOENT;
 
-       if (optname != MRT_VERSION &&
-          optname != MRT_PIM &&
-          optname != MRT_ASSERT)
+       switch (optname) {
+       case MRT_VERSION:
+               val = 0x0305;
+               break;
+       case MRT_PIM:
+               if (!pimsm_enabled())
+                       return -ENOPROTOOPT;
+               val = mrt->mroute_do_pim;
+               break;
+       case MRT_ASSERT:
+               val = mrt->mroute_do_assert;
+               break;
+       default:
                return -ENOPROTOOPT;
+       }
 
        if (get_user(olr, optlen))
                return -EFAULT;
-
        olr = min_t(unsigned int, olr, sizeof(int));
        if (olr < 0)
                return -EINVAL;
-
        if (put_user(olr, optlen))
                return -EFAULT;
-       if (optname == MRT_VERSION) {
-               val = 0x0305;
-       } else if (optname == MRT_PIM) {
-               if (!pimsm_enabled())
-                       return -ENOPROTOOPT;
-               val = mrt->mroute_do_pim;
-       } else {
-               val = mrt->mroute_do_assert;
-       }
        if (copy_to_user(optval, &val, olr))
                return -EFAULT;
        return 0;