mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-09-01 06:39:05 +00:00
HID: wacom: Remove static WACOM_PKGLEN_MAX limit
Rather than memcpy every packet that we receive from HID into our own local fixed-size array, we can just access the data directly through the original pointer. While we're at it, remove the few other places that assume a fixed maximum packet size and make them dynamic (in particular: temporary buffers created by the wacom_wac_queue_flush and wacom_intuos_bt_process_data functions; and the pen_fifo FIFO). To ensure pen_fifo allocation has access to the maximum used packet length, this commit also moves the function call to occur a little later in the probe process. Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
This commit is contained in:
parent
58c9bf3363
commit
5e013ad206
@ -69,16 +69,27 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
|
|||||||
struct kfifo_rec_ptr_2 *fifo)
|
struct kfifo_rec_ptr_2 *fifo)
|
||||||
{
|
{
|
||||||
while (!kfifo_is_empty(fifo)) {
|
while (!kfifo_is_empty(fifo)) {
|
||||||
u8 buf[WACOM_PKGLEN_MAX];
|
int size = kfifo_peek_len(fifo);
|
||||||
int size;
|
u8 *buf = kzalloc(size, GFP_KERNEL);
|
||||||
|
unsigned int count;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
size = kfifo_out(fifo, buf, sizeof(buf));
|
count = kfifo_out(fifo, buf, size);
|
||||||
|
if (count != size) {
|
||||||
|
// Hard to say what is the "right" action in this
|
||||||
|
// circumstance. Skipping the entry and continuing
|
||||||
|
// to flush seems reasonable enough, however.
|
||||||
|
hid_warn(hdev, "%s: removed fifo entry with unexpected size\n",
|
||||||
|
__func__);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
err = hid_report_raw_event(hdev, HID_INPUT_REPORT, buf, size, false);
|
err = hid_report_raw_event(hdev, HID_INPUT_REPORT, buf, size, false);
|
||||||
if (err) {
|
if (err) {
|
||||||
hid_warn(hdev, "%s: unable to flush event due to error %d\n",
|
hid_warn(hdev, "%s: unable to flush event due to error %d\n",
|
||||||
__func__, err);
|
__func__, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kfree(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,13 +169,10 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
|
|||||||
if (wacom->wacom_wac.features.type == BOOTLOADER)
|
if (wacom->wacom_wac.features.type == BOOTLOADER)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (size > WACOM_PKGLEN_MAX)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (wacom_wac_pen_serial_enforce(hdev, report, raw_data, size))
|
if (wacom_wac_pen_serial_enforce(hdev, report, raw_data, size))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memcpy(wacom->wacom_wac.data, raw_data, size);
|
wacom->wacom_wac.data = raw_data;
|
||||||
|
|
||||||
wacom_wac_irq(&wacom->wacom_wac, size);
|
wacom_wac_irq(&wacom->wacom_wac, size);
|
||||||
|
|
||||||
@ -1286,6 +1294,7 @@ static void wacom_devm_kfifo_release(struct device *dev, void *res)
|
|||||||
static int wacom_devm_kfifo_alloc(struct wacom *wacom)
|
static int wacom_devm_kfifo_alloc(struct wacom *wacom)
|
||||||
{
|
{
|
||||||
struct wacom_wac *wacom_wac = &wacom->wacom_wac;
|
struct wacom_wac *wacom_wac = &wacom->wacom_wac;
|
||||||
|
int fifo_size = min(PAGE_SIZE, 10 * wacom_wac->features.pktlen);
|
||||||
struct kfifo_rec_ptr_2 *pen_fifo;
|
struct kfifo_rec_ptr_2 *pen_fifo;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
@ -1296,7 +1305,7 @@ static int wacom_devm_kfifo_alloc(struct wacom *wacom)
|
|||||||
if (!pen_fifo)
|
if (!pen_fifo)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
error = kfifo_alloc(pen_fifo, WACOM_PKGLEN_MAX, GFP_KERNEL);
|
error = kfifo_alloc(pen_fifo, fifo_size, GFP_KERNEL);
|
||||||
if (error) {
|
if (error) {
|
||||||
devres_free(pen_fifo);
|
devres_free(pen_fifo);
|
||||||
return error;
|
return error;
|
||||||
@ -2352,12 +2361,14 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
|
|||||||
unsigned int connect_mask = HID_CONNECT_HIDRAW;
|
unsigned int connect_mask = HID_CONNECT_HIDRAW;
|
||||||
|
|
||||||
features->pktlen = wacom_compute_pktlen(hdev);
|
features->pktlen = wacom_compute_pktlen(hdev);
|
||||||
if (features->pktlen > WACOM_PKGLEN_MAX)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (!devres_open_group(&hdev->dev, wacom, GFP_KERNEL))
|
if (!devres_open_group(&hdev->dev, wacom, GFP_KERNEL))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
error = wacom_devm_kfifo_alloc(wacom);
|
||||||
|
if (error)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
wacom->resources = true;
|
wacom->resources = true;
|
||||||
|
|
||||||
error = wacom_allocate_inputs(wacom);
|
error = wacom_allocate_inputs(wacom);
|
||||||
@ -2821,10 +2832,6 @@ static int wacom_probe(struct hid_device *hdev,
|
|||||||
if (features->check_for_hid_type && features->hid_type != hdev->type)
|
if (features->check_for_hid_type && features->hid_type != hdev->type)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
error = wacom_devm_kfifo_alloc(wacom);
|
|
||||||
if (error)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
wacom_wac->hid_data.inputmode = -1;
|
wacom_wac->hid_data.inputmode = -1;
|
||||||
wacom_wac->mode_report = -1;
|
wacom_wac->mode_report = -1;
|
||||||
|
|
||||||
|
@ -1201,12 +1201,10 @@ static void wacom_intuos_bt_process_data(struct wacom_wac *wacom,
|
|||||||
|
|
||||||
static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
|
static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
|
||||||
{
|
{
|
||||||
unsigned char data[WACOM_PKGLEN_MAX];
|
u8 *data = kmemdup(wacom->data, len, GFP_KERNEL);
|
||||||
int i = 1;
|
int i = 1;
|
||||||
unsigned power_raw, battery_capacity, bat_charging, ps_connected;
|
unsigned power_raw, battery_capacity, bat_charging, ps_connected;
|
||||||
|
|
||||||
memcpy(data, wacom->data, len);
|
|
||||||
|
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case 0x04:
|
case 0x04:
|
||||||
wacom_intuos_bt_process_data(wacom, data + i);
|
wacom_intuos_bt_process_data(wacom, data + i);
|
||||||
@ -1230,8 +1228,10 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
|
|||||||
dev_dbg(wacom->pen_input->dev.parent,
|
dev_dbg(wacom->pen_input->dev.parent,
|
||||||
"Unknown report: %d,%d size:%zu\n",
|
"Unknown report: %d,%d size:%zu\n",
|
||||||
data[0], data[1], len);
|
data[0], data[1], len);
|
||||||
return 0;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kfree(data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,6 @@
|
|||||||
#include <linux/hid.h>
|
#include <linux/hid.h>
|
||||||
#include <linux/kfifo.h>
|
#include <linux/kfifo.h>
|
||||||
|
|
||||||
/* maximum packet length for USB/BT devices */
|
|
||||||
#define WACOM_PKGLEN_MAX 361
|
|
||||||
|
|
||||||
#define WACOM_NAME_MAX 64
|
#define WACOM_NAME_MAX 64
|
||||||
#define WACOM_MAX_REMOTES 5
|
#define WACOM_MAX_REMOTES 5
|
||||||
#define WACOM_STATUS_UNKNOWN 255
|
#define WACOM_STATUS_UNKNOWN 255
|
||||||
@ -277,7 +274,7 @@ struct wacom_features {
|
|||||||
unsigned touch_max;
|
unsigned touch_max;
|
||||||
int oVid;
|
int oVid;
|
||||||
int oPid;
|
int oPid;
|
||||||
int pktlen;
|
unsigned int pktlen;
|
||||||
bool check_for_hid_type;
|
bool check_for_hid_type;
|
||||||
int hid_type;
|
int hid_type;
|
||||||
};
|
};
|
||||||
@ -341,7 +338,7 @@ struct wacom_wac {
|
|||||||
char pen_name[WACOM_NAME_MAX];
|
char pen_name[WACOM_NAME_MAX];
|
||||||
char touch_name[WACOM_NAME_MAX];
|
char touch_name[WACOM_NAME_MAX];
|
||||||
char pad_name[WACOM_NAME_MAX];
|
char pad_name[WACOM_NAME_MAX];
|
||||||
unsigned char data[WACOM_PKGLEN_MAX];
|
u8 *data;
|
||||||
int tool[2];
|
int tool[2];
|
||||||
int id[2];
|
int id[2];
|
||||||
__u64 serial[2];
|
__u64 serial[2];
|
||||||
|
Loading…
Reference in New Issue
Block a user