@@ -69,16 +69,27 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
69
69
struct kfifo_rec_ptr_2 * fifo )
70
70
{
71
71
while (!kfifo_is_empty (fifo )) {
72
- u8 buf [WACOM_PKGLEN_MAX ];
73
- int size ;
72
+ int size = kfifo_peek_len (fifo );
73
+ u8 * buf = kzalloc (size , GFP_KERNEL );
74
+ unsigned int count ;
74
75
int err ;
75
76
76
- size = kfifo_out (fifo , buf , sizeof (buf ));
77
+ count = kfifo_out (fifo , buf , size );
78
+ if (count != size ) {
79
+ // Hard to say what is the "right" action in this
80
+ // circumstance. Skipping the entry and continuing
81
+ // to flush seems reasonable enough, however.
82
+ hid_warn (hdev , "%s: removed fifo entry with unexpected size\n" ,
83
+ __func__ );
84
+ continue ;
85
+ }
77
86
err = hid_report_raw_event (hdev , HID_INPUT_REPORT , buf , size , false);
78
87
if (err ) {
79
88
hid_warn (hdev , "%s: unable to flush event due to error %d\n" ,
80
89
__func__ , err );
81
90
}
91
+
92
+ kfree (buf );
82
93
}
83
94
}
84
95
@@ -158,13 +169,10 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
158
169
if (wacom -> wacom_wac .features .type == BOOTLOADER )
159
170
return 0 ;
160
171
161
- if (size > WACOM_PKGLEN_MAX )
162
- return 1 ;
163
-
164
172
if (wacom_wac_pen_serial_enforce (hdev , report , raw_data , size ))
165
173
return -1 ;
166
174
167
- memcpy ( wacom -> wacom_wac .data , raw_data , size ) ;
175
+ wacom -> wacom_wac .data = raw_data ;
168
176
169
177
wacom_wac_irq (& wacom -> wacom_wac , size );
170
178
@@ -1286,6 +1294,7 @@ static void wacom_devm_kfifo_release(struct device *dev, void *res)
1286
1294
static int wacom_devm_kfifo_alloc (struct wacom * wacom )
1287
1295
{
1288
1296
struct wacom_wac * wacom_wac = & wacom -> wacom_wac ;
1297
+ int fifo_size = min (PAGE_SIZE , 10 * wacom_wac -> features .pktlen );
1289
1298
struct kfifo_rec_ptr_2 * pen_fifo ;
1290
1299
int error ;
1291
1300
@@ -1296,7 +1305,7 @@ static int wacom_devm_kfifo_alloc(struct wacom *wacom)
1296
1305
if (!pen_fifo )
1297
1306
return - ENOMEM ;
1298
1307
1299
- error = kfifo_alloc (pen_fifo , WACOM_PKGLEN_MAX , GFP_KERNEL );
1308
+ error = kfifo_alloc (pen_fifo , fifo_size , GFP_KERNEL );
1300
1309
if (error ) {
1301
1310
devres_free (pen_fifo );
1302
1311
return error ;
@@ -2352,12 +2361,14 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
2352
2361
unsigned int connect_mask = HID_CONNECT_HIDRAW ;
2353
2362
2354
2363
features -> pktlen = wacom_compute_pktlen (hdev );
2355
- if (features -> pktlen > WACOM_PKGLEN_MAX )
2356
- return - EINVAL ;
2357
2364
2358
2365
if (!devres_open_group (& hdev -> dev , wacom , GFP_KERNEL ))
2359
2366
return - ENOMEM ;
2360
2367
2368
+ error = wacom_devm_kfifo_alloc (wacom );
2369
+ if (error )
2370
+ goto fail ;
2371
+
2361
2372
wacom -> resources = true;
2362
2373
2363
2374
error = wacom_allocate_inputs (wacom );
@@ -2821,10 +2832,6 @@ static int wacom_probe(struct hid_device *hdev,
2821
2832
if (features -> check_for_hid_type && features -> hid_type != hdev -> type )
2822
2833
return - ENODEV ;
2823
2834
2824
- error = wacom_devm_kfifo_alloc (wacom );
2825
- if (error )
2826
- return error ;
2827
-
2828
2835
wacom_wac -> hid_data .inputmode = -1 ;
2829
2836
wacom_wac -> mode_report = -1 ;
2830
2837
0 commit comments