Commit 76f693f0 authored by Benjamin Tissoires's avatar Benjamin Tissoires Committed by Greg Kroah-Hartman

HID: input: make sure the wheel high resolution multiplier is set

commit d43c17ea upstream.

Some old mice have a tendency to not accept the high resolution multiplier.
They reply with a -EPIPE which was previously ignored.

Force the call to resolution multiplier to be synchronous and actually
check for the answer. If this fails, consider the mouse like a normal one.

Fixes: 2dc702c9 ("HID: input: use the Resolution Multiplier for
       high-resolution scrolling")
Link: https://bugzilla.redhat.com/show_bug.cgi?id=1700071Reported-and-tested-by: default avatarJames Feeney <james@nurealm.net>
Cc: stable@vger.kernel.org  # v5.0+
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2bf61c27
...@@ -1636,7 +1636,7 @@ static struct hid_report *hid_get_report(struct hid_report_enum *report_enum, ...@@ -1636,7 +1636,7 @@ static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
* Implement a generic .request() callback, using .raw_request() * Implement a generic .request() callback, using .raw_request()
* DO NOT USE in hid drivers directly, but through hid_hw_request instead. * DO NOT USE in hid drivers directly, but through hid_hw_request instead.
*/ */
void __hid_request(struct hid_device *hid, struct hid_report *report, int __hid_request(struct hid_device *hid, struct hid_report *report,
int reqtype) int reqtype)
{ {
char *buf; char *buf;
...@@ -1645,7 +1645,7 @@ void __hid_request(struct hid_device *hid, struct hid_report *report, ...@@ -1645,7 +1645,7 @@ void __hid_request(struct hid_device *hid, struct hid_report *report,
buf = hid_alloc_report_buf(report, GFP_KERNEL); buf = hid_alloc_report_buf(report, GFP_KERNEL);
if (!buf) if (!buf)
return; return -ENOMEM;
len = hid_report_len(report); len = hid_report_len(report);
...@@ -1662,8 +1662,11 @@ void __hid_request(struct hid_device *hid, struct hid_report *report, ...@@ -1662,8 +1662,11 @@ void __hid_request(struct hid_device *hid, struct hid_report *report,
if (reqtype == HID_REQ_GET_REPORT) if (reqtype == HID_REQ_GET_REPORT)
hid_input_report(hid, report->type, buf, ret, 0); hid_input_report(hid, report->type, buf, ret, 0);
ret = 0;
out: out:
kfree(buf); kfree(buf);
return ret;
} }
EXPORT_SYMBOL_GPL(__hid_request); EXPORT_SYMBOL_GPL(__hid_request);
......
...@@ -1557,52 +1557,71 @@ static void hidinput_close(struct input_dev *dev) ...@@ -1557,52 +1557,71 @@ static void hidinput_close(struct input_dev *dev)
hid_hw_close(hid); hid_hw_close(hid);
} }
static void hidinput_change_resolution_multipliers(struct hid_device *hid) static bool __hidinput_change_resolution_multipliers(struct hid_device *hid,
struct hid_report *report, bool use_logical_max)
{ {
struct hid_report_enum *rep_enum;
struct hid_report *rep;
struct hid_usage *usage; struct hid_usage *usage;
bool update_needed = false;
int i, j; int i, j;
rep_enum = &hid->report_enum[HID_FEATURE_REPORT]; if (report->maxfield == 0)
list_for_each_entry(rep, &rep_enum->report_list, list) { return false;
bool update_needed = false;
if (rep->maxfield == 0) /*
continue; * If we have more than one feature within this report we
* need to fill in the bits from the others before we can
* overwrite the ones for the Resolution Multiplier.
*/
if (report->maxfield > 1) {
hid_hw_request(hid, report, HID_REQ_GET_REPORT);
hid_hw_wait(hid);
}
/* for (i = 0; i < report->maxfield; i++) {
* If we have more than one feature within this report we __s32 value = use_logical_max ?
* need to fill in the bits from the others before we can report->field[i]->logical_maximum :
* overwrite the ones for the Resolution Multiplier. report->field[i]->logical_minimum;
/* There is no good reason for a Resolution
* Multiplier to have a count other than 1.
* Ignore that case.
*/ */
if (rep->maxfield > 1) { if (report->field[i]->report_count != 1)
hid_hw_request(hid, rep, HID_REQ_GET_REPORT); continue;
hid_hw_wait(hid);
}
for (i = 0; i < rep->maxfield; i++) { for (j = 0; j < report->field[i]->maxusage; j++) {
__s32 logical_max = rep->field[i]->logical_maximum; usage = &report->field[i]->usage[j];
/* There is no good reason for a Resolution if (usage->hid != HID_GD_RESOLUTION_MULTIPLIER)
* Multiplier to have a count other than 1.
* Ignore that case.
*/
if (rep->field[i]->report_count != 1)
continue; continue;
for (j = 0; j < rep->field[i]->maxusage; j++) { *report->field[i]->value = value;
usage = &rep->field[i]->usage[j]; update_needed = true;
}
}
return update_needed;
}
if (usage->hid != HID_GD_RESOLUTION_MULTIPLIER) static void hidinput_change_resolution_multipliers(struct hid_device *hid)
continue; {
struct hid_report_enum *rep_enum;
struct hid_report *rep;
int ret;
*rep->field[i]->value = logical_max; rep_enum = &hid->report_enum[HID_FEATURE_REPORT];
update_needed = true; list_for_each_entry(rep, &rep_enum->report_list, list) {
bool update_needed = __hidinput_change_resolution_multipliers(hid,
rep, true);
if (update_needed) {
ret = __hid_request(hid, rep, HID_REQ_SET_REPORT);
if (ret) {
__hidinput_change_resolution_multipliers(hid,
rep, false);
return;
} }
} }
if (update_needed)
hid_hw_request(hid, rep, HID_REQ_SET_REPORT);
} }
/* refresh our structs */ /* refresh our structs */
......
...@@ -894,7 +894,7 @@ struct hid_field *hidinput_get_led_field(struct hid_device *hid); ...@@ -894,7 +894,7 @@ struct hid_field *hidinput_get_led_field(struct hid_device *hid);
unsigned int hidinput_count_leds(struct hid_device *hid); unsigned int hidinput_count_leds(struct hid_device *hid);
__s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code); __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code);
void hid_output_report(struct hid_report *report, __u8 *data); void hid_output_report(struct hid_report *report, __u8 *data);
void __hid_request(struct hid_device *hid, struct hid_report *rep, int reqtype); int __hid_request(struct hid_device *hid, struct hid_report *rep, int reqtype);
u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags); u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags);
struct hid_device *hid_allocate_device(void); struct hid_device *hid_allocate_device(void);
struct hid_report *hid_register_report(struct hid_device *device, struct hid_report *hid_register_report(struct hid_device *device,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment