From 4efdef565f9a0ca3468534f97c6ac4aaaf747c9a Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 27 Sep 2008 08:51:18 +0000 Subject: Replace all calls to minor() with dev2unit(). After I removed all the unit2minor()/minor2unit() calls from the kernel yesterday, I realised calling minor() everywhere is quite confusing. Character devices now only have the ability to store a unit number, not a minor number. Remove the confusion by using dev2unit() everywhere. This commit could also be considered as a bug fix. A lot of drivers call minor(), while they should actually be calling dev2unit(). In -CURRENT this isn't a problem, but it turns out we never had any problem reports related to that issue in the past. I suspect not many people connect more than 256 pieces of the same hardware. Reviewed by: kib --- sys/net/if.c | 4 ++-- sys/net/if_tap.c | 34 +++++++++++++++++----------------- sys/net/if_tun.c | 12 ++++++------ 3 files changed, 25 insertions(+), 25 deletions(-) (limited to 'sys/net') diff --git a/sys/net/if.c b/sys/net/if.c index 0bc0329..0e5821e 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -252,7 +252,7 @@ netioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td /* only support interface specific ioctls */ if (IOCGROUP(cmd) != 'i') return (EOPNOTSUPP); - idx = minor(dev); + idx = dev2unit(dev); if (idx == 0) { /* * special network device, not interface. @@ -291,7 +291,7 @@ netkqfilter(struct cdev *dev, struct knote *kn) return (EINVAL); } - idx = minor(dev); + idx = dev2unit(dev); if (idx == 0) { klist = &V_ifklist; } else { diff --git a/sys/net/if_tap.c b/sys/net/if_tap.c index 25728f4..6dfc8c9 100644 --- a/sys/net/if_tap.c +++ b/sys/net/if_tap.c @@ -429,7 +429,7 @@ tapcreate(struct cdev *dev) unit &= TAPMAXUNIT; - TAPDEBUG("tapcreate(%s%d). minor = %#x\n", name, unit, minor(dev)); + TAPDEBUG("tapcreate(%s%d). minor = %#x\n", name, unit, dev2unit(dev)); /* generate fake MAC address: 00 bd xx xx xx unit_no */ macaddr_hi = htons(0x00bd); @@ -465,7 +465,7 @@ tapcreate(struct cdev *dev) knlist_init(&tp->tap_rsel.si_note, NULL, NULL, NULL, NULL); TAPDEBUG("interface %s is created. minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); } /* tapcreate */ @@ -511,7 +511,7 @@ tapopen(struct cdev *dev, int flag, int mode, struct thread *td) ifp->if_flags |= IFF_UP; splx(s); - TAPDEBUG("%s is open. minor = %#x\n", ifp->if_xname, minor(dev)); + TAPDEBUG("%s is open. minor = %#x\n", ifp->if_xname, dev2unit(dev)); return (0); } /* tapopen */ @@ -564,7 +564,7 @@ tapclose(struct cdev *dev, int foo, int bar, struct thread *td) mtx_unlock(&tp->tap_mtx); TAPDEBUG("%s is closed. minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); return (0); } /* tapclose */ @@ -851,7 +851,7 @@ tapread(struct cdev *dev, struct uio *uio, int flag) struct mbuf *m = NULL; int error = 0, len, s; - TAPDEBUG("%s reading, minor = %#x\n", ifp->if_xname, minor(dev)); + TAPDEBUG("%s reading, minor = %#x\n", ifp->if_xname, dev2unit(dev)); mtx_lock(&tp->tap_mtx); if ((tp->tap_flags & TAP_READY) != TAP_READY) { @@ -859,7 +859,7 @@ tapread(struct cdev *dev, struct uio *uio, int flag) /* Unlocked read. */ TAPDEBUG("%s not ready. minor = %#x, tap_flags = 0x%x\n", - ifp->if_xname, minor(dev), tp->tap_flags); + ifp->if_xname, dev2unit(dev), tp->tap_flags); return (EHOSTDOWN); } @@ -901,7 +901,7 @@ tapread(struct cdev *dev, struct uio *uio, int flag) if (m != NULL) { TAPDEBUG("%s dropping mbuf, minor = %#x\n", ifp->if_xname, - minor(dev)); + dev2unit(dev)); m_freem(m); } @@ -923,14 +923,14 @@ tapwrite(struct cdev *dev, struct uio *uio, int flag) struct mbuf *m; TAPDEBUG("%s writting, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); if (uio->uio_resid == 0) return (0); if ((uio->uio_resid < 0) || (uio->uio_resid > TAPMRU)) { TAPDEBUG("%s invalid packet len = %d, minor = %#x\n", - ifp->if_xname, uio->uio_resid, minor(dev)); + ifp->if_xname, uio->uio_resid, dev2unit(dev)); return (EIO); } @@ -983,19 +983,19 @@ tappoll(struct cdev *dev, int events, struct thread *td) int s, revents = 0; TAPDEBUG("%s polling, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); s = splimp(); if (events & (POLLIN | POLLRDNORM)) { if (ifp->if_snd.ifq_len > 0) { TAPDEBUG("%s have data in queue. len = %d, " \ "minor = %#x\n", ifp->if_xname, - ifp->if_snd.ifq_len, minor(dev)); + ifp->if_snd.ifq_len, dev2unit(dev)); revents |= (events & (POLLIN | POLLRDNORM)); } else { TAPDEBUG("%s waiting for data, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); selrecord(td, &tp->tap_rsel); } @@ -1025,19 +1025,19 @@ tapkqfilter(struct cdev *dev, struct knote *kn) switch (kn->kn_filter) { case EVFILT_READ: TAPDEBUG("%s kqfilter: EVFILT_READ, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); kn->kn_fop = &tap_read_filterops; break; case EVFILT_WRITE: TAPDEBUG("%s kqfilter: EVFILT_WRITE, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); kn->kn_fop = &tap_write_filterops; break; default: TAPDEBUG("%s kqfilter: invalid filter, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); splx(s); return (EINVAL); /* NOT REACHED */ @@ -1067,11 +1067,11 @@ tapkqread(struct knote *kn, long hint) s = splimp(); if ((kn->kn_data = ifp->if_snd.ifq_len) > 0) { TAPDEBUG("%s have data in queue. len = %d, minor = %#x\n", - ifp->if_xname, ifp->if_snd.ifq_len, minor(dev)); + ifp->if_xname, ifp->if_snd.ifq_len, dev2unit(dev)); ret = 1; } else { TAPDEBUG("%s waiting for data, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); ret = 0; } splx(s); diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index 24f3187..b057b79 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -386,7 +386,7 @@ tuncreate(const char *name, struct cdev *dev) bpfattach(ifp, DLT_NULL, sizeof(u_int32_t)); dev->si_drv1 = sc; TUNDEBUG(ifp, "interface %s is created, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); } static int @@ -978,19 +978,19 @@ tunkqfilter(struct cdev *dev, struct knote *kn) switch(kn->kn_filter) { case EVFILT_READ: TUNDEBUG(ifp, "%s kqfilter: EVFILT_READ, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); kn->kn_fop = &tun_read_filterops; break; case EVFILT_WRITE: TUNDEBUG(ifp, "%s kqfilter: EVFILT_WRITE, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); kn->kn_fop = &tun_write_filterops; break; default: TUNDEBUG(ifp, "%s kqfilter: invalid filter, minor = %#x\n", - ifp->if_xname, minor(dev)); + ifp->if_xname, dev2unit(dev)); splx(s); return(EINVAL); } @@ -1017,12 +1017,12 @@ tunkqread(struct knote *kn, long hint) if ((kn->kn_data = ifp->if_snd.ifq_len) > 0) { TUNDEBUG(ifp, "%s have data in the queue. Len = %d, minor = %#x\n", - ifp->if_xname, ifp->if_snd.ifq_len, minor(dev)); + ifp->if_xname, ifp->if_snd.ifq_len, dev2unit(dev)); ret = 1; } else { TUNDEBUG(ifp, "%s waiting for data, minor = %#x\n", ifp->if_xname, - minor(dev)); + dev2unit(dev)); ret = 0; } splx(s); -- cgit v1.1