From 22d7e3fc82eb0ba0096f6c1ca411d04b2d044266 Mon Sep 17 00:00:00 2001 From: msaitoh Date: Tue, 21 May 2019 09:18:37 +0000 Subject: [PATCH] KNF. No functional change. --- sys/net/if.c | 20 +++++++------- sys/net/if_media.c | 7 +++-- sys/net/if_tap.c | 67 ++++++++++++++++++++++++---------------------- 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index e9093bb63126..e5fabe018975 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.454 2019/05/17 07:37:12 msaitoh Exp $ */ +/* $NetBSD: if.c,v 1.455 2019/05/21 09:18:37 msaitoh Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.454 2019/05/17 07:37:12 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.455 2019/05/21 09:18:37 msaitoh Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -452,7 +452,7 @@ if_dl_create(const struct ifnet *ifp, const struct sockaddr_dl **sdlp) addrlen = ifp->if_addrlen; socksize = roundup(sockaddr_dl_measure(namelen, addrlen), sizeof(long)); ifasize = sizeof(*ifa) + 2 * socksize; - ifa = malloc(ifasize, M_IFADDR, M_WAITOK|M_ZERO); + ifa = malloc(ifasize, M_IFADDR, M_WAITOK | M_ZERO); sdl = (struct sockaddr_dl *)(ifa + 1); mask = (struct sockaddr_dl *)(socksize + (char *)sdl); @@ -657,7 +657,7 @@ skip: /* grow ifindex2ifnet */ m = oldlim * sizeof(struct ifnet *); n = if_indexlim * sizeof(struct ifnet *); - q = malloc(n, M_IFADDR, M_WAITOK|M_ZERO); + q = malloc(n, M_IFADDR, M_WAITOK | M_ZERO); if (ifindex2ifnet != NULL) { memcpy(q, ifindex2ifnet, m); free(ifindex2ifnet, M_IFADDR); @@ -985,7 +985,7 @@ sysctl_percpuq_setup(struct sysctllog **clog, const char* ifname, goto bad; if (sysctl_createv(clog, 0, &rnode, &cnode, - CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "maxlen", SYSCTL_DESCR("Maximum allowed input queue length"), sysctl_percpuq_maxlen_handler, 0, (void *)ipq, 0, @@ -1643,7 +1643,7 @@ static bool if_is_unit(const char *name) { - while(*name != '\0') { + while (*name != '\0') { if (*name < '0' || *name > '9') return false; name++; @@ -3583,8 +3583,8 @@ if_do_dad(struct ifnet *ifp) * XXX: we should rather mark "tentative" on such addresses, * and do DAD after the interface becomes ready. */ - if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != - (IFF_UP|IFF_RUNNING)) + if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) != + (IFF_UP | IFF_RUNNING)) return 0; return 1; @@ -3684,7 +3684,7 @@ sysctl_sndq_setup(struct sysctllog **clog, const char *ifname, goto bad; if (sysctl_createv(clog, 0, &rnode, &cnode, - CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "maxlen", SYSCTL_DESCR("Maximum allowed output queue length"), NULL, 0, &ifq->ifq_maxlen, 0, @@ -3788,7 +3788,7 @@ sysctl_net_pktq_setup(struct sysctllog **clog, int pf) len_func, 0, NULL, 0, CTL_NET, pf, ipn, qid, IFQCTL_LEN, CTL_EOL); sysctl_createv(clog, 0, NULL, NULL, - CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "maxlen", SYSCTL_DESCR("Maximum allowed input queue length"), maxlen_func, 0, NULL, 0, diff --git a/sys/net/if_media.c b/sys/net/if_media.c index 4142bd33ebbe..6f6faa392431 100644 --- a/sys/net/if_media.c +++ b/sys/net/if_media.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_media.c,v 1.45 2019/05/17 07:37:12 msaitoh Exp $ */ +/* $NetBSD: if_media.c,v 1.46 2019/05/21 09:18:37 msaitoh Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -76,7 +76,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.45 2019/05/17 07:37:12 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.46 2019/05/21 09:18:37 msaitoh Exp $"); #include #include @@ -134,8 +134,7 @@ ifmedia_change(struct ifmedia *ifm, struct ifnet *ifp) } static void -ifmedia_status(struct ifmedia *ifm, struct ifnet *ifp, - struct ifmediareq *ifmr) +ifmedia_status(struct ifmedia *ifm, struct ifnet *ifp, struct ifmediareq *ifmr) { if (ifm->ifm_status == NULL) diff --git a/sys/net/if_tap.c b/sys/net/if_tap.c index 852f1f5dd2db..2bbb84c46733 100644 --- a/sys/net/if_tap.c +++ b/sys/net/if_tap.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_tap.c,v 1.111 2019/04/26 11:51:56 pgoyette Exp $ */ +/* $NetBSD: if_tap.c,v 1.112 2019/05/21 09:18:37 msaitoh Exp $ */ /* * Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation. @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.111 2019/04/26 11:51:56 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.112 2019/05/21 09:18:37 msaitoh Exp $"); #if defined(_KERNEL_OPT) @@ -251,6 +251,7 @@ static void tapinit(void) { int error = config_cfattach_attach(tap_cd.cd_name, &tap_ca); + if (error) { aprint_error("%s: unable to register cfattach\n", tap_cd.cd_name); @@ -350,14 +351,14 @@ tap_attach(device_t parent, device_t self, void *aux) * of them. */ ifmedia_init(&sc->sc_im, 0, tap_mediachange, tap_mediastatus); - ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_1000_T, 0, NULL); - ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_1000_T|IFM_FDX, 0, NULL); - ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_100_TX, 0, NULL); - ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL); - ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_10_T, 0, NULL); - ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL); - ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_AUTO, 0, NULL); - ifmedia_set(&sc->sc_im, IFM_ETHER|IFM_AUTO); + ifmedia_add(&sc->sc_im, IFM_ETHER | IFM_1000_T, 0, NULL); + ifmedia_add(&sc->sc_im, IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL); + ifmedia_add(&sc->sc_im, IFM_ETHER | IFM_100_TX, 0, NULL); + ifmedia_add(&sc->sc_im, IFM_ETHER | IFM_100_TX | IFM_FDX, 0, NULL); + ifmedia_add(&sc->sc_im, IFM_ETHER | IFM_10_T, 0, NULL); + ifmedia_add(&sc->sc_im, IFM_ETHER | IFM_10_T | IFM_FDX, 0, NULL); + ifmedia_add(&sc->sc_im, IFM_ETHER | IFM_AUTO, 0, NULL); + ifmedia_set(&sc->sc_im, IFM_ETHER | IFM_AUTO); /* * One should note that an interface must do multicast in order @@ -477,6 +478,7 @@ static void tap_mediastatus(struct ifnet *ifp, struct ifmediareq *imr) { struct tap_softc *sc = (struct tap_softc *)ifp->if_softc; + imr->ifm_active = sc->sc_im.ifm_cur->ifm_media; } @@ -516,7 +518,7 @@ tap_start(struct ifnet *ifp) mutex_enter(&sc->sc_lock); if ((sc->sc_flags & TAP_INUSE) == 0) { /* Simply drop packets */ - for(;;) { + for (;;) { IFQ_DEQUEUE(&ifp->if_snd, m0); if (m0 == NULL) goto done; @@ -550,7 +552,7 @@ tap_softintr(void *cookie) ifp = &sc->sc_ec.ec_if; if (ifp->if_flags & IFF_RUNNING) { a = POLL_IN; - b = POLLIN|POLLRDNORM; + b = POLLIN | POLLRDNORM; } else { a = POLL_HUP; b = 0; @@ -661,6 +663,7 @@ tap_stop(struct ifnet *ifp, int disable) static int tap_clone_create(struct if_clone *ifc, int unit) { + if (tap_clone_creator(unit) == NULL) { aprint_error("%s%d: unable to attach an instance\n", tap_cd.cd_name, unit); @@ -806,7 +809,7 @@ tap_dev_cloner(struct lwp *l) sc->sc_flags |= TAP_INUSE; - return fd_clone(fp, fd, FREAD|FWRITE, &tap_fileops, + return fd_clone(fp, fd, FREAD | FWRITE, &tap_fileops, (void *)(intptr_t)device_unit(sc->sc_dev)); } @@ -821,11 +824,9 @@ tap_dev_cloner(struct lwp *l) * created it closes it. */ static int -tap_cdev_close(dev_t dev, int flags, int fmt, - struct lwp *l) +tap_cdev_close(dev_t dev, int flags, int fmt, struct lwp *l) { - struct tap_softc *sc = - device_lookup_private(&tap_cd, minor(dev)); + struct tap_softc *sc = device_lookup_private(&tap_cd, minor(dev)); if (sc == NULL) return ENXIO; @@ -842,8 +843,8 @@ tap_cdev_close(dev_t dev, int flags, int fmt, static int tap_fops_close(file_t *fp) { - int unit = fp->f_devunit; struct tap_softc *sc; + int unit = fp->f_devunit; int error; sc = device_lookup_private(&tap_cd, unit); @@ -909,6 +910,7 @@ tap_dev_close(struct tap_softc *sc) static int tap_cdev_read(dev_t dev, struct uio *uio, int flags) { + return tap_dev_read(minor(dev), uio, flags); } @@ -941,15 +943,12 @@ tap_dev_read(int unit, struct uio *uio, int flags) if ((ifp->if_flags & IFF_UP) == 0) return EHOSTDOWN; - /* - * In the TAP_NBIO case, we have to make sure we won't be sleeping - */ + /* In the TAP_NBIO case, we have to make sure we won't be sleeping */ if ((sc->sc_flags & TAP_NBIO) != 0) { if (!mutex_tryenter(&sc->sc_lock)) return EWOULDBLOCK; - } else { + } else mutex_enter(&sc->sc_lock); - } if (IFQ_IS_EMPTY(&ifp->if_snd)) { ifp->if_flags &= ~IFF_OACTIVE; @@ -1027,6 +1026,7 @@ out: static int tap_cdev_write(dev_t dev, struct uio *uio, int flags) { + return tap_dev_write(minor(dev), uio, flags); } @@ -1092,15 +1092,16 @@ tap_dev_write(int unit, struct uio *uio, int flags) } static int -tap_cdev_ioctl(dev_t dev, u_long cmd, void *data, int flags, - struct lwp *l) +tap_cdev_ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l) { + return tap_dev_ioctl(minor(dev), cmd, data, l); } static int tap_fops_ioctl(file_t *fp, u_long cmd, void *data) { + return tap_dev_ioctl(fp->f_devunit, cmd, data, curlwp); } @@ -1174,26 +1175,27 @@ tap_dev_ioctl(int unit, u_long cmd, void *data, struct lwp *l) static int tap_cdev_poll(dev_t dev, int events, struct lwp *l) { + return tap_dev_poll(minor(dev), events, l); } static int tap_fops_poll(file_t *fp, int events) { + return tap_dev_poll(fp->f_devunit, events, curlwp); } static int tap_dev_poll(int unit, int events, struct lwp *l) { - struct tap_softc *sc = - device_lookup_private(&tap_cd, unit); + struct tap_softc *sc = device_lookup_private(&tap_cd, unit); int revents = 0; if (sc == NULL) return POLLERR; - if (events & (POLLIN|POLLRDNORM)) { + if (events & (POLLIN | POLLRDNORM)) { struct ifnet *ifp = &sc->sc_ec.ec_if; struct mbuf *m; int s; @@ -1202,7 +1204,7 @@ tap_dev_poll(int unit, int events, struct lwp *l) IFQ_POLL(&ifp->if_snd, m); if (m != NULL) - revents |= events & (POLLIN|POLLRDNORM); + revents |= events & (POLLIN | POLLRDNORM); else { mutex_spin_enter(&sc->sc_lock); selrecord(l, &sc->sc_rsel); @@ -1210,7 +1212,7 @@ tap_dev_poll(int unit, int events, struct lwp *l) } splx(s); } - revents |= events & (POLLOUT|POLLWRNORM); + revents |= events & (POLLOUT | POLLWRNORM); return revents; } @@ -1223,20 +1225,21 @@ static struct filterops tap_seltrue_filterops = { 1, NULL, tap_kqdetach, static int tap_cdev_kqfilter(dev_t dev, struct knote *kn) { + return tap_dev_kqfilter(minor(dev), kn); } static int tap_fops_kqfilter(file_t *fp, struct knote *kn) { + return tap_dev_kqfilter(fp->f_devunit, kn); } static int tap_dev_kqfilter(int unit, struct knote *kn) { - struct tap_softc *sc = - device_lookup_private(&tap_cd, unit); + struct tap_softc *sc = device_lookup_private(&tap_cd, unit); if (sc == NULL) return ENXIO;