Sat Jan 25 00:03:14 2014 UTC ()
close uhidev only when it was successfully opened.


(mlelstv)
diff -r1.86 -r1.87 src/sys/dev/usb/ums.c

cvs diff -r1.86 -r1.87 src/sys/dev/usb/ums.c (expand / switch to unified diff)

--- src/sys/dev/usb/ums.c 2013/01/05 23:34:19 1.86
+++ src/sys/dev/usb/ums.c 2014/01/25 00:03:14 1.87
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ums.c,v 1.86 2013/01/05 23:34:19 christos Exp $ */ 1/* $NetBSD: ums.c,v 1.87 2014/01/25 00:03:14 mlelstv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net) at 8 * by Lennart Augustsson (lennart@augustsson.net) at
9 * Carlstedt Research & Technology. 9 * Carlstedt Research & Technology.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf 34 * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.86 2013/01/05 23:34:19 christos Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.87 2014/01/25 00:03:14 mlelstv Exp $");
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/kernel.h> 42#include <sys/kernel.h>
43#include <sys/malloc.h> 43#include <sys/malloc.h>
44#include <sys/device.h> 44#include <sys/device.h>
45#include <sys/ioctl.h> 45#include <sys/ioctl.h>
46#include <sys/file.h> 46#include <sys/file.h>
47#include <sys/select.h> 47#include <sys/select.h>
48#include <sys/proc.h> 48#include <sys/proc.h>
49#include <sys/vnode.h> 49#include <sys/vnode.h>
50#include <sys/poll.h> 50#include <sys/poll.h>
51 51
@@ -448,56 +448,63 @@ ums_intr(struct uhidev *addr, void *ibuf @@ -448,56 +448,63 @@ ums_intr(struct uhidev *addr, void *ibuf
448 if (sc->sc_wsmousedev != NULL) { 448 if (sc->sc_wsmousedev != NULL) {
449 s = spltty(); 449 s = spltty();
450 wsmouse_input(sc->sc_wsmousedev, buttons, dx, dy, dz, 450 wsmouse_input(sc->sc_wsmousedev, buttons, dx, dy, dz,
451 dw, flags); 451 dw, flags);
452 splx(s); 452 splx(s);
453 } 453 }
454 } 454 }
455} 455}
456 456
457Static int 457Static int
458ums_enable(void *v) 458ums_enable(void *v)
459{ 459{
460 struct ums_softc *sc = v; 460 struct ums_softc *sc = v;
 461 int error;
461 462
462 DPRINTFN(1,("ums_enable: sc=%p\n", sc)); 463 DPRINTFN(1,("ums_enable: sc=%p\n", sc));
463 464
464 if (sc->sc_dying) 465 if (sc->sc_dying)
465 return (EIO); 466 return (EIO);
466 467
467 if (sc->sc_enabled) 468 if (sc->sc_enabled)
468 return (EBUSY); 469 return (EBUSY);
469 470
470 sc->sc_enabled = 1; 471 sc->sc_enabled = 1;
471 sc->sc_buttons = 0; 472 sc->sc_buttons = 0;
472 473
473 return (uhidev_open(&sc->sc_hdev)); 474 error = uhidev_open(&sc->sc_hdev);
 475 if (error)
 476 sc->sc_enabled = 0;
 477
 478 return error;
474} 479}
475 480
476Static void 481Static void
477ums_disable(void *v) 482ums_disable(void *v)
478{ 483{
479 struct ums_softc *sc = v; 484 struct ums_softc *sc = v;
480 485
481 DPRINTFN(1,("ums_disable: sc=%p\n", sc)); 486 DPRINTFN(1,("ums_disable: sc=%p\n", sc));
482#ifdef DIAGNOSTIC 487#ifdef DIAGNOSTIC
483 if (!sc->sc_enabled) { 488 if (!sc->sc_enabled) {
484 printf("ums_disable: not enabled\n"); 489 printf("ums_disable: not enabled\n");
485 return; 490 return;
486 } 491 }
487#endif 492#endif
488 493
489 sc->sc_enabled = 0; 494 if (sc->sc_enabled) {
490 uhidev_close(&sc->sc_hdev); 495 sc->sc_enabled = 0;
 496 uhidev_close(&sc->sc_hdev);
 497 }
491} 498}
492 499
493Static int 500Static int
494ums_ioctl(void *v, u_long cmd, void *data, int flag, 501ums_ioctl(void *v, u_long cmd, void *data, int flag,
495 struct lwp * p) 502 struct lwp * p)
496 503
497{ 504{
498 struct ums_softc *sc = v; 505 struct ums_softc *sc = v;
499 506
500 switch (cmd) { 507 switch (cmd) {
501 case WSMOUSEIO_GTYPE: 508 case WSMOUSEIO_GTYPE:
502 if (sc->flags & UMS_ABS) 509 if (sc->flags & UMS_ABS)
503 *(u_int *)data = WSMOUSE_TYPE_TPANEL; 510 *(u_int *)data = WSMOUSE_TYPE_TPANEL;