[PATCH v16 02/19] HID: asus: move functions above
From: Denis Benato
Date: Sat Nov 21 2026 - 21:19:11 EST
Core asus functions that ally driver has to use are below the position where
they will be used: move static function declaration above to avoid forward
declaration of said functions.
Signed-off-by: Denis Benato <denis.benato@xxxxxxxxx>
---
drivers/hid/hid-asus.c | 232 ++++++++++++++++++++---------------------
1 file changed, 116 insertions(+), 116 deletions(-)
diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
index 482e082586f1..659b5f3f2801 100644
--- a/drivers/hid/hid-asus.c
+++ b/drivers/hid/hid-asus.c
@@ -182,6 +182,122 @@ struct asus_drvdata {
struct asus_xgm_led *xgm_led;
};
+/**
+ * asus_find_report() - Find a report of the given type by its ID
+ * @hdev: HID device
+ * @type: report type (HID_INPUT_REPORT, HID_OUTPUT_REPORT or
+ * HID_FEATURE_REPORT)
+ * @report_id: report ID to look for
+ *
+ * Return: the report with the given ID, or NULL if the device does not
+ * declare such a report.
+ */
+static struct hid_report *asus_find_report(struct hid_device *hdev,
+ unsigned int type, u8 report_id)
+{
+ return hdev->report_enum[type].report_id_hash[report_id];
+}
+
+/**
+ * asus_report_len() - Length of a feature report for the device
+ * @hdev: HID device
+ * @report_id: report ID of the feature report
+ *
+ * The same ASUS report ID can have different sizes depending on the device:
+ * report 0x5E is a 64-byte report on laptops but a 300-byte report on XG
+ * Mobile stations. Always size transfers from the report descriptor of the
+ * device at hand instead of hardcoding lengths.
+ *
+ * Return: the length of the feature report in bytes, or 0 if the device
+ * does not declare the report.
+ */
+static size_t asus_report_len(struct hid_device *hdev, u8 report_id)
+{
+ struct hid_report *report;
+
+ report = asus_find_report(hdev, HID_FEATURE_REPORT, report_id);
+
+ return report ? hid_report_len(report) : 0;
+}
+
+static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t buf_size)
+{
+ const size_t hw_len = asus_report_len(hdev, buf[0]);
+ int ret;
+
+ if (!buf || !buf_size)
+ return -EINVAL;
+
+ /* The payload (including the report ID) must fit the device report. */
+ if (!hw_len || buf_size > hw_len)
+ return -EINVAL;
+
+ /*
+ * Send a number of bytes exactly the declared size of the report, report ID
+ * included. Sizes differ between devices: most ROG keyboards declare
+ * 64 bytes and the XG Mobile 300, while the Zenbook Duo keyboards, like
+ * the touchpads, declare 16 for report 0x5a, the size of the handshake,
+ * and do not answer the 64 byte writes sized for the ROG keyboards.
+ */
+ u8 *dmabuf __free(kfree) = kzalloc(hw_len, GFP_KERNEL);
+ if (!dmabuf)
+ return -ENOMEM;
+
+ memcpy(dmabuf, buf, buf_size);
+
+ /* The device may be runtime suspended, e.g. for a deferred backlight change */
+ ret = hid_hw_power(hdev, PM_HINT_FULLON);
+ if (ret < 0)
+ return ret;
+
+ /*
+ * The report ID should be set from the incoming buffer due to LED and
+ * key interfaces having different pages. Short payloads are zero-padded
+ * to the exact report size the hardware expects for this report ID.
+ */
+ ret = hid_hw_raw_request(hdev, buf[0], dmabuf, hw_len, HID_FEATURE_REPORT,
+ HID_REQ_SET_REPORT);
+ hid_hw_power(hdev, PM_HINT_NORMAL);
+ return ret;
+}
+
+/**
+ * asus_kbd_get_report() - Read a report sized from the descriptor
+ * @hdev: HID device
+ * @report_id: report ID to read
+ * @buf: buffer to store the report in
+ * @buf_size: size of @buf
+ *
+ * The transfer is performed at the exact report size the device declares
+ * for @report_id. The device may answer with a short read, and only the
+ * bytes that fit in @buf are copied into it.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+static int asus_kbd_get_report(struct hid_device *hdev, u8 report_id,
+ u8 *buf, size_t buf_size)
+{
+ size_t hw_len = asus_report_len(hdev, report_id);
+ int ret;
+
+ if (!hw_len)
+ return -EINVAL;
+
+ u8 *dmabuf __free(kfree) = kzalloc(hw_len, GFP_KERNEL);
+ if (!dmabuf)
+ return -ENOMEM;
+
+ ret = hid_hw_raw_request(hdev, report_id, dmabuf, hw_len,
+ HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
+ if (ret < 0)
+ return ret;
+
+ /* The device may return less than requested (short read). */
+ memcpy(buf, dmabuf, min(buf_size, hw_len));
+
+ return 0;
+}
+
static int asus_report_battery(struct asus_drvdata *, u8 *, int);
static const struct asus_touchpad_info asus_i2c_tp = {
@@ -628,122 +744,6 @@ static int asus_raw_event(struct hid_device *hdev,
return 0;
}
-/**
- * asus_find_report() - Find a report of the given type by its ID
- * @hdev: HID device
- * @type: report type (HID_INPUT_REPORT, HID_OUTPUT_REPORT or
- * HID_FEATURE_REPORT)
- * @report_id: report ID to look for
- *
- * Return: the report with the given ID, or NULL if the device does not
- * declare such a report.
- */
-static struct hid_report *asus_find_report(struct hid_device *hdev,
- unsigned int type, u8 report_id)
-{
- return hdev->report_enum[type].report_id_hash[report_id];
-}
-
-/**
- * asus_report_len() - Length of a feature report for the device
- * @hdev: HID device
- * @report_id: report ID of the feature report
- *
- * The same ASUS report ID can have different sizes depending on the device:
- * report 0x5E is a 64-byte report on laptops but a 300-byte report on XG
- * Mobile stations. Always size transfers from the report descriptor of the
- * device at hand instead of hardcoding lengths.
- *
- * Return: the length of the feature report in bytes, or 0 if the device
- * does not declare the report.
- */
-static size_t asus_report_len(struct hid_device *hdev, u8 report_id)
-{
- struct hid_report *report;
-
- report = asus_find_report(hdev, HID_FEATURE_REPORT, report_id);
-
- return report ? hid_report_len(report) : 0;
-}
-
-static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t buf_size)
-{
- const size_t hw_len = asus_report_len(hdev, buf[0]);
- int ret;
-
- if (!buf || !buf_size)
- return -EINVAL;
-
- /* The payload (including the report ID) must fit the device report. */
- if (!hw_len || buf_size > hw_len)
- return -EINVAL;
-
- /*
- * Send a number of bytes exactly the declared size of the report, report ID
- * included. Sizes differ between devices: most ROG keyboards declare
- * 64 bytes and the XG Mobile 300, while the Zenbook Duo keyboards, like
- * the touchpads, declare 16 for report 0x5a, the size of the handshake,
- * and do not answer the 64 byte writes sized for the ROG keyboards.
- */
- u8 *dmabuf __free(kfree) = kzalloc(hw_len, GFP_KERNEL);
- if (!dmabuf)
- return -ENOMEM;
-
- memcpy(dmabuf, buf, buf_size);
-
- /* The device may be runtime suspended, e.g. for a deferred backlight change */
- ret = hid_hw_power(hdev, PM_HINT_FULLON);
- if (ret < 0)
- return ret;
-
- /*
- * The report ID should be set from the incoming buffer due to LED and
- * key interfaces having different pages. Short payloads are zero-padded
- * to the exact report size the hardware expects for this report ID.
- */
- ret = hid_hw_raw_request(hdev, buf[0], dmabuf, hw_len, HID_FEATURE_REPORT,
- HID_REQ_SET_REPORT);
- hid_hw_power(hdev, PM_HINT_NORMAL);
- return ret;
-}
-
-/**
- * asus_kbd_get_report() - Read a report sized from the descriptor
- * @hdev: HID device
- * @report_id: report ID to read
- * @buf: buffer to store the report in
- * @buf_size: size of @buf
- *
- * The transfer is performed at the exact report size the device declares
- * for @report_id. The device may answer with a short read, and only the
- * bytes that fit in @buf are copied into it.
- *
- * Return: 0 on success, negative errno on failure.
- */
-static int asus_kbd_get_report(struct hid_device *hdev, u8 report_id,
- u8 *buf, size_t buf_size)
-{
- size_t hw_len = asus_report_len(hdev, report_id);
- int ret;
-
- if (!hw_len)
- return -EINVAL;
-
- u8 *dmabuf __free(kfree) = kzalloc(hw_len, GFP_KERNEL);
- if (!dmabuf)
- return -ENOMEM;
-
- ret = hid_hw_raw_request(hdev, report_id, dmabuf, hw_len,
- HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
- if (ret < 0)
- return ret;
-
- /* The device may return less than requested (short read). */
- memcpy(buf, dmabuf, min(buf_size, hw_len));
-
- return 0;
-}
-
static int asus_kbd_init(struct hid_device *hdev, u8 report_id)
{
/*
--
2.47.3