On Fri, May 10, 2013 at 10:35 -0700, Matthew Dempsky wrote:
> On Fri, May 10, 2013 at 6:02 AM, Mike Belopuhov <[email protected]> wrote:
> > my intention here is very simple: there's a way you should call
> > device_lookup and everyone has to fulfill it's part of the contract.
> > all our devices do, vscsi doesn't.  what's the reason for it to be
> > one of a kind?
> 
> I'm ok with adding a check, though I don't think it should really be
> necessary either.
> 
> Just a thought: What about adding them as KASSERT()s?
> 

i don't have a strong opinion about that.

> Why doesn't your diff include vscsiclose()?

missed it.

diff --git sys/dev/vscsi.c sys/dev/vscsi.c
index 3da371c..a8f2c5b 100644
--- sys/dev/vscsi.c
+++ sys/dev/vscsi.c
@@ -296,6 +296,9 @@ vscsiioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, 
struct proc *p)
        int                             read = 0;
        int                             err = 0;
 
+       if (sc == NULL)
+               return (ENXIO);
+
        rw_enter_write(&sc->sc_ioc_lock);
 
        switch (cmd) {
@@ -476,6 +479,9 @@ vscsipoll(dev_t dev, int events, struct proc *p)
        struct vscsi_softc              *sc = DEV2SC(dev);
        int                             revents = 0;
 
+       if (sc == NULL)
+               return (ENXIO);
+
        if (events & (POLLIN | POLLRDNORM)) {
                mtx_enter(&sc->sc_state_mtx);
                if (!TAILQ_EMPTY(&sc->sc_ccb_i2t))
@@ -494,9 +500,14 @@ vscsipoll(dev_t dev, int events, struct proc *p)
 
 int
 vscsikqfilter(dev_t dev, struct knote *kn)
-{ 
+{
        struct vscsi_softc *sc = DEV2SC(dev);
-       struct klist *klist = &sc->sc_sel.si_note;
+       struct klist *klist;
+
+       if (sc == NULL)
+               return (ENXIO);
+
+       klist = &sc->sc_sel.si_note;
 
        switch (kn->kn_filter) {
        case EVFILT_READ:
@@ -548,6 +559,9 @@ vscsiclose(dev_t dev, int flags, int mode, struct proc *p)
        struct vscsi_softc              *sc = DEV2SC(dev);
        struct vscsi_ccb                *ccb;
 
+       if (sc == NULL)
+               return (ENXIO);
+
        mtx_enter(&sc->sc_state_mtx);
        KASSERT(sc->sc_state == VSCSI_S_RUNNING);
        sc->sc_state = VSCSI_S_CONFIG;

Reply via email to