diff options
author | hselasky <hselasky@FreeBSD.org> | 2014-10-03 16:09:46 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2014-10-03 16:09:46 +0000 |
commit | 4e6d53a2d7a84302ed17d387112456b16ab657b4 (patch) | |
tree | a130c89225a5187f1fdec4a0b4a3e9a9dc6ef830 | |
parent | de588ec5bedb67975b367a4b0c79f0c5f612eb64 (diff) | |
download | FreeBSD-src-4e6d53a2d7a84302ed17d387112456b16ab657b4.zip FreeBSD-src-4e6d53a2d7a84302ed17d387112456b16ab657b4.tar.gz |
When we fail to get a USB reference we should just return, because
there are no more references held.
MFC after: 3 days
-rw-r--r-- | sys/dev/usb/usb_dev.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/sys/dev/usb/usb_dev.c b/sys/dev/usb/usb_dev.c index 3960673..2dad2bd 100644 --- a/sys/dev/usb/usb_dev.c +++ b/sys/dev/usb/usb_dev.c @@ -298,6 +298,10 @@ error: } mtx_unlock(&usb_ref_lock); DPRINTFN(2, "fail\n"); + + /* clear all refs */ + memset(crd, 0, sizeof(*crd)); + return (USB_ERR_INVAL); } @@ -1093,8 +1097,8 @@ usb_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int fflag, struct thread* goto done; if (usb_usb_ref_device(cpd, &refs)) { - err = ENXIO; - goto done; + /* we lost the reference */ + return (ENXIO); } err = (f->methods->f_ioctl_post) (f, cmd, addr, fflags); @@ -1117,9 +1121,8 @@ usb_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int fflag, struct thread* while (usb_ref_device(cpd, &refs, 1 /* need uref */)) { if (usb_ref_device(cpd, &refs, 0)) { - /* device no longer exits */ - err = ENXIO; - goto done; + /* device no longer exists */ + return (ENXIO); } usb_unref_device(cpd, &refs); usb_pause_mtx(NULL, hz / 128); @@ -1411,9 +1414,9 @@ usb_read(struct cdev *dev, struct uio *uio, int ioflag) return (err); err = usb_ref_device(cpd, &refs, 0 /* no uref */ ); - if (err) { + if (err) return (ENXIO); - } + fflags = cpd->fflags; f = refs.rxfifo; @@ -1537,9 +1540,9 @@ usb_write(struct cdev *dev, struct uio *uio, int ioflag) return (err); err = usb_ref_device(cpd, &refs, 0 /* no uref */ ); - if (err) { + if (err) return (ENXIO); - } + fflags = cpd->fflags; f = refs.txfifo; |