Skip to content

Commit 5c2ebb1

Browse files
committed
Merge branch 'for-6.15' into 'master'
2 parents 5024945 + e72dc4b commit 5c2ebb1

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

4.18/wacom_sys.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
12971305
static 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

4.18/wacom_wac.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,12 +1213,10 @@ static void wacom_intuos_bt_process_data(struct wacom_wac *wacom,
12131213

12141214
static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
12151215
{
1216-
unsigned char data[WACOM_PKGLEN_MAX];
1216+
u8 *data = kmemdup(wacom->data, len, GFP_KERNEL);
12171217
int i = 1;
12181218
unsigned power_raw, battery_capacity, bat_charging, ps_connected;
12191219

1220-
memcpy(data, wacom->data, len);
1221-
12221220
switch (data[0]) {
12231221
case 0x04:
12241222
wacom_intuos_bt_process_data(wacom, data + i);
@@ -1242,8 +1240,10 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
12421240
dev_dbg(wacom->pen_input->dev.parent,
12431241
"Unknown report: %d,%d size:%zu\n",
12441242
data[0], data[1], len);
1245-
return 0;
1243+
break;
12461244
}
1245+
1246+
kfree(data);
12471247
return 0;
12481248
}
12491249

4.18/wacom_wac.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#include <linux/kfifo.h>
1111
#include <linux/version.h>
1212

13-
/* maximum packet length for USB/BT devices */
14-
#define WACOM_PKGLEN_MAX 361
15-
1613
#define WACOM_NAME_MAX 64
1714
#define WACOM_MAX_REMOTES 5
1815
#define WACOM_STATUS_UNKNOWN 255
@@ -304,7 +301,7 @@ struct wacom_features {
304301
unsigned touch_max;
305302
int oVid;
306303
int oPid;
307-
int pktlen;
304+
unsigned int pktlen;
308305
bool check_for_hid_type;
309306
int hid_type;
310307
};
@@ -370,7 +367,7 @@ struct wacom_wac {
370367
char pen_name[WACOM_NAME_MAX];
371368
char touch_name[WACOM_NAME_MAX];
372369
char pad_name[WACOM_NAME_MAX];
373-
unsigned char data[WACOM_PKGLEN_MAX];
370+
u8 *data;
374371
int tool[2];
375372
int id[2];
376373
__u64 serial[2];

0 commit comments

Comments
 (0)