Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'hid-for-linus-2024120501' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid

Pull HID fixes from Benjamin Tissoires:

- regression fix in suspend/resume for i2c-hid (Kenny Levinsen)

- fix wacom driver assuming a name can not be null (WangYuli)

- a couple of constify changes/fixes (Thomas Weißschuh)

- a couple of selftests/hid fixes (Maximilian Heyne & Benjamin
Tissoires)

* tag 'hid-for-linus-2024120501' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid:
selftests/hid: fix kfunc inclusions with newer bpftool
HID: bpf: drop unneeded casts discarding const
HID: bpf: constify hid_ops
selftests: hid: fix typo and exit code
HID: wacom: fix when get product name maybe null pointer
HID: i2c-hid: Revert to using power commands to wake on resume

+40 -39
+4 -13
drivers/hid/bpf/hid_bpf_dispatch.c
··· 19 19 #include <linux/module.h> 20 20 #include "hid_bpf_dispatch.h" 21 21 22 - struct hid_ops *hid_ops; 22 + const struct hid_ops *hid_ops; 23 23 EXPORT_SYMBOL(hid_ops); 24 24 25 25 u8 * ··· 352 352 { 353 353 struct hid_report_enum *report_enum; 354 354 struct hid_report *report; 355 - struct hid_device *hdev; 356 355 u32 report_len; 357 356 358 357 /* check arguments */ ··· 370 371 if (*buf__sz < 1) 371 372 return -EINVAL; 372 373 373 - hdev = (struct hid_device *)ctx->hid; /* discard const */ 374 - 375 - report_enum = hdev->report_enum + rtype; 374 + report_enum = ctx->hid->report_enum + rtype; 376 375 report = hid_ops->hid_get_report(report_enum, buf); 377 376 if (!report) 378 377 return -EINVAL; ··· 399 402 enum hid_report_type rtype, enum hid_class_request reqtype) 400 403 { 401 404 struct hid_bpf_ctx_kern *ctx_kern; 402 - struct hid_device *hdev; 403 405 size_t size = buf__sz; 404 406 u8 *dma_data; 405 407 int ret; ··· 425 429 return -EINVAL; 426 430 } 427 431 428 - hdev = (struct hid_device *)ctx->hid; /* discard const */ 429 - 430 432 dma_data = kmemdup(buf, size, GFP_KERNEL); 431 433 if (!dma_data) 432 434 return -ENOMEM; 433 435 434 - ret = hid_ops->hid_hw_raw_request(hdev, 436 + ret = hid_ops->hid_hw_raw_request(ctx->hid, 435 437 dma_data[0], 436 438 dma_data, 437 439 size, ··· 458 464 hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz) 459 465 { 460 466 struct hid_bpf_ctx_kern *ctx_kern; 461 - struct hid_device *hdev; 462 467 size_t size = buf__sz; 463 468 u8 *dma_data; 464 469 int ret; ··· 471 478 if (ret) 472 479 return ret; 473 480 474 - hdev = (struct hid_device *)ctx->hid; /* discard const */ 475 - 476 481 dma_data = kmemdup(buf, size, GFP_KERNEL); 477 482 if (!dma_data) 478 483 return -ENOMEM; 479 484 480 - ret = hid_ops->hid_hw_output_report(hdev, dma_data, size, (u64)(long)ctx, true); 485 + ret = hid_ops->hid_hw_output_report(ctx->hid, dma_data, size, (u64)(long)ctx, true); 481 486 482 487 kfree(dma_data); 483 488 return ret;
+1 -1
drivers/hid/hid-core.c
··· 3064 3064 EXPORT_SYMBOL_GPL(hid_check_keys_pressed); 3065 3065 3066 3066 #ifdef CONFIG_HID_BPF 3067 - static struct hid_ops __hid_ops = { 3067 + static const struct hid_ops __hid_ops = { 3068 3068 .hid_get_report = hid_get_report, 3069 3069 .hid_hw_raw_request = __hid_hw_raw_request, 3070 3070 .hid_hw_output_report = __hid_hw_output_report,
+12 -8
drivers/hid/i2c-hid/i2c-hid-core.c
··· 414 414 415 415 i2c_hid_dbg(ihid, "%s\n", __func__); 416 416 417 + /* 418 + * Some STM-based devices need 400µs after a rising clock edge to wake 419 + * from deep sleep, in which case the first request will fail due to 420 + * the address not being acknowledged. Try after a short sleep to see 421 + * if the device came alive on the bus. Certain Weida Tech devices also 422 + * need this. 423 + */ 417 424 ret = i2c_hid_set_power_command(ihid, power_state); 425 + if (ret && power_state == I2C_HID_PWR_ON) { 426 + usleep_range(400, 500); 427 + ret = i2c_hid_set_power_command(ihid, I2C_HID_PWR_ON); 428 + } 429 + 418 430 if (ret) 419 431 dev_err(&ihid->client->dev, 420 432 "failed to change power setting.\n"); ··· 987 975 i2c_hid_core_power_up(ihid); 988 976 989 977 enable_irq(client->irq); 990 - 991 - /* Make sure the device is awake on the bus */ 992 - ret = i2c_hid_probe_address(ihid); 993 - if (ret < 0) { 994 - dev_err(&client->dev, "nothing at address after resume: %d\n", 995 - ret); 996 - return -ENXIO; 997 - } 998 978 999 979 /* On Goodix 27c6:0d42 wait extra time before device wakeup. 1000 980 * It's not clear why but if we send wakeup too early, the device will
+2 -1
drivers/hid/wacom_sys.c
··· 2241 2241 if (hid_is_usb(wacom->hdev)) { 2242 2242 struct usb_interface *intf = to_usb_interface(wacom->hdev->dev.parent); 2243 2243 struct usb_device *dev = interface_to_usbdev(intf); 2244 - product_name = dev->product; 2244 + if (dev->product != NULL) 2245 + product_name = dev->product; 2245 2246 } 2246 2247 2247 2248 if (wacom->hdev->bus == BUS_I2C) {
+1 -1
include/linux/hid_bpf.h
··· 78 78 const struct bus_type *bus_type; 79 79 }; 80 80 81 - extern struct hid_ops *hid_ops; 81 + extern const struct hid_ops *hid_ops; 82 82 83 83 /** 84 84 * struct hid_bpf_ops - A BPF struct_ops of callbacks allowing to attach HID-BPF
+11 -8
tools/testing/selftests/hid/progs/hid_bpf_helpers.h
··· 22 22 #define HID_REQ_SET_IDLE HID_REQ_SET_IDLE___not_used 23 23 #define HID_REQ_SET_PROTOCOL HID_REQ_SET_PROTOCOL___not_used 24 24 25 + /* do not define kfunc through vmlinux.h as this messes up our custom hack */ 26 + #define BPF_NO_KFUNC_PROTOTYPES 27 + 25 28 #include "vmlinux.h" 26 29 27 30 #undef hid_bpf_ctx ··· 94 91 /* following are kfuncs exported by HID for HID-BPF */ 95 92 extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx, 96 93 unsigned int offset, 97 - const size_t __sz) __ksym; 98 - extern struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id) __ksym; 99 - extern void hid_bpf_release_context(struct hid_bpf_ctx *ctx) __ksym; 94 + const size_t __sz) __weak __ksym; 95 + extern struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id) __weak __ksym; 96 + extern void hid_bpf_release_context(struct hid_bpf_ctx *ctx) __weak __ksym; 100 97 extern int hid_bpf_hw_request(struct hid_bpf_ctx *ctx, 101 98 __u8 *data, 102 99 size_t buf__sz, 103 100 enum hid_report_type type, 104 - enum hid_class_request reqtype) __ksym; 101 + enum hid_class_request reqtype) __weak __ksym; 105 102 extern int hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx, 106 - __u8 *buf, size_t buf__sz) __ksym; 103 + __u8 *buf, size_t buf__sz) __weak __ksym; 107 104 extern int hid_bpf_input_report(struct hid_bpf_ctx *ctx, 108 105 enum hid_report_type type, 109 106 __u8 *data, 110 - size_t buf__sz) __ksym; 107 + size_t buf__sz) __weak __ksym; 111 108 extern int hid_bpf_try_input_report(struct hid_bpf_ctx *ctx, 112 109 enum hid_report_type type, 113 110 __u8 *data, 114 - size_t buf__sz) __ksym; 111 + size_t buf__sz) __weak __ksym; 115 112 116 113 /* bpf_wq implementation */ 117 114 extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym; 118 115 extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym; 119 116 extern int bpf_wq_set_callback_impl(struct bpf_wq *wq, 120 117 int (callback_fn)(void *map, int *key, void *wq), 121 - unsigned int flags__k, void *aux__ign) __ksym; 118 + unsigned int flags__k, void *aux__ign) __weak __ksym; 122 119 #define bpf_wq_set_callback(timer, cb, flags) \ 123 120 bpf_wq_set_callback_impl(timer, cb, flags, NULL) 124 121
+9 -7
tools/testing/selftests/hid/run-hid-tools-tests.sh
··· 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 # Runs tests for the HID subsystem 4 4 5 + KSELFTEST_SKIP_TEST=4 6 + 5 7 if ! command -v python3 > /dev/null 2>&1; then 6 8 echo "hid-tools: [SKIP] python3 not installed" 7 - exit 77 9 + exit $KSELFTEST_SKIP_TEST 8 10 fi 9 11 10 12 if ! python3 -c "import pytest" > /dev/null 2>&1; then 11 - echo "hid: [SKIP/ pytest module not installed" 12 - exit 77 13 + echo "hid: [SKIP] pytest module not installed" 14 + exit $KSELFTEST_SKIP_TEST 13 15 fi 14 16 15 17 if ! python3 -c "import pytest_tap" > /dev/null 2>&1; then 16 - echo "hid: [SKIP/ pytest_tap module not installed" 17 - exit 77 18 + echo "hid: [SKIP] pytest_tap module not installed" 19 + exit $KSELFTEST_SKIP_TEST 18 20 fi 19 21 20 22 if ! python3 -c "import hidtools" > /dev/null 2>&1; then 21 - echo "hid: [SKIP/ hid-tools module not installed" 22 - exit 77 23 + echo "hid: [SKIP] hid-tools module not installed" 24 + exit $KSELFTEST_SKIP_TEST 23 25 fi 24 26 25 27 TARGET=${TARGET:=.}