From 7668cef283864085203848eb486b1e1de4debb68 Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Mon, 19 Jun 2023 14:41:36 +0100 Subject: [PATCH] ANDROID: HID: Only utilise UHID provided exports if UHID is enabled Commit "ANDROID: HID; Over-ride default maximum buffer size when using UHID" provided a means for the UHID driver to offer an alternative (smaller) report buffer size when dealing with user-space. The method used was an Android-only solution designed to prevent the KMI ABI from being broken (nb: the upstream solution was cleaner, but broke the ABI). Since this solution involved consuming resources exported by a subordinate driver, that driver would have to be enabled for the export to take place. Since all of our default configs enable UHID, an issue was not detected. However, for more specific kernel configs, where HID is enabled, but UHID is not, this leads to compile-time undefined symbol errors: ld.lld: error: undefined symbol: uhid_hid_driver This patch relies on the compiler to leave out unutilised sections of the code if the associated resources are not available. Bug: 260007429 Reported-by: Paul Lawrence Reported-by: Nathan Chancellor Signed-off-by: Lee Jones Change-Id: I80b1aa7454c89d5c5e21f0268252ffb666efab97 --- drivers/hid/hid-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index e012a4382ea3..f017b457f222 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -293,7 +293,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign offset = report->size; report->size += parser->global.report_size * parser->global.report_count; - if (parser->device->ll_driver == &uhid_hid_driver) + if (IS_ENABLED(CONFIG_UHID) && parser->device->ll_driver == &uhid_hid_driver) max_buffer_size = UHID_DATA_MAX; /* Total size check: Allow for possible report index byte */ @@ -1987,7 +1987,7 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 * rsize = hid_compute_report_size(report); - if (hid->ll_driver == &uhid_hid_driver) + if (IS_ENABLED(CONFIG_UHID) && hid->ll_driver == &uhid_hid_driver) max_buffer_size = UHID_DATA_MAX; if (report_enum->numbered && rsize >= max_buffer_size) @@ -2398,7 +2398,7 @@ int hid_hw_raw_request(struct hid_device *hdev, { unsigned int max_buffer_size = HID_MAX_BUFFER_SIZE; - if (hdev->ll_driver == &uhid_hid_driver) + if (IS_ENABLED(CONFIG_UHID) && hdev->ll_driver == &uhid_hid_driver) max_buffer_size = UHID_DATA_MAX; if (len < 1 || len > max_buffer_size || !buf) @@ -2422,7 +2422,7 @@ int hid_hw_output_report(struct hid_device *hdev, __u8 *buf, size_t len) { unsigned int max_buffer_size = HID_MAX_BUFFER_SIZE; - if (hdev->ll_driver == &uhid_hid_driver) + if (IS_ENABLED(CONFIG_UHID) && hdev->ll_driver == &uhid_hid_driver) max_buffer_size = UHID_DATA_MAX; if (len < 1 || len > max_buffer_size || !buf)