Convert a complicated if/else if/else chain to a switch statement

that is a bit more readable.

ENODEV and ENOTTY are appropriate error codes for indicating
unsupported ioctls, but EINVAL is definitely not!  If an operation
is not supported, return ENODEV instead of EINVAL.
This commit is contained in:
dyoung 2008-02-23 02:26:53 +00:00
parent 932264266e
commit 29e838604a
1 changed files with 12 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: dp8390.c,v 1.66 2007/10/19 11:59:50 ad Exp $ */ /* $NetBSD: dp8390.c,v 1.67 2008/02/23 02:26:53 dyoung Exp $ */
/* /*
* Device driver for National Semiconductor DS8390/WD83C690 based ethernet * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
@ -14,7 +14,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: dp8390.c,v 1.66 2007/10/19 11:59:50 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: dp8390.c,v 1.67 2008/02/23 02:26:53 dyoung Exp $");
#include "opt_ipkdb.h" #include "opt_ipkdb.h"
#include "opt_inet.h" #include "opt_inet.h"
@ -892,8 +892,8 @@ dp8390_ioctl(ifp, cmd, data)
break; break;
case SIOCSIFFLAGS: case SIOCSIFFLAGS:
if ((ifp->if_flags & IFF_UP) == 0 && switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) {
(ifp->if_flags & IFF_RUNNING) != 0) { case IFF_RUNNING:
/* /*
* If interface is marked down and it is running, then * If interface is marked down and it is running, then
* stop it. * stop it.
@ -901,8 +901,8 @@ dp8390_ioctl(ifp, cmd, data)
dp8390_stop(sc); dp8390_stop(sc);
ifp->if_flags &= ~IFF_RUNNING; ifp->if_flags &= ~IFF_RUNNING;
dp8390_disable(sc); dp8390_disable(sc);
} else if ((ifp->if_flags & IFF_UP) != 0 && break;
(ifp->if_flags & IFF_RUNNING) == 0) { case IFF_UP:
/* /*
* If interface is marked up and it is stopped, then * If interface is marked up and it is stopped, then
* start it. * start it.
@ -910,13 +910,17 @@ dp8390_ioctl(ifp, cmd, data)
if ((error = dp8390_enable(sc)) != 0) if ((error = dp8390_enable(sc)) != 0)
break; break;
dp8390_init(sc); dp8390_init(sc);
} else if ((ifp->if_flags & IFF_UP) != 0) { break;
case IFF_UP|IFF_RUNNING:
/* /*
* Reset the interface to pick up changes in any other * Reset the interface to pick up changes in any other
* flags that affect hardware registers. * flags that affect hardware registers.
*/ */
dp8390_stop(sc); dp8390_stop(sc);
dp8390_init(sc); dp8390_init(sc);
break;
default:
break;
} }
break; break;
@ -947,7 +951,7 @@ dp8390_ioctl(ifp, cmd, data)
break; break;
default: default:
error = EINVAL; error = ENODEV;
break; break;
} }