[PATCH] ppbus/ppc locking
Bruce M. Simpson
bms at FreeBSD.org
Fri Jan 23 07:50:26 PST 2009
Here's a diff with my edits.
With these changes, the printer keeps being reported as busy, although I
seem to be able to write to the /dev/lpt0 device, and it is seen.
As Ed Schouten pointed out on IRC probably this unit2minor stuff needs
to go back in.
Back to work for this machine...
-------------- next part --------------
--- lpt.c.jhb 2009-01-23 14:31:43.000000000 +0000
+++ lpt.c 2009-01-23 15:21:08.000000000 +0000
@@ -140,6 +140,7 @@
static timeout_t lptout;
static int lpt_port_test(device_t dev, u_char data, u_char mask);
+static int lpt_detach(device_t dev);
static int lpt_detect(device_t dev);
#define DEVTOSOFTC(dev) \
@@ -408,12 +409,22 @@
sc->sc_inbuf = malloc(BUFSIZE, M_DEVBUF, M_WAITOK);
sc->sc_statbuf = malloc(BUFSTATSIZE, M_DEVBUF, M_WAITOK);
sc->sc_dev = dev;
- sc->sc_cdev = make_dev(&lpt_cdevsw, unit,
+ sc->sc_cdev = make_dev(&lpt_cdevsw, unit * 2,
UID_ROOT, GID_WHEEL, 0600, LPT_NAME "%d", unit);
+ if (sc->sc_cdev == NULL) {
+ device_printf(dev, "Unable to create data device node\n");
+ (void)lpt_detach(dev);
+ return (ENXIO);
+ }
sc->sc_cdev->si_drv1 = sc;
sc->sc_cdev->si_drv2 = 0;
- sc->sc_cdev_bypass = make_dev(&lpt_cdevsw, unit,
+ sc->sc_cdev_bypass = make_dev(&lpt_cdevsw, (unit * 2) + 1,
UID_ROOT, GID_WHEEL, 0600, LPT_NAME "%d.ctl", unit);
+ if (sc->sc_cdev_bypass == NULL) {
+ device_printf(dev, "Unable to create control device node\n");
+ (void)lpt_detach(dev);
+ return (ENXIO);
+ }
sc->sc_cdev_bypass->si_drv1 = sc;
sc->sc_cdev_bypass->si_drv2 = (void *)LP_BYPASS;
return (0);
@@ -425,8 +436,10 @@
struct lpt_data *sc = DEVTOSOFTC(dev);
device_t ppbus = device_get_parent(dev);
- destroy_dev(sc->sc_cdev);
- destroy_dev(sc->sc_cdev_bypass);
+ if (sc->sc_cdev)
+ destroy_dev(sc->sc_cdev);
+ if (sc->sc_cdev_bypass)
+ destroy_dev(sc->sc_cdev_bypass);
ppb_lock(ppbus);
lpt_release_ppbus(dev);
ppb_unlock(ppbus);
More information about the freebsd-current
mailing list