Sun Sep 26 15:07:17 2021 UTC ()
Use seltrue_filtops rather than rolling our own with filt_seltrue.


(thorpej)
diff -r1.118 -r1.119 src/sys/dev/usb/uhid.c

cvs diff -r1.118 -r1.119 src/sys/dev/usb/uhid.c (expand / switch to unified diff)

--- src/sys/dev/usb/uhid.c 2021/09/26 01:16:09 1.118
+++ src/sys/dev/usb/uhid.c 2021/09/26 15:07:17 1.119
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: uhid.c,v 1.118 2021/09/26 01:16:09 thorpej Exp $ */ 1/* $NetBSD: uhid.c,v 1.119 2021/09/26 15:07:17 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2004, 2008, 2012 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2004, 2008, 2012 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 and Matthew R. Green (mrg@eterna.com.au). 9 * Carlstedt Research & Technology and Matthew R. Green (mrg@eterna.com.au).
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: uhid.c,v 1.118 2021/09/26 01:16:09 thorpej Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.119 2021/09/26 15:07:17 thorpej Exp $");
39 39
40#ifdef _KERNEL_OPT 40#ifdef _KERNEL_OPT
41#include "opt_compat_netbsd.h" 41#include "opt_compat_netbsd.h"
42#include "opt_usb.h" 42#include "opt_usb.h"
43#endif 43#endif
44 44
45#include <sys/param.h> 45#include <sys/param.h>
46#include <sys/types.h> 46#include <sys/types.h>
47 47
48#include <sys/atomic.h> 48#include <sys/atomic.h>
49#include <sys/compat_stub.h> 49#include <sys/compat_stub.h>
50#include <sys/conf.h> 50#include <sys/conf.h>
51#include <sys/device.h> 51#include <sys/device.h>
@@ -852,51 +852,44 @@ filt_uhidread(struct knote *kn, long hin @@ -852,51 +852,44 @@ filt_uhidread(struct knote *kn, long hin
852 else 852 else
853 mutex_exit(&sc->sc_lock); 853 mutex_exit(&sc->sc_lock);
854 854
855 return kn->kn_data > 0; 855 return kn->kn_data > 0;
856} 856}
857 857
858static const struct filterops uhidread_filtops = { 858static const struct filterops uhidread_filtops = {
859 .f_flags = FILTEROP_ISFD, 859 .f_flags = FILTEROP_ISFD,
860 .f_attach = NULL, 860 .f_attach = NULL,
861 .f_detach = filt_uhidrdetach, 861 .f_detach = filt_uhidrdetach,
862 .f_event = filt_uhidread, 862 .f_event = filt_uhidread,
863}; 863};
864 864
865static const struct filterops uhid_seltrue_filtops = { 
866 .f_flags = FILTEROP_ISFD, 
867 .f_attach = NULL, 
868 .f_detach = filt_uhidrdetach, 
869 .f_event = filt_seltrue, 
870}; 
871 
872static int 865static int
873uhidkqfilter(dev_t dev, struct knote *kn) 866uhidkqfilter(dev_t dev, struct knote *kn)
874{ 867{
875 struct uhid_softc *sc; 868 struct uhid_softc *sc;
876 int error; 869 int error;
877 870
878 error = uhid_enter(dev, &sc); 871 error = uhid_enter(dev, &sc);
879 if (error) 872 if (error)
880 return error; 873 return error;
881 874
882 switch (kn->kn_filter) { 875 switch (kn->kn_filter) {
883 case EVFILT_READ: 876 case EVFILT_READ:
884 kn->kn_fop = &uhidread_filtops; 877 kn->kn_fop = &uhidread_filtops;
 878 kn->kn_hook = sc;
 879 mutex_enter(&sc->sc_lock);
 880 selrecord_knote(&sc->sc_rsel, kn);
 881 mutex_exit(&sc->sc_lock);
885 break; 882 break;
 883
886 case EVFILT_WRITE: 884 case EVFILT_WRITE:
887 kn->kn_fop = &uhid_seltrue_filtops; 885 kn->kn_fop = &seltrue_filtops;
888 break; 886 break;
 887
889 default: 888 default:
890 error = EINVAL; 889 error = EINVAL;
891 goto out; 890 goto out;
892 } 891 }
893 892
894 kn->kn_hook = sc; 
895 
896 mutex_enter(&sc->sc_lock); 
897 selrecord_knote(&sc->sc_rsel, kn); 
898 mutex_exit(&sc->sc_lock); 
899 
900out: uhid_exit(sc); 893out: uhid_exit(sc);
901 return error; 894 return error;
902} 895}