@@ -60,27 +60,41 @@ static void wacom_wac_queue_insert(struct hid_device *hdev,
6060{
6161 bool warned = false;
6262
63- while (kfifo_avail (fifo ) < size ) {
63+ while (kfifo_avail (fifo ) < size && ! kfifo_is_empty ( fifo ) ) {
6464 if (!warned )
6565 hid_warn (hdev , "%s: kfifo has filled, starting to drop events\n" , __func__ );
6666 warned = true;
6767
6868 kfifo_skip (fifo );
6969 }
7070
71+ #ifdef WACOM_HID_WARN_RATELIMITED
72+ if (!kfifo_in (fifo , raw_data , size ))
73+ hid_warn_ratelimited (hdev , "%s: report is too large (%d)\n" ,
74+ __func__ , size );
75+ #else
7176 kfifo_in (fifo , raw_data , size );
77+ #endif
7278}
7379
7480static void wacom_wac_queue_flush (struct hid_device * hdev ,
7581 struct kfifo_rec_ptr_2 * fifo )
7682{
7783 while (!kfifo_is_empty (fifo )) {
7884 int size = kfifo_peek_len (fifo );
85+ #ifdef WACOM_CLEANUP_FREE
86+ u8 * buf __free (kfree ) = kzalloc (size , GFP_ATOMIC );
87+ #else
7988 u8 * buf ;
89+ #endif
8090 unsigned int count ;
8191 int err ;
8292
83- buf = kzalloc (size , GFP_KERNEL );
93+ #ifdef WACOM_CLEANUP_FREE
94+ #else
95+ buf = kzalloc (size , GFP_ATOMIC );
96+ #endif
97+
8498 if (!buf ) {
8599 kfifo_skip (fifo );
86100 continue ;
@@ -91,9 +105,12 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
91105 // Hard to say what is the "right" action in this
92106 // circumstance. Skipping the entry and continuing
93107 // to flush seems reasonable enough, however.
94- hid_warn (hdev , "%s: removed fifo entry with unexpected size\n" ,
108+ hid_warn (hdev , "%s: removed fifo entry with unexpected size\n" ,
95109 __func__ );
110+ #ifdef WACOM_CLEANUP_FREE
111+ #else
96112 kfree (buf );
113+ #endif
97114 continue ;
98115 }
99116#ifdef WACOM_HID_REPORT_RAW_EVENT_BUFSIZE
@@ -105,8 +122,10 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
105122 hid_warn (hdev , "%s: unable to flush event due to error %d\n" ,
106123 __func__ , err );
107124 }
108-
125+ #ifdef WACOM_CLEANUP_FREE
126+ #else
109127 kfree (buf );
128+ #endif
110129 }
111130}
112131
@@ -371,6 +390,7 @@ static void wacom_feature_mapping(struct hid_device *hdev,
371390
372391 hid_data -> inputmode = field -> report -> id ;
373392 hid_data -> inputmode_index = usage -> usage_index ;
393+ hid_data -> inputmode_field_index = field -> index ;
374394 break ;
375395
376396 case HID_UP_DIGITIZER :
@@ -591,9 +611,14 @@ static int wacom_hid_set_device_mode(struct hid_device *hdev)
591611
592612 re = & (hdev -> report_enum [HID_FEATURE_REPORT ]);
593613 r = re -> report_id_hash [hid_data -> inputmode ];
594- if (r ) {
595- r -> field [0 ]-> value [hid_data -> inputmode_index ] = 2 ;
596- hid_hw_request (hdev , r , HID_REQ_SET_REPORT );
614+ if (r && hid_data -> inputmode_field_index >= 0 &&
615+ hid_data -> inputmode_field_index < r -> maxfield ) {
616+ struct hid_field * field = r -> field [hid_data -> inputmode_field_index ];
617+
618+ if (field && hid_data -> inputmode_index < field -> report_count ) {
619+ field -> value [hid_data -> inputmode_index ] = 2 ;
620+ hid_hw_request (hdev , r , HID_REQ_SET_REPORT );
621+ }
597622 }
598623 return 0 ;
599624}
@@ -928,7 +953,11 @@ static int wacom_add_shared_data(struct hid_device *hdev)
928953
929954 data = wacom_get_hdev_data (hdev );
930955 if (!data ) {
956+ #ifdef WACOM_KZALLOC_OBJ
957+ data = kzalloc_obj (struct wacom_hdev_data );
958+ #else
931959 data = kzalloc (sizeof (struct wacom_hdev_data ), GFP_KERNEL );
960+ #endif
932961 if (!data ) {
933962 mutex_unlock (& wacom_udev_list_lock );
934963 return - ENOMEM ;
@@ -2487,16 +2516,16 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
24872516
24882517 error = wacom_register_inputs (wacom );
24892518 if (error )
2490- goto fail ;
2519+ goto fail_hw_stop ;
24912520
24922521 if (wacom -> wacom_wac .features .device_type & WACOM_DEVICETYPE_PAD ) {
24932522 error = wacom_initialize_leds (wacom );
24942523 if (error )
2495- goto fail ;
2524+ goto fail_hw_stop ;
24962525
24972526 error = wacom_initialize_remotes (wacom );
24982527 if (error )
2499- goto fail ;
2528+ goto fail_hw_stop ;
25002529 }
25012530
25022531 if (!wireless ) {
@@ -2510,14 +2539,14 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
25102539 cancel_delayed_work_sync (& wacom -> init_work );
25112540 _wacom_query_tablet_data (wacom );
25122541 error = - ENODEV ;
2513- goto fail_quirks ;
2542+ goto fail_hw_stop ;
25142543 }
25152544
25162545 if (features -> device_type & WACOM_DEVICETYPE_WL_MONITOR ) {
25172546 error = hid_hw_open (hdev );
25182547 if (error ) {
25192548 hid_err (hdev , "hw open failed\n" );
2520- goto fail_quirks ;
2549+ goto fail_hw_stop ;
25212550 }
25222551 }
25232552
@@ -2526,7 +2555,7 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
25262555
25272556 return 0 ;
25282557
2529- fail_quirks :
2558+ fail_hw_stop :
25302559 hid_hw_stop (hdev );
25312560fail :
25322561 wacom_release_resources (wacom );
@@ -2877,6 +2906,7 @@ static int wacom_probe(struct hid_device *hdev,
28772906 return - ENODEV ;
28782907
28792908 wacom_wac -> hid_data .inputmode = -1 ;
2909+ wacom_wac -> hid_data .inputmode_field_index = -1 ;
28802910 wacom_wac -> mode_report = -1 ;
28812911
28822912 if (wacom_is_using_usb_driver (hdev )) {
0 commit comments