Skip to content

Commit 1430ee7

Browse files
LekensteynJiri Kosina
authored andcommitted
HID: logitech-hidpp: check name retrieval return code
hidpp_devicenametype_get_device_name() may return a negative value on protocol errors (for example, when the device is powered off). Explicitly check this condition to avoid a long-running loop. (0 cannot be returned as __name_length - index > 0, but check for it anyway as it would otherwise result in an infinite loop.) Signed-off-by: Peter Wu <[email protected]> Reviewed-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 02cc097 commit 1430ee7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/hid/hid-logitech-hidpp.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,16 @@ static char *hidpp_get_device_name(struct hidpp_device *hidpp)
484484
if (!name)
485485
return NULL;
486486

487-
while (index < __name_length)
488-
index += hidpp_devicenametype_get_device_name(hidpp,
487+
while (index < __name_length) {
488+
ret = hidpp_devicenametype_get_device_name(hidpp,
489489
feature_index, index, name + index,
490490
__name_length - index);
491+
if (ret <= 0) {
492+
kfree(name);
493+
return NULL;
494+
}
495+
index += ret;
496+
}
491497

492498
return name;
493499
}

0 commit comments

Comments
 (0)