diff options
author | ed <ed@FreeBSD.org> | 2009-10-31 10:38:30 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-10-31 10:38:30 +0000 |
commit | 9ade11517cead4cc052d6f18b7cc626962a03fc0 (patch) | |
tree | 9afa2ddf4d9e77374a2f3de33198e8ec2c7250f2 /sys/i386/bios | |
parent | 8bda786eedc7619f1dac0e722db1d4d8ca68fcd5 (diff) | |
download | FreeBSD-src-9ade11517cead4cc052d6f18b7cc626962a03fc0.zip FreeBSD-src-9ade11517cead4cc052d6f18b7cc626962a03fc0.tar.gz |
Unobfuscate unit number handling in apm(4).
There is no need to use the lower 4 bits of the unit number to store the
device type number. Just use 0 and 1 to distinguish them. devfs also
guarantees that there can never be an open call on a device that has a
unit number different to 0 and 1, so there is no need to check for this
in open().
Diffstat (limited to 'sys/i386/bios')
-rw-r--r-- | sys/i386/bios/apm.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/sys/i386/bios/apm.c b/sys/i386/bios/apm.c index 49d028b..e015cd0 100644 --- a/sys/i386/bios/apm.c +++ b/sys/i386/bios/apm.c @@ -79,9 +79,8 @@ int apm_evindex; #define SCFLAG_OCTL 0x0000002 #define SCFLAG_OPEN (SCFLAG_ONORMAL|SCFLAG_OCTL) -#define APMDEV(dev) (dev2unit(dev)&0x0f) #define APMDEV_NORMAL 0 -#define APMDEV_CTL 8 +#define APMDEV_CTL 1 #ifdef PC98 extern int bios32_apm98(struct bios_regs *, u_int, u_short); @@ -1249,8 +1248,10 @@ apm_attach(device_t dev) sc->suspending = 0; sc->running = 0; - make_dev(&apm_cdevsw, 0, 0, 5, 0664, "apm"); - make_dev(&apm_cdevsw, 8, 0, 5, 0660, "apmctl"); + make_dev(&apm_cdevsw, APMDEV_NORMAL, + UID_ROOT, GID_OPERATOR, 0664, "apm"); + make_dev(&apm_cdevsw, APMDEV_CTL, + UID_ROOT, GID_OPERATOR, 0660, "apmctl"); return 0; } @@ -1258,12 +1259,11 @@ static int apmopen(struct cdev *dev, int flag, int fmt, struct thread *td) { struct apm_softc *sc = &apm_softc; - int ctl = APMDEV(dev); if (sc == NULL || sc->initialized == 0) return (ENXIO); - switch (ctl) { + switch (dev2unit(dev)) { case APMDEV_CTL: if (!(flag & FWRITE)) return EINVAL; @@ -1275,9 +1275,6 @@ apmopen(struct cdev *dev, int flag, int fmt, struct thread *td) case APMDEV_NORMAL: sc->sc_flags |= SCFLAG_ONORMAL; break; - default: - return ENXIO; - break; } return 0; } @@ -1286,9 +1283,8 @@ static int apmclose(struct cdev *dev, int flag, int fmt, struct thread *td) { struct apm_softc *sc = &apm_softc; - int ctl = APMDEV(dev); - switch (ctl) { + switch (dev2unit(dev)) { case APMDEV_CTL: apm_lastreq_rejected(); sc->sc_flags &= ~SCFLAG_OCTL; @@ -1429,7 +1425,7 @@ apmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td } /* for /dev/apmctl */ - if (APMDEV(dev) == APMDEV_CTL) { + if (dev2unit(dev) == APMDEV_CTL) { struct apm_event_info *evp; int i; @@ -1468,7 +1464,7 @@ apmwrite(struct cdev *dev, struct uio *uio, int ioflag) int error; u_char enabled; - if (APMDEV(dev) != APMDEV_CTL) + if (dev2unit(dev) != APMDEV_CTL) return(ENODEV); if (uio->uio_resid != sizeof(u_int)) return(E2BIG); |