Skip to content

Commit 5abfe85

Browse files
bentissJiri Kosina
authored andcommitted
HID: logitech-dj: prevent false errors to be shown
Commit "HID: logitech: perform bounds checking on device_id early enough" unfortunately leaks some errors to dmesg which are not real ones: - if the report is not a DJ one, then there is not point in checking the device_id - the receiver (index 0) can also receive some notifications which can be safely ignored given the current implementation Move out the test regarding the report_id and also discards printing errors when the receiver got notified. Fixes: ad3e14d Cc: [email protected] Reported-and-tested-by: Markus Trippelsdorf <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 4ab2578 commit 5abfe85

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

drivers/hid/hid-logitech-dj.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,6 @@ static int logi_dj_raw_event(struct hid_device *hdev,
656656
struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
657657
struct dj_report *dj_report = (struct dj_report *) data;
658658
unsigned long flags;
659-
bool report_processed = false;
660659

661660
dbg_hid("%s, size:%d\n", __func__, size);
662661

@@ -683,34 +682,42 @@ static int logi_dj_raw_event(struct hid_device *hdev,
683682
* device (via hid_input_report() ) and return 1 so hid-core does not do
684683
* anything else with it.
685684
*/
685+
686+
/* case 1) */
687+
if (data[0] != REPORT_ID_DJ_SHORT)
688+
return false;
689+
686690
if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
687691
(dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
688-
dev_err(&hdev->dev, "%s: invalid device index:%d\n",
692+
/*
693+
* Device index is wrong, bail out.
694+
* This driver can ignore safely the receiver notifications,
695+
* so ignore those reports too.
696+
*/
697+
if (dj_report->device_index != DJ_RECEIVER_INDEX)
698+
dev_err(&hdev->dev, "%s: invalid device index:%d\n",
689699
__func__, dj_report->device_index);
690700
return false;
691701
}
692702

693703
spin_lock_irqsave(&djrcv_dev->lock, flags);
694-
if (dj_report->report_id == REPORT_ID_DJ_SHORT) {
695-
switch (dj_report->report_type) {
696-
case REPORT_TYPE_NOTIF_DEVICE_PAIRED:
697-
case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED:
698-
logi_dj_recv_queue_notification(djrcv_dev, dj_report);
699-
break;
700-
case REPORT_TYPE_NOTIF_CONNECTION_STATUS:
701-
if (dj_report->report_params[CONNECTION_STATUS_PARAM_STATUS] ==
702-
STATUS_LINKLOSS) {
703-
logi_dj_recv_forward_null_report(djrcv_dev, dj_report);
704-
}
705-
break;
706-
default:
707-
logi_dj_recv_forward_report(djrcv_dev, dj_report);
704+
switch (dj_report->report_type) {
705+
case REPORT_TYPE_NOTIF_DEVICE_PAIRED:
706+
case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED:
707+
logi_dj_recv_queue_notification(djrcv_dev, dj_report);
708+
break;
709+
case REPORT_TYPE_NOTIF_CONNECTION_STATUS:
710+
if (dj_report->report_params[CONNECTION_STATUS_PARAM_STATUS] ==
711+
STATUS_LINKLOSS) {
712+
logi_dj_recv_forward_null_report(djrcv_dev, dj_report);
708713
}
709-
report_processed = true;
714+
break;
715+
default:
716+
logi_dj_recv_forward_report(djrcv_dev, dj_report);
710717
}
711718
spin_unlock_irqrestore(&djrcv_dev->lock, flags);
712719

713-
return report_processed;
720+
return true;
714721
}
715722

716723
static int logi_dj_probe(struct hid_device *hdev,

drivers/hid/hid-logitech-dj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#define DJ_MAX_PAIRED_DEVICES 6
2929
#define DJ_MAX_NUMBER_NOTIFICATIONS 8
30+
#define DJ_RECEIVER_INDEX 0
3031
#define DJ_DEVICE_INDEX_MIN 1
3132
#define DJ_DEVICE_INDEX_MAX 6
3233

0 commit comments

Comments
 (0)