From fcf7e634fb12f16e5d5a0b3ee3cfafda001a303c Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 21 Feb 2004 20:41:11 +0000 Subject: [PATCH] Device megapatch 3/6: Add missing D_TTY flags to various drivers. Complete asserts that dev_t's passed to ttyread(), ttywrite(), ttypoll() and ttykqwrite() have (d_flags & D_TTY) and a struct tty pointer. Make ttyread(), ttywrite(), ttypoll() and ttykqwrite() the default cdevsw methods for D_TTY drivers and remove the explicit initializations in various drivers cdevsw structures. --- sys/alpha/alpha/promcons.c | 4 +--- sys/alpha/tlsb/zs_tlsb.c | 4 +--- sys/dev/cx/if_cx.c | 1 - sys/dev/cy/cy.c | 3 --- sys/dev/cy/cy_isa.c | 3 --- sys/dev/dcons/dcons.c | 4 +--- sys/dev/digi/digi.c | 2 -- sys/dev/nmdm/nmdm.c | 1 - sys/dev/ofw/ofw_console.c | 4 +--- sys/dev/rc/rc.c | 4 ---- sys/dev/rp/rp.c | 2 -- sys/dev/sab/sab.c | 4 ---- sys/dev/si/si.c | 3 --- sys/dev/sio/sio.c | 2 -- sys/dev/syscons/syscons.c | 3 --- sys/dev/syscons/sysmouse.c | 2 -- sys/dev/uart/uart_tty.c | 4 ---- sys/dev/usb/ucom.c | 2 -- sys/dev/zs/zs.c | 4 ---- sys/i386/isa/cy.c | 3 --- sys/i386/isa/istallion.c | 2 -- sys/i386/isa/pcvt/pcvt_drv.c | 4 ---- sys/i386/isa/stallion.c | 4 ---- sys/ia64/ia64/ssc.c | 4 +--- sys/kern/kern_conf.c | 8 ++++++++ sys/kern/tty.c | 19 ++++++++++++++++++- sys/kern/tty_pty.c | 3 --- sys/pc98/cbus/sio.c | 2 -- sys/pc98/pc98/sio.c | 2 -- 29 files changed, 31 insertions(+), 76 deletions(-) diff --git a/sys/alpha/alpha/promcons.c b/sys/alpha/alpha/promcons.c index 1800de6e624c..473f0fc515e5 100644 --- a/sys/alpha/alpha/promcons.c +++ b/sys/alpha/alpha/promcons.c @@ -66,11 +66,9 @@ static d_ioctl_t promioctl; static struct cdevsw prom_cdevsw = { .d_open = promopen, .d_close = promclose, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = promioctl, - .d_poll = ttypoll, .d_name = "prom", + .d_flags = D_TTY, }; diff --git a/sys/alpha/tlsb/zs_tlsb.c b/sys/alpha/tlsb/zs_tlsb.c index 55065e1f786f..035ac45678c7 100644 --- a/sys/alpha/tlsb/zs_tlsb.c +++ b/sys/alpha/tlsb/zs_tlsb.c @@ -73,11 +73,9 @@ static d_ioctl_t zsioctl; static struct cdevsw zs_cdevsw = { .d_open = zsopen, .d_close = zsclose, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = zsioctl, - .d_poll = ttypoll, .d_name = "zs", + .d_flags = D_TTY, }; static void zsstart(struct tty *); diff --git a/sys/dev/cx/if_cx.c b/sys/dev/cx/if_cx.c index 7fb4247d6390..52fc80dcbce6 100644 --- a/sys/dev/cx/if_cx.c +++ b/sys/dev/cx/if_cx.c @@ -2555,7 +2555,6 @@ static struct cdevsw cx_cdevsw = { .d_read = cx_read, .d_write = cx_write, .d_ioctl = cx_ioctl, - .d_poll = ttypoll, .d_name = "cx", .d_maj = CDEV_MAJOR, .d_flags = D_TTY, diff --git a/sys/dev/cy/cy.c b/sys/dev/cy/cy.c index 4351a3051de8..2a715c03046b 100644 --- a/sys/dev/cy/cy.c +++ b/sys/dev/cy/cy.c @@ -388,13 +388,10 @@ static d_ioctl_t sioioctl; static struct cdevsw sio_cdevsw = { .d_open = sioopen, .d_close = sioclose, - .d_read = ttyread, .d_write = siowrite, .d_ioctl = sioioctl, - .d_poll = ttypoll, .d_name = driver_name, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; static int comconsole = -1; diff --git a/sys/dev/cy/cy_isa.c b/sys/dev/cy/cy_isa.c index 4351a3051de8..2a715c03046b 100644 --- a/sys/dev/cy/cy_isa.c +++ b/sys/dev/cy/cy_isa.c @@ -388,13 +388,10 @@ static d_ioctl_t sioioctl; static struct cdevsw sio_cdevsw = { .d_open = sioopen, .d_close = sioclose, - .d_read = ttyread, .d_write = siowrite, .d_ioctl = sioioctl, - .d_poll = ttypoll, .d_name = driver_name, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; static int comconsole = -1; diff --git a/sys/dev/dcons/dcons.c b/sys/dev/dcons/dcons.c index 04d75494f1c6..8e6732626c09 100644 --- a/sys/dev/dcons/dcons.c +++ b/sys/dev/dcons/dcons.c @@ -90,11 +90,9 @@ static struct cdevsw dcons_cdevsw = { #if __FreeBSD_version >= 500104 .d_open = dcons_open, .d_close = dcons_close, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = dcons_ioctl, - .d_poll = ttypoll, .d_name = "dcons", + .d_flags = D_TTY, #else /* open */ dcons_open, /* close */ dcons_close, diff --git a/sys/dev/digi/digi.c b/sys/dev/digi/digi.c index f1bc67019e2a..87ebbef528c0 100644 --- a/sys/dev/digi/digi.c +++ b/sys/dev/digi/digi.c @@ -147,10 +147,8 @@ static struct cdevsw digi_sw = { .d_read = digiread, .d_write = digiwrite, .d_ioctl = digiioctl, - .d_poll = ttypoll, .d_name = driver_name, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter }; static void diff --git a/sys/dev/nmdm/nmdm.c b/sys/dev/nmdm/nmdm.c index f3440dda9f1e..27625068a08a 100644 --- a/sys/dev/nmdm/nmdm.c +++ b/sys/dev/nmdm/nmdm.c @@ -77,7 +77,6 @@ static struct cdevsw nmdm_cdevsw = { .d_read = nmdmread, .d_write = nmdmwrite, .d_ioctl = nmdmioctl, - .d_poll = ttypoll, .d_name = "nmdm", .d_flags = D_TTY | D_PSEUDO, }; diff --git a/sys/dev/ofw/ofw_console.c b/sys/dev/ofw/ofw_console.c index a4b5c8f98902..dd5537661e5e 100644 --- a/sys/dev/ofw/ofw_console.c +++ b/sys/dev/ofw/ofw_console.c @@ -55,11 +55,9 @@ static d_ioctl_t ofw_dev_ioctl; static struct cdevsw ofw_cdevsw = { .d_open = ofw_dev_open, .d_close = ofw_dev_close, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = ofw_dev_ioctl, - .d_poll = ttypoll, .d_name = "ofw", + .d_flags = D_TTY, }; static struct tty *ofw_tp = NULL; diff --git a/sys/dev/rc/rc.c b/sys/dev/rc/rc.c index f11537c4c82c..e519177db935 100644 --- a/sys/dev/rc/rc.c +++ b/sys/dev/rc/rc.c @@ -149,13 +149,9 @@ static d_ioctl_t rcioctl; static struct cdevsw rc_cdevsw = { .d_open = rcopen, .d_close = rcclose, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = rcioctl, - .d_poll = ttypoll, .d_name = "rc", .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; static devclass_t rc_devclass; diff --git a/sys/dev/rp/rp.c b/sys/dev/rp/rp.c index 98ae4a738bd3..1088de23496f 100644 --- a/sys/dev/rp/rp.c +++ b/sys/dev/rp/rp.c @@ -574,10 +574,8 @@ static d_ioctl_t rpioctl; struct cdevsw rp_cdevsw = { .d_open = rpopen, .d_close = rpclose, - .d_read = ttyread, .d_write = rpwrite, .d_ioctl = rpioctl, - .d_poll = ttypoll, .d_name = "rp", .d_flags = D_TTY, }; diff --git a/sys/dev/sab/sab.c b/sys/dev/sab/sab.c index aea2e16a0d56..36b6c1f9c53f 100644 --- a/sys/dev/sab/sab.c +++ b/sys/dev/sab/sab.c @@ -163,13 +163,9 @@ static int sabttyparam(struct tty *tp, struct termios *t); static struct cdevsw sabtty_cdevsw = { .d_open = sabttyopen, .d_close = sabttyclose, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = sabttyioctl, - .d_poll = ttypoll, .d_name = "sabtty", .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; static device_method_t sab_methods[] = { diff --git a/sys/dev/si/si.c b/sys/dev/si/si.c index a3fd213f0e65..fa0d9dba4f6d 100644 --- a/sys/dev/si/si.c +++ b/sys/dev/si/si.c @@ -120,13 +120,10 @@ static d_ioctl_t siioctl; static struct cdevsw si_cdevsw = { .d_open = siopen, .d_close = siclose, - .d_read = ttyread, .d_write = siwrite, .d_ioctl = siioctl, - .d_poll = ttypoll, .d_name = "si", .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; static int si_Nports; diff --git a/sys/dev/sio/sio.c b/sys/dev/sio/sio.c index 571265ddc65b..42c78b6fd587 100644 --- a/sys/dev/sio/sio.c +++ b/sys/dev/sio/sio.c @@ -328,10 +328,8 @@ static struct cdevsw sio_cdevsw = { .d_read = sioread, .d_write = siowrite, .d_ioctl = sioioctl, - .d_poll = ttypoll, .d_name = sio_driver_name, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; int comconsole = -1; diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c index 88c6ade511d6..f05de849f341 100644 --- a/sys/dev/syscons/syscons.c +++ b/sys/dev/syscons/syscons.c @@ -221,14 +221,11 @@ static struct cdevsw sc_cdevsw = { .d_open = scopen, .d_close = scclose, .d_read = scread, - .d_write = ttywrite, .d_ioctl = scioctl, - .d_poll = ttypoll, .d_mmap = scmmap, .d_name = "sc", .d_maj = CDEV_MAJOR, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter }; int diff --git a/sys/dev/syscons/sysmouse.c b/sys/dev/syscons/sysmouse.c index a7cff80c6bfe..08847a0dad5e 100644 --- a/sys/dev/syscons/sysmouse.c +++ b/sys/dev/syscons/sysmouse.c @@ -51,9 +51,7 @@ static d_ioctl_t smioctl; static struct cdevsw sm_cdevsw = { .d_open = smopen, .d_close = smclose, - .d_read = ttyread, .d_ioctl = smioctl, - .d_poll = ttypoll, .d_name = "sysmouse", .d_flags = D_TTY, }; diff --git a/sys/dev/uart/uart_tty.c b/sys/dev/uart/uart_tty.c index 6724ba759624..66ce71658e25 100644 --- a/sys/dev/uart/uart_tty.c +++ b/sys/dev/uart/uart_tty.c @@ -69,13 +69,9 @@ static d_ioctl_t uart_tty_ioctl; static struct cdevsw uart_cdevsw = { .d_open = uart_tty_open, .d_close = uart_tty_close, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = uart_tty_ioctl, - .d_poll = ttypoll, .d_name = uart_driver_name, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; static struct uart_devinfo uart_console; diff --git a/sys/dev/usb/ucom.c b/sys/dev/usb/ucom.c index 9298d087c18c..ad0a3d1ec099 100644 --- a/sys/dev/usb/ucom.c +++ b/sys/dev/usb/ucom.c @@ -133,13 +133,11 @@ static struct cdevsw ucom_cdevsw = { .d_read = ucomread, .d_write = ucomwrite, .d_ioctl = ucomioctl, - .d_poll = ttypoll, .d_name = "ucom", .d_flags = D_TTY, #if __FreeBSD_version < 500014 .d_bmaj = -1, #endif - .d_kqfilter = ttykqfilter, }; Static void ucom_cleanup(struct ucom_softc *); diff --git a/sys/dev/zs/zs.c b/sys/dev/zs/zs.c index a6e398f2c011..c3895a6457f2 100644 --- a/sys/dev/zs/zs.c +++ b/sys/dev/zs/zs.c @@ -154,13 +154,9 @@ static int zsttyparam(struct tty *tp, struct termios *t); static struct cdevsw zstty_cdevsw = { .d_open = zsttyopen, .d_close = zsttyclose, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = zsttyioctl, - .d_poll = ttypoll, .d_name = "zstty", .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; static struct zstty_softc *zstty_cons; diff --git a/sys/i386/isa/cy.c b/sys/i386/isa/cy.c index 4351a3051de8..2a715c03046b 100644 --- a/sys/i386/isa/cy.c +++ b/sys/i386/isa/cy.c @@ -388,13 +388,10 @@ static d_ioctl_t sioioctl; static struct cdevsw sio_cdevsw = { .d_open = sioopen, .d_close = sioclose, - .d_read = ttyread, .d_write = siowrite, .d_ioctl = sioioctl, - .d_poll = ttypoll, .d_name = driver_name, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; static int comconsole = -1; diff --git a/sys/i386/isa/istallion.c b/sys/i386/isa/istallion.c index e44400dc48a9..ee82892b6f14 100644 --- a/sys/i386/isa/istallion.c +++ b/sys/i386/isa/istallion.c @@ -648,10 +648,8 @@ static struct cdevsw stli_cdevsw = { .d_read = stliread, .d_write = stliwrite, .d_ioctl = stliioctl, - .d_poll = ttypoll, .d_name = stli_drvname, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; #endif diff --git a/sys/i386/isa/pcvt/pcvt_drv.c b/sys/i386/isa/pcvt/pcvt_drv.c index 351048020351..af16af93b75c 100644 --- a/sys/i386/isa/pcvt/pcvt_drv.c +++ b/sys/i386/isa/pcvt/pcvt_drv.c @@ -97,14 +97,10 @@ static d_mmap_t pcvt_mmap; static struct cdevsw vt_cdevsw = { .d_open = pcvt_open, .d_close = pcvt_close, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = pcvt_ioctl, - .d_poll = ttypoll, .d_mmap = pcvt_mmap, .d_name = "vt", .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; static int pcvt_probe(device_t dev); diff --git a/sys/i386/isa/stallion.c b/sys/i386/isa/stallion.c index 4665491dd57d..de0b2ccc9301 100644 --- a/sys/i386/isa/stallion.c +++ b/sys/i386/isa/stallion.c @@ -539,13 +539,9 @@ COMPAT_PCI_DRIVER (stlpci, stlpcidriver); static struct cdevsw stl_cdevsw = { .d_open = stlopen, .d_close = stlclose, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = stlioctl, - .d_poll = ttypoll, .d_name = "stl", .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; #endif diff --git a/sys/ia64/ia64/ssc.c b/sys/ia64/ia64/ssc.c index 551ff0b55288..1f21be121773 100644 --- a/sys/ia64/ia64/ssc.c +++ b/sys/ia64/ia64/ssc.c @@ -60,11 +60,9 @@ static d_ioctl_t sscioctl; static struct cdevsw ssc_cdevsw = { .d_open = sscopen, .d_close = sscclose, - .d_read = ttyread, - .d_write = ttywrite, .d_ioctl = sscioctl, - .d_poll = ttypoll, .d_name = "ssc", + .d_flags = D_TTY, }; static struct tty *ssc_tp = NULL; diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index 62033c7e366a..19592ad56017 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include static MALLOC_DEFINE(M_DEVT, "dev_t", "dev_t storage"); @@ -340,6 +341,13 @@ static void prep_cdevsw(struct cdevsw *devsw) { + if (devsw->d_flags & D_TTY) { + if (devsw->d_read == NULL) devsw->d_read = ttyread; + if (devsw->d_write == NULL) devsw->d_write = ttywrite; + if (devsw->d_kqfilter == NULL) devsw->d_kqfilter = ttykqfilter; + if (devsw->d_poll == NULL) devsw->d_poll = ttypoll; + } + if (devsw->d_open == NULL) devsw->d_open = null_open; if (devsw->d_close == NULL) devsw->d_close = null_close; if (devsw->d_read == NULL) devsw->d_read = no_read; diff --git a/sys/kern/tty.c b/sys/kern/tty.c index a3d8e3546119..65b9607f555d 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1142,7 +1142,11 @@ ttypoll(dev_t dev, int events, struct thread *td) int revents = 0; struct tty *tp; + KASSERT(devsw(dev)->d_flags & D_TTY, + ("ttypoll() called on non D_TTY device (%s)", devtoname(dev))); tp = dev->si_tty; + KASSERT(tp != NULL, + ("ttypoll(): no tty pointer on device (%s)", devtoname(dev))); if (tp == NULL) /* XXX used to return ENXIO, but that means true! */ return ((events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)) | POLLHUP); @@ -1174,10 +1178,15 @@ static struct filterops ttywrite_filtops = int ttykqfilter(dev_t dev, struct knote *kn) { - struct tty *tp = dev->si_tty; + struct tty *tp; struct klist *klist; int s; + KASSERT(devsw(dev)->d_flags & D_TTY, + ("ttykqfilter() called on non D_TTY device (%s)", devtoname(dev))); + tp = dev->si_tty; + KASSERT(tp != NULL, + ("ttykqfilter(): no tty pointer on device (%s)", devtoname(dev))); switch (kn->kn_filter) { case EVFILT_READ: klist = &tp->t_rsel.si_note; @@ -2722,7 +2731,11 @@ ttyread(dev_t dev, struct uio *uio, int flag) { struct tty *tp; + KASSERT(devsw(dev)->d_flags & D_TTY, + ("ttyread() called on non D_TTY device (%s)", devtoname(dev))); tp = dev->si_tty; + KASSERT(tp != NULL, + ("ttyread(): no tty pointer on device (%s)", devtoname(dev))); if (tp == NULL) return (ENODEV); return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); @@ -2733,7 +2746,11 @@ ttywrite(dev_t dev, struct uio *uio, int flag) { struct tty *tp; + KASSERT(devsw(dev)->d_flags & D_TTY, + ("ttywrite() called on non D_TTY device (%s)", devtoname(dev))); tp = dev->si_tty; + KASSERT(tp != NULL, + ("ttywrite(): no tty pointer on device (%s)", devtoname(dev))); if (tp == NULL) return (ENODEV); return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index a01851d905e9..ab3ef5dbf1e4 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -85,11 +85,9 @@ static struct cdevsw pts_cdevsw = { .d_read = ptsread, .d_write = ptswrite, .d_ioctl = ptyioctl, - .d_poll = ttypoll, .d_name = "pts", .d_maj = CDEV_MAJOR_S, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; #define CDEV_MAJOR_C 6 @@ -103,7 +101,6 @@ static struct cdevsw ptc_cdevsw = { .d_name = "ptc", .d_maj = CDEV_MAJOR_C, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; #define BUFSIZ 100 /* Chunk size iomoved to/from user */ diff --git a/sys/pc98/cbus/sio.c b/sys/pc98/cbus/sio.c index 6c865853ddb5..3c309c00a7ea 100644 --- a/sys/pc98/cbus/sio.c +++ b/sys/pc98/cbus/sio.c @@ -421,10 +421,8 @@ static struct cdevsw sio_cdevsw = { .d_read = sioread, .d_write = siowrite, .d_ioctl = sioioctl, - .d_poll = ttypoll, .d_name = sio_driver_name, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; int comconsole = -1; diff --git a/sys/pc98/pc98/sio.c b/sys/pc98/pc98/sio.c index 6c865853ddb5..3c309c00a7ea 100644 --- a/sys/pc98/pc98/sio.c +++ b/sys/pc98/pc98/sio.c @@ -421,10 +421,8 @@ static struct cdevsw sio_cdevsw = { .d_read = sioread, .d_write = siowrite, .d_ioctl = sioioctl, - .d_poll = ttypoll, .d_name = sio_driver_name, .d_flags = D_TTY, - .d_kqfilter = ttykqfilter, }; int comconsole = -1;