Subject: minor kqueue bug?
To: None <tech-kern@netbsd.org>
From: Emmanuel Dreyfus <manu@netbsd.org>
List: tech-kern
Date: 09/21/2003 15:49:56
Hi

In src/sys/kern/kern_tty.c:ttykqfilter()

        cdev = cdevsw_lookup(dev);
        if (cdev == NULL)
                return (ENXIO);
        tp = (*cdev->d_tty)(dev);


I see no reason for (*cdev->d_tty)() to always return a tty. 

For now if a wsscreen has no tty attached, it will return a garbage
pointer, I'm working on a patch to fix that, but of course then
(*cdev->d_tty)() will return NULL. Therefore I'd suggest this: 

        if (((cdev = cdevsw_lookup(dev)) == NULL) ||
            ((tp = (*cdev->d_tty)(dev)) == NULL)))  
                return (ENXIO);

What do you think? It could be inappropriate if you can assume that
ttykqfilter will never be called for an unallocated wsscreen, but is it
the case?

Additionnally, shouldn't we check (cdev->d_tty != NULL)? Is d_tty
mandatory for any character device? If it's not, we would do this:

        if (((cdev = cdevsw_lookup(dev)) == NULL) ||
            ((cdev->d_tty == NULL)) ||
            ((tp = (*cdev->d_tty)(dev)) == NULL)))  
                return (ENXIO);

-- 
Emmanuel Dreyfus
Il y a 10 sortes de personnes dans le monde: ceux qui comprennent 
le binaire et ceux qui ne le comprennent pas.
manu@netbsd.org