Skip to content

Commit 6b5faec

Browse files
committed
Merge tag 'for-linus-2024072901' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid
Pull HID fixes from Benjamin Tissoires: - fixes for HID-BPF after the merge with the bpf tree (Arnd Bergmann and Benjamin Tissoires) - some tool type fix for the Wacom driver (Tatsunosuke Tobita) - a reorder of the sensor discovery to ensure the HID AMD SFH is removed when no sensors are available (Basavaraj Natikar) * tag 'for-linus-2024072901' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: selftests/hid: add test for attaching multiple time the same struct_ops HID: bpf: prevent the same struct_ops to be attached more than once selftests/hid: disable struct_ops auto-attach selftests/hid: fix bpf_wq new API HID: amd_sfh: Move sensor discovery before HID device initialization hid: bpf: add BPF_JIT dependency HID: wacom: more appropriate tool type categorization HID: wacom: Modify pen IDs
2 parents 1082650 + facdbdf commit 6b5faec

File tree

7 files changed

+55
-67
lines changed

7 files changed

+55
-67
lines changed

drivers/hid/amd-sfh-hid/amd_sfh_client.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,22 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
288288
mp2_ops->start(privdata, info);
289289
cl_data->sensor_sts[i] = amd_sfh_wait_for_response
290290
(privdata, cl_data->sensor_idx[i], SENSOR_ENABLED);
291+
292+
if (cl_data->sensor_sts[i] == SENSOR_ENABLED)
293+
cl_data->is_any_sensor_enabled = true;
294+
}
295+
296+
if (!cl_data->is_any_sensor_enabled ||
297+
(mp2_ops->discovery_status && mp2_ops->discovery_status(privdata) == 0)) {
298+
dev_warn(dev, "Failed to discover, sensors not enabled is %d\n",
299+
cl_data->is_any_sensor_enabled);
300+
rc = -EOPNOTSUPP;
301+
goto cleanup;
291302
}
292303

293304
for (i = 0; i < cl_data->num_hid_devices; i++) {
294305
cl_data->cur_hid_dev = i;
295306
if (cl_data->sensor_sts[i] == SENSOR_ENABLED) {
296-
cl_data->is_any_sensor_enabled = true;
297307
rc = amdtp_hid_probe(i, cl_data);
298308
if (rc)
299309
goto cleanup;
@@ -305,12 +315,6 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
305315
cl_data->sensor_sts[i]);
306316
}
307317

308-
if (!cl_data->is_any_sensor_enabled ||
309-
(mp2_ops->discovery_status && mp2_ops->discovery_status(privdata) == 0)) {
310-
dev_warn(dev, "Failed to discover, sensors not enabled is %d\n", cl_data->is_any_sensor_enabled);
311-
rc = -EOPNOTSUPP;
312-
goto cleanup;
313-
}
314318
schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
315319
return 0;
316320

drivers/hid/bpf/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ menu "HID-BPF support"
33

44
config HID_BPF
55
bool "HID-BPF support"
6-
depends on BPF
6+
depends on BPF_JIT
77
depends on BPF_SYSCALL
88
depends on DYNAMIC_FTRACE_WITH_DIRECT_CALLS
99
help

drivers/hid/bpf/hid_bpf_struct_ops.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ static int hid_bpf_reg(void *kdata, struct bpf_link *link)
183183
struct hid_device *hdev;
184184
int count, err = 0;
185185

186+
/* prevent multiple attach of the same struct_ops */
187+
if (ops->hdev)
188+
return -EINVAL;
189+
186190
hdev = hid_get_device(ops->hid_id);
187191
if (IS_ERR(hdev))
188192
return PTR_ERR(hdev);
@@ -248,6 +252,7 @@ static void hid_bpf_unreg(void *kdata, struct bpf_link *link)
248252

249253
list_del_rcu(&ops->list);
250254
synchronize_srcu(&hdev->bpf.srcu);
255+
ops->hdev = NULL;
251256

252257
reconnect = hdev->bpf.rdesc_ops == ops;
253258
if (reconnect)

drivers/hid/wacom_wac.c

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -692,89 +692,42 @@ static bool wacom_is_art_pen(int tool_id)
692692

693693
static int wacom_intuos_get_tool_type(int tool_id)
694694
{
695-
int tool_type = BTN_TOOL_PEN;
696-
697-
if (wacom_is_art_pen(tool_id))
698-
return tool_type;
699-
700695
switch (tool_id) {
701696
case 0x812: /* Inking pen */
702697
case 0x801: /* Intuos3 Inking pen */
703698
case 0x12802: /* Intuos4/5 Inking Pen */
704699
case 0x012:
705-
tool_type = BTN_TOOL_PENCIL;
706-
break;
707-
708-
case 0x822: /* Pen */
709-
case 0x842:
710-
case 0x852:
711-
case 0x823: /* Intuos3 Grip Pen */
712-
case 0x813: /* Intuos3 Classic Pen */
713-
case 0x802: /* Intuos4/5 13HD/24HD General Pen */
714-
case 0x8e2: /* IntuosHT2 pen */
715-
case 0x022:
716-
case 0x200: /* Pro Pen 3 */
717-
case 0x04200: /* Pro Pen 3 */
718-
case 0x10842: /* MobileStudio Pro Pro Pen slim */
719-
case 0x14802: /* Intuos4/5 13HD/24HD Classic Pen */
720-
case 0x16802: /* Cintiq 13HD Pro Pen */
721-
case 0x18802: /* DTH2242 Pen */
722-
case 0x10802: /* Intuos4/5 13HD/24HD General Pen */
723-
case 0x80842: /* Intuos Pro and Cintiq Pro 3D Pen */
724-
tool_type = BTN_TOOL_PEN;
725-
break;
700+
return BTN_TOOL_PENCIL;
726701

727702
case 0x832: /* Stroke pen */
728703
case 0x032:
729-
tool_type = BTN_TOOL_BRUSH;
730-
break;
704+
return BTN_TOOL_BRUSH;
731705

732706
case 0x007: /* Mouse 4D and 2D */
733707
case 0x09c:
734708
case 0x094:
735709
case 0x017: /* Intuos3 2D Mouse */
736710
case 0x806: /* Intuos4 Mouse */
737-
tool_type = BTN_TOOL_MOUSE;
738-
break;
711+
return BTN_TOOL_MOUSE;
739712

740713
case 0x096: /* Lens cursor */
741714
case 0x097: /* Intuos3 Lens cursor */
742715
case 0x006: /* Intuos4 Lens cursor */
743-
tool_type = BTN_TOOL_LENS;
744-
break;
745-
746-
case 0x82a: /* Eraser */
747-
case 0x84a:
748-
case 0x85a:
749-
case 0x91a:
750-
case 0xd1a:
751-
case 0x0fa:
752-
case 0x82b: /* Intuos3 Grip Pen Eraser */
753-
case 0x81b: /* Intuos3 Classic Pen Eraser */
754-
case 0x91b: /* Intuos3 Airbrush Eraser */
755-
case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
756-
case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
757-
case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
758-
case 0x1480a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
759-
case 0x1090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
760-
case 0x1080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
761-
case 0x1084a: /* MobileStudio Pro Pro Pen slim Eraser */
762-
case 0x1680a: /* Cintiq 13HD Pro Pen Eraser */
763-
case 0x1880a: /* DTH2242 Eraser */
764-
case 0x1080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
765-
tool_type = BTN_TOOL_RUBBER;
766-
break;
716+
return BTN_TOOL_LENS;
767717

768718
case 0xd12:
769719
case 0x912:
770720
case 0x112:
771721
case 0x913: /* Intuos3 Airbrush */
772722
case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
773723
case 0x10902: /* Intuos4/5 13HD/24HD Airbrush */
774-
tool_type = BTN_TOOL_AIRBRUSH;
775-
break;
724+
return BTN_TOOL_AIRBRUSH;
725+
726+
default:
727+
if (tool_id & 0x0008)
728+
return BTN_TOOL_RUBBER;
729+
return BTN_TOOL_PEN;
776730
}
777-
return tool_type;
778731
}
779732

780733
static void wacom_exit_report(struct wacom_wac *wacom)

tools/testing/selftests/hid/hid_bpf.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ static void load_programs(const struct test_program programs[],
532532
FIXTURE_DATA(hid_bpf) * self,
533533
const FIXTURE_VARIANT(hid_bpf) * variant)
534534
{
535+
struct bpf_map *iter_map;
535536
int err = -EINVAL;
536537

537538
ASSERT_LE(progs_count, ARRAY_SIZE(self->hid_links))
@@ -564,6 +565,13 @@ static void load_programs(const struct test_program programs[],
564565
*ops_hid_id = self->hid_id;
565566
}
566567

568+
/* we disable the auto-attach feature of all maps because we
569+
* only want the tested one to be manually attached in the next
570+
* call to bpf_map__attach_struct_ops()
571+
*/
572+
bpf_object__for_each_map(iter_map, *self->skel->skeleton->obj)
573+
bpf_map__set_autoattach(iter_map, false);
574+
567575
err = hid__load(self->skel);
568576
ASSERT_OK(err) TH_LOG("hid_skel_load failed: %d", err);
569577

@@ -686,6 +694,24 @@ TEST_F(hid_bpf, subprog_raw_event)
686694
ASSERT_EQ(buf[2], 52);
687695
}
688696

697+
/*
698+
* Attach hid_first_event to the given uhid device,
699+
* attempt at re-attaching it, we should not lock and
700+
* return an invalid struct bpf_link
701+
*/
702+
TEST_F(hid_bpf, multiple_attach)
703+
{
704+
const struct test_program progs[] = {
705+
{ .name = "hid_first_event" },
706+
};
707+
struct bpf_link *link;
708+
709+
LOAD_PROGRAMS(progs);
710+
711+
link = bpf_map__attach_struct_ops(self->skel->maps.first_event);
712+
ASSERT_NULL(link) TH_LOG("unexpected return value when re-attaching the struct_ops");
713+
}
714+
689715
/*
690716
* Ensures that we can attach/detach programs
691717
*/

tools/testing/selftests/hid/progs/hid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ struct {
455455
__type(value, struct elem);
456456
} hmap SEC(".maps");
457457

458-
static int wq_cb_sleepable(void *map, int *key, struct bpf_wq *work)
458+
static int wq_cb_sleepable(void *map, int *key, void *work)
459459
{
460460
__u8 buf[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
461461
struct hid_bpf_ctx *hid_ctx;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ extern int hid_bpf_try_input_report(struct hid_bpf_ctx *ctx,
114114
extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym;
115115
extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym;
116116
extern int bpf_wq_set_callback_impl(struct bpf_wq *wq,
117-
int (callback_fn)(void *map, int *key, struct bpf_wq *wq),
117+
int (callback_fn)(void *map, int *key, void *wq),
118118
unsigned int flags__k, void *aux__ign) __ksym;
119119
#define bpf_wq_set_callback(timer, cb, flags) \
120120
bpf_wq_set_callback_impl(timer, cb, flags, NULL)

0 commit comments

Comments
 (0)