Skip to contentSkip to conversation

HID: intel-thc-hid: intel-quicki2c: Fix the return value in quicki2c_dev_init() kernel-doc

PATCH In review Karl Mehltretter 3 participants 3 messages Sep 12

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: intel-thc-hid: intel-quicki2c: Fix the return value in quicki2c_dev_init() kernel-doc

quicki2c_dev_init() returns an ERR_PTR() on failure, but its kernel-doc says that failure returns NULL. This mismatch was present in the original driver skeleton.

Document the error pointer returned by the initialization paths.

Fixes 61bb2714dc3a ("HID: intel-thc-hid: intel-quicki2c: Add THC QuickI2C driver skeleton")
Assisted-by LLM
---
 drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +1 -1
index 0d2ad7bc3648a2f227db2ed27ad9cbe18955bc0f..aa601ef613c91729f4fc90bdc1674cb838921421 100644
@@ -380,7 +380,7 @@ exit:
  * If success, enable THC hardware interrupt.
  *
  * Return: Pointer to the quicki2c_device structure if success
- * or NULL on failure.
+ * or an ERR_PTR() on failure.
  */
 static struct quicki2c_device *quicki2c_dev_init(struct pci_dev *pdev, void __iomem *mem_addr,
 						 const struct quicki2c_ddata *ddata)
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Transport drivers use hid_input_report() instead of the safer hid_safe_input_report() when feeding data from interrupts. --

commit e849f07638d5d777d058d1762033819d3087f020
Author: Karl Mehltretter <[email protected]>

HID: intel-thc-hid: intel-quicki2c: Fix the return value in quicki2c_dev_init() kernel-doc

This commit corrects the kernel-doc for quicki2c_dev_init() to accurately reflect that it returns an ERR_PTR() on failure instead of NULL.

drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c

Quoted 4 lines
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +0 -0
index 0d2ad7bc3648a..aa601ef613c91 100644

[ ... ]

[Severity: High]
This is a pre-existing issue, but does this code in quicki2c_hid_send_report() bypass the HID core's bounds checks?

drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c:quicki2c_hid_send_report() {
    ...
    ret = hid_input_report(qcdev->hid_dev, HID_INPUT_REPORT, data, data_len, 1);
    ...
}

If a malicious or malfunctioning device sends an interrupt with a spoofed length larger than the allocated buffer, the hardware could send an inflated length over DMA. When this is passed as data_len to hid_input_report(), which does not know the actual allocated size of the buffer, could it blindly read data_len bytes and cause an out-of-bounds read in the HID core?

Should this transport driver use hid_safe_input_report() instead when feeding data from interrupts to prevent local memory disclosure or a kernel oops?

This same pattern also appears to exist in the QuickSPI driver:

drivers/hid/intel-thc-hid/intel-quickspi/quickspi-hid.c:quickspi_hid_send_report() {
    ...
    ret = hid_input_report(qsdev->hid_dev, HID_INPUT_REPORT, data, data_len, 1);
    ...
}

Should both of these transport drivers be updated to use the safer hid_safe_input_report() API?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Karl Mehltretter
Quoted 5 lines · Karl Mehltretter

quicki2c_dev_init() returns an ERR_PTR() on failure, but its kernel-doc says that failure returns NULL. This mismatch was present in the original driver skeleton.

Document the error pointer returned by the initialization paths.

...

Quoted 3 lines

* Return: Pointer to the quicki2c_device structure if success
- * or NULL on failure.
+ * or an ERR_PTR() on failure.

" * or an error pointer on failure."

Quoted 1 line

*/

...

The rule of thumb: Among options always choose the one that is less cryptic and uses more plain English.

Signature · 2 lines
With Best Regards,
Andy Shevchenko