Skip to content

Commit 2a770b4

Browse files
committed
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
2 parents 42d52ac + 8d355b5 commit 2a770b4

File tree

7 files changed

+40
-39
lines changed

7 files changed

+40
-39
lines changed

drivers/hid/bpf/hid_bpf_dispatch.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <linux/module.h>
2020
#include "hid_bpf_dispatch.h"
2121

22-
struct hid_ops *hid_ops;
22+
const struct hid_ops *hid_ops;
2323
EXPORT_SYMBOL(hid_ops);
2424

2525
u8 *
@@ -352,7 +352,6 @@ __hid_bpf_hw_check_params(struct hid_bpf_ctx *ctx, __u8 *buf, size_t *buf__sz,
352352
{
353353
struct hid_report_enum *report_enum;
354354
struct hid_report *report;
355-
struct hid_device *hdev;
356355
u32 report_len;
357356

358357
/* check arguments */
@@ -371,9 +370,7 @@ __hid_bpf_hw_check_params(struct hid_bpf_ctx *ctx, __u8 *buf, size_t *buf__sz,
371370
if (*buf__sz < 1)
372371
return -EINVAL;
373372

374-
hdev = (struct hid_device *)ctx->hid; /* discard const */
375-
376-
report_enum = hdev->report_enum + rtype;
373+
report_enum = ctx->hid->report_enum + rtype;
377374
report = hid_ops->hid_get_report(report_enum, buf);
378375
if (!report)
379376
return -EINVAL;
@@ -402,7 +399,6 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,
402399
enum hid_report_type rtype, enum hid_class_request reqtype)
403400
{
404401
struct hid_bpf_ctx_kern *ctx_kern;
405-
struct hid_device *hdev;
406402
size_t size = buf__sz;
407403
u8 *dma_data;
408404
int ret;
@@ -429,13 +425,11 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,
429425
return -EINVAL;
430426
}
431427

432-
hdev = (struct hid_device *)ctx->hid; /* discard const */
433-
434428
dma_data = kmemdup(buf, size, GFP_KERNEL);
435429
if (!dma_data)
436430
return -ENOMEM;
437431

438-
ret = hid_ops->hid_hw_raw_request(hdev,
432+
ret = hid_ops->hid_hw_raw_request(ctx->hid,
439433
dma_data[0],
440434
dma_data,
441435
size,
@@ -464,7 +458,6 @@ __bpf_kfunc int
464458
hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz)
465459
{
466460
struct hid_bpf_ctx_kern *ctx_kern;
467-
struct hid_device *hdev;
468461
size_t size = buf__sz;
469462
u8 *dma_data;
470463
int ret;
@@ -478,13 +471,11 @@ hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz)
478471
if (ret)
479472
return ret;
480473

481-
hdev = (struct hid_device *)ctx->hid; /* discard const */
482-
483474
dma_data = kmemdup(buf, size, GFP_KERNEL);
484475
if (!dma_data)
485476
return -ENOMEM;
486477

487-
ret = hid_ops->hid_hw_output_report(hdev, dma_data, size, (u64)(long)ctx, true);
478+
ret = hid_ops->hid_hw_output_report(ctx->hid, dma_data, size, (u64)(long)ctx, true);
488479

489480
kfree(dma_data);
490481
return ret;

drivers/hid/hid-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3064,7 +3064,7 @@ int hid_check_keys_pressed(struct hid_device *hid)
30643064
EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
30653065

30663066
#ifdef CONFIG_HID_BPF
3067-
static struct hid_ops __hid_ops = {
3067+
static const struct hid_ops __hid_ops = {
30683068
.hid_get_report = hid_get_report,
30693069
.hid_hw_raw_request = __hid_hw_raw_request,
30703070
.hid_hw_output_report = __hid_hw_output_report,

drivers/hid/i2c-hid/i2c-hid-core.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,19 @@ static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
414414

415415
i2c_hid_dbg(ihid, "%s\n", __func__);
416416

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+
*/
417424
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+
418430
if (ret)
419431
dev_err(&ihid->client->dev,
420432
"failed to change power setting.\n");
@@ -976,14 +988,6 @@ static int i2c_hid_core_resume(struct i2c_hid *ihid)
976988

977989
enable_irq(client->irq);
978990

979-
/* Make sure the device is awake on the bus */
980-
ret = i2c_hid_probe_address(ihid);
981-
if (ret < 0) {
982-
dev_err(&client->dev, "nothing at address after resume: %d\n",
983-
ret);
984-
return -ENXIO;
985-
}
986-
987991
/* On Goodix 27c6:0d42 wait extra time before device wakeup.
988992
* It's not clear why but if we send wakeup too early, the device will
989993
* never trigger input interrupts.

drivers/hid/wacom_sys.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2241,7 +2241,8 @@ static void wacom_update_name(struct wacom *wacom, const char *suffix)
22412241
if (hid_is_usb(wacom->hdev)) {
22422242
struct usb_interface *intf = to_usb_interface(wacom->hdev->dev.parent);
22432243
struct usb_device *dev = interface_to_usbdev(intf);
2244-
product_name = dev->product;
2244+
if (dev->product != NULL)
2245+
product_name = dev->product;
22452246
}
22462247

22472248
if (wacom->hdev->bus == BUS_I2C) {

include/linux/hid_bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct hid_ops {
7878
const struct bus_type *bus_type;
7979
};
8080

81-
extern struct hid_ops *hid_ops;
81+
extern const struct hid_ops *hid_ops;
8282

8383
/**
8484
* struct hid_bpf_ops - A BPF struct_ops of callbacks allowing to attach HID-BPF

tools/testing/selftests/hid/progs/hid_bpf_helpers.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#define HID_REQ_SET_IDLE HID_REQ_SET_IDLE___not_used
2323
#define HID_REQ_SET_PROTOCOL HID_REQ_SET_PROTOCOL___not_used
2424

25+
/* do not define kfunc through vmlinux.h as this messes up our custom hack */
26+
#define BPF_NO_KFUNC_PROTOTYPES
27+
2528
#include "vmlinux.h"
2629

2730
#undef hid_bpf_ctx
@@ -91,31 +94,31 @@ struct hid_bpf_ops {
9194
/* following are kfuncs exported by HID for HID-BPF */
9295
extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
9396
unsigned int offset,
94-
const size_t __sz) __ksym;
95-
extern struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id) __ksym;
96-
extern void hid_bpf_release_context(struct hid_bpf_ctx *ctx) __ksym;
97+
const size_t __sz) __weak __ksym;
98+
extern struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id) __weak __ksym;
99+
extern void hid_bpf_release_context(struct hid_bpf_ctx *ctx) __weak __ksym;
97100
extern int hid_bpf_hw_request(struct hid_bpf_ctx *ctx,
98101
__u8 *data,
99102
size_t buf__sz,
100103
enum hid_report_type type,
101-
enum hid_class_request reqtype) __ksym;
104+
enum hid_class_request reqtype) __weak __ksym;
102105
extern int hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx,
103-
__u8 *buf, size_t buf__sz) __ksym;
106+
__u8 *buf, size_t buf__sz) __weak __ksym;
104107
extern int hid_bpf_input_report(struct hid_bpf_ctx *ctx,
105108
enum hid_report_type type,
106109
__u8 *data,
107-
size_t buf__sz) __ksym;
110+
size_t buf__sz) __weak __ksym;
108111
extern int hid_bpf_try_input_report(struct hid_bpf_ctx *ctx,
109112
enum hid_report_type type,
110113
__u8 *data,
111-
size_t buf__sz) __ksym;
114+
size_t buf__sz) __weak __ksym;
112115

113116
/* bpf_wq implementation */
114117
extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym;
115118
extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym;
116119
extern int bpf_wq_set_callback_impl(struct bpf_wq *wq,
117120
int (callback_fn)(void *map, int *key, void *wq),
118-
unsigned int flags__k, void *aux__ign) __ksym;
121+
unsigned int flags__k, void *aux__ign) __weak __ksym;
119122
#define bpf_wq_set_callback(timer, cb, flags) \
120123
bpf_wq_set_callback_impl(timer, cb, flags, NULL)
121124

tools/testing/selftests/hid/run-hid-tools-tests.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@
22
# SPDX-License-Identifier: GPL-2.0
33
# Runs tests for the HID subsystem
44

5+
KSELFTEST_SKIP_TEST=4
6+
57
if ! command -v python3 > /dev/null 2>&1; then
68
echo "hid-tools: [SKIP] python3 not installed"
7-
exit 77
9+
exit $KSELFTEST_SKIP_TEST
810
fi
911

1012
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
1315
fi
1416

1517
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
1820
fi
1921

2022
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
2325
fi
2426

2527
TARGET=${TARGET:=.}

0 commit comments

Comments
 (0)