summaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-huawei.c
diff options
context:
space:
mode:
authorSteven Rostedt <rostedt@goodmis.org>2026-09-02 09:55:01 -0400
committerSteven Rostedt <rostedt@goodmis.org>2026-09-02 11:08:21 -0400
commit4617721c502b2ddaa4e324e86da4997edf738fa5 (patch)
tree350aa83b47da0b574a814795392b20b0bed83cbc /drivers/hid/hid-huawei.c
downloadlinux-stable-4617721c502b2ddaa4e324e86da4997edf738fa5.tar.gz
linux-stable-4617721c502b2ddaa4e324e86da4997edf738fa5.zip
ftrace: Synchronize the initialization of ftrace_opsgrafted
There's some internal state that ftrace_ops needs to have set, but since it can be declared outside of the ftrace.c code, it calls ftrace_ops_init() on the ops in every global function. The issue is that if two tasks call it on the same ops at the same time it is possible to have the initialization of one corrupt the initialization of the other call. Create a ops_mutex to use to synchronize every initialization of the ftrace_ops. The mutex is taken within checking the ftrace_ops flag that states it was initializied but the flag is checked again after the mutex has been taken. Checking first outside the mutex allows it to shortcut having to take the mutex. But then the check needs to be done again after the mute is taken in case of races. Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260902095501.6b59af20@gandalf.local.home Fixes: f04f24fb7e48d ("ftrace, kprobes: Fix a deadlock on ftrace_regex_lock") Reported-by: sashiko-bot@kernel.org Close: https://lore.kernel.org/all/20260829025528.49A831F000E9@smtp.kernel.org/ Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'drivers/hid/hid-huawei.c')
-rw-r--r--drivers/hid/hid-huawei.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/drivers/hid/hid-huawei.c b/drivers/hid/hid-huawei.c
new file mode 100644
index 000000000..ee3fc6f68
--- /dev/null
+++ b/drivers/hid/hid-huawei.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * HID driver for some huawei "special" devices
+ *
+ * Copyright (c) 2026 Miao Li <limiao@kylinos.cn>
+ */
+
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+
+#include "hid-ids.h"
+
+static const __u8 huawei_cd30_kbd_rdesc_fixed[] = {
+ 0x05, 0x01, /* Usage Page (Generic Desktop) */
+ 0x09, 0x80, /* Usage (System Control) */
+ 0xa1, 0x01, /* Collection (Application) */
+ 0x85, 0x01, /* Report ID (1) */
+ 0x19, 0x81, /* Usage Minimum (System Power Down) */
+ 0x29, 0x83, /* Usage Maximum (System Wake Up) */
+ 0x15, 0x00, /* Logical Minimum (0) */
+ 0x25, 0x01, /* Logical Maximum (1) */
+ 0x75, 0x01, /* Report Size (1 bit) */
+ 0x95, 0x03, /* Report Count (3) */
+ 0x81, 0x02, /* Input (Data,Var,Abs) */
+ 0x95, 0x05, /* Report Count (5) */
+ 0x81, 0x01, /* Input (Cnst,Ary,Abs) */
+ 0xc0, /* End Collection */
+ 0x05, 0x0c, /* Usage Page (Consumer) */
+ 0x09, 0x01, /* Usage (Consumer Control) */
+ 0xa1, 0x01, /* Collection (Application) */
+ 0x85, 0x02, /* Report ID (2) */
+ 0x19, 0x00, /* Usage Minimum (0) */
+ 0x2a, 0x3c, 0x02, /* Usage Maximum (0x023C) */
+ 0x15, 0x00, /* Logical Minimum (0) */
+ 0x26, 0x3c, 0x02, /* Logical Maximum (0x023C) */
+ 0x95, 0x01, /* Report Count (1) */
+ 0x75, 0x10, /* Report Size (16 bits) */
+ 0x81, 0x00, /* Input (Data,Ary,Abs) */
+ 0xc0 /* End Collection */
+};
+
+static const __u8 *huawei_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+ unsigned int *rsize)
+{
+ struct usb_interface *intf = hid_is_usb(hdev) ?
+ to_usb_interface(hdev->dev.parent) : NULL;
+
+ switch (hdev->product) {
+ case USB_DEVICE_ID_HUAWEI_CD30KBD:
+ if (!intf || intf->cur_altsetting->desc.bInterfaceNumber == 1) {
+ if (*rsize != sizeof(huawei_cd30_kbd_rdesc_fixed) ||
+ memcmp(huawei_cd30_kbd_rdesc_fixed, rdesc,
+ sizeof(huawei_cd30_kbd_rdesc_fixed)) != 0) {
+ hid_info(hdev, "Replacing Huawei cd30 keyboard report descriptor.\n");
+ *rsize = sizeof(huawei_cd30_kbd_rdesc_fixed);
+ return huawei_cd30_kbd_rdesc_fixed;
+ }
+ }
+ break;
+ }
+
+ return rdesc;
+}
+
+static const struct hid_device_id huawei_devices[] = {
+ /* HUAWEI cd30 keyboard */
+ { HID_USB_DEVICE(USB_VENDOR_ID_HUAWEI, USB_DEVICE_ID_HUAWEI_CD30KBD)},
+ { }
+};
+MODULE_DEVICE_TABLE(hid, huawei_devices);
+
+static struct hid_driver huawei_driver = {
+ .name = "huawei",
+ .id_table = huawei_devices,
+ .report_fixup = huawei_report_fixup,
+};
+module_hid_driver(huawei_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Miao Li <limiao@kylinos.cn>");
+MODULE_DESCRIPTION("HID driver for some huawei \"special\" devices");