@@ -75,16 +75,27 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
7575 struct kfifo_rec_ptr_2 * fifo )
7676{
7777 while (!kfifo_is_empty (fifo )) {
78- u8 buf [WACOM_PKGLEN_MAX ];
79- int size ;
78+ int size = kfifo_peek_len (fifo );
79+ u8 * buf = kzalloc (size , GFP_KERNEL );
80+ unsigned int count ;
8081 int err ;
8182
82- size = kfifo_out (fifo , buf , sizeof (buf ));
83+ count = kfifo_out (fifo , buf , size );
84+ if (count != size ) {
85+ // Hard to say what is the "right" action in this
86+ // circumstance. Skipping the entry and continuing
87+ // to flush seems reasonable enough, however.
88+ hid_warn (hdev , "%s: removed fifo entry with unexpected size\n" ,
89+ __func__ );
90+ continue ;
91+ }
8392 err = hid_report_raw_event (hdev , HID_INPUT_REPORT , buf , size , false);
8493 if (err ) {
8594 hid_warn (hdev , "%s: unable to flush event due to error %d\n" ,
8695 __func__ , err );
8796 }
97+
98+ kfree (buf );
8899 }
89100}
90101
@@ -164,13 +175,10 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
164175 if (wacom -> wacom_wac .features .type == BOOTLOADER )
165176 return 0 ;
166177
167- if (size > WACOM_PKGLEN_MAX )
168- return 1 ;
169-
170178 if (wacom_wac_pen_serial_enforce (hdev , report , raw_data , size ))
171179 return -1 ;
172180
173- memcpy ( wacom -> wacom_wac .data , raw_data , size ) ;
181+ wacom -> wacom_wac .data = raw_data ;
174182
175183 wacom_wac_irq (& wacom -> wacom_wac , size );
176184
@@ -1297,6 +1305,7 @@ static void wacom_devm_kfifo_release(struct device *dev, void *res)
12971305static int wacom_devm_kfifo_alloc (struct wacom * wacom )
12981306{
12991307 struct wacom_wac * wacom_wac = & wacom -> wacom_wac ;
1308+ int fifo_size = min (PAGE_SIZE , 10 * wacom_wac -> features .pktlen );
13001309 struct kfifo_rec_ptr_2 * pen_fifo ;
13011310 int error ;
13021311
@@ -1307,7 +1316,7 @@ static int wacom_devm_kfifo_alloc(struct wacom *wacom)
13071316 if (!pen_fifo )
13081317 return - ENOMEM ;
13091318
1310- error = kfifo_alloc (pen_fifo , WACOM_PKGLEN_MAX , GFP_KERNEL );
1319+ error = kfifo_alloc (pen_fifo , fifo_size , GFP_KERNEL );
13111320 if (error ) {
13121321 devres_free (pen_fifo );
13131322 return error ;
@@ -2369,12 +2378,14 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
23692378 unsigned int connect_mask = HID_CONNECT_HIDRAW ;
23702379
23712380 features -> pktlen = wacom_compute_pktlen (hdev );
2372- if (features -> pktlen > WACOM_PKGLEN_MAX )
2373- return - EINVAL ;
23742381
23752382 if (!devres_open_group (& hdev -> dev , wacom , GFP_KERNEL ))
23762383 return - ENOMEM ;
23772384
2385+ error = wacom_devm_kfifo_alloc (wacom );
2386+ if (error )
2387+ goto fail ;
2388+
23782389 wacom -> resources = true;
23792390
23802391 error = wacom_allocate_inputs (wacom );
@@ -2838,10 +2849,6 @@ static int wacom_probe(struct hid_device *hdev,
28382849 if (features -> check_for_hid_type && features -> hid_type != hdev -> type )
28392850 return - ENODEV ;
28402851
2841- error = wacom_devm_kfifo_alloc (wacom );
2842- if (error )
2843- return error ;
2844-
28452852 wacom_wac -> hid_data .inputmode = -1 ;
28462853 wacom_wac -> mode_report = -1 ;
28472854
0 commit comments