summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authoryar <yar@FreeBSD.org>2005-10-03 02:14:51 +0000
committeryar <yar@FreeBSD.org>2005-10-03 02:14:51 +0000
commit99e7b443ad74d6a46a5350fe9d9ecfe4bb26315d (patch)
tree436deb331c457cd1d1044ecb8d94b45008fb9b74 /sys
parent8b308662cd9807a1704b529ddd0e145f51e34b3d (diff)
downloadFreeBSD-src-99e7b443ad74d6a46a5350fe9d9ecfe4bb26315d.zip
FreeBSD-src-99e7b443ad74d6a46a5350fe9d9ecfe4bb26315d.tar.gz
Clean up consistency checks in if_setflag():
. use KASSERT for all checks so that the source of an error can be detected; . use __func__ instead of spelling function name each time; . fix a typo.
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index bc51abe..31d286b 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1594,7 +1594,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td)
/*
* The code common to handling reference counted flags,
* e.g., in ifpromisc() and if_allmulti().
- * The "pflag" argument can specify a permanent mode flag,
+ * The "pflag" argument can specify a permanent mode flag to check,
* such as IFF_PPROMISC for promiscuous mode; should be 0 if none.
*
* Only to be used on stack-owned flags, not driver-owned flags.
@@ -1606,25 +1606,18 @@ if_setflag(struct ifnet *ifp, int flag, int pflag, int *refcount, int onswitch)
int error;
int oldflags, oldcount;
+ /* Sanity checks to catch programming errors */
KASSERT((flag & (IFF_DRV_OACTIVE|IFF_DRV_RUNNING)) == 0,
- ("if_setflag: setting driver-ownded flag %d", flag));
+ ("%s: setting driver-owned flag %d", __func__, flag));
- /* Sanity checks to catch programming errors */
- if (onswitch) {
- if (*refcount < 0) {
- if_printf(ifp,
- "refusing to increment negative refcount %d "
- "for interface flag %d\n", *refcount, flag);
- return (EINVAL);
- }
- } else {
- if (*refcount <= 0) {
- if_printf(ifp,
- "refusing to decrement non-positive refcount %d"
- "for interface flag %d\n", *refcount, flag);
- return (EINVAL);
- }
- }
+ if (onswitch)
+ KASSERT(*refcount >= 0,
+ ("%s: increment negative refcount %d for flag %d",
+ __func__, *refcount, flag));
+ else
+ KASSERT(*refcount > 0,
+ ("%s: decrement non-positive refcount %d for flag %d",
+ __func__, *refcount, flag));
/* In case this mode is permanent, just touch refcount */
if (ifp->if_flags & pflag) {
OpenPOWER on IntegriCloud