Skip to content

Commit bba920e

Browse files
basuamdJiri Kosina
authored andcommitted
HID: amd_sfh: Add sync across amd sfh work functions
The process of the report is delegated across different work functions. Hence, add a sync mechanism to protect SFH work data across functions. Fixes: 4b2c53d ("SFH:Transport Driver to add support of AMD Sensor Fusion Hub (SFH)") Reported-by: Matthew Schwartz <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Tested-by: Prakruthi SP <[email protected]> Co-developed-by: Akshata MukundShetty <[email protected]> Signed-off-by: Akshata MukundShetty <[email protected]> Signed-off-by: Basavaraj Natikar <[email protected]> Reviewed-by: Mario Limonciello (AMD) <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 831f70a commit bba920e

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type)
3939
struct amdtp_hid_data *hid_data = hid->driver_data;
4040
struct amdtp_cl_data *cli_data = hid_data->cli_data;
4141
struct request_list *req_list = &cli_data->req_list;
42+
struct amd_input_data *in_data = cli_data->in_data;
43+
struct amd_mp2_dev *mp2;
4244
int i;
4345

46+
mp2 = container_of(in_data, struct amd_mp2_dev, in_data);
47+
guard(mutex)(&mp2->lock);
4448
for (i = 0; i < cli_data->num_hid_devices; i++) {
4549
if (cli_data->hid_sensor_hubs[i] == hid) {
4650
struct request_list *new = kzalloc(sizeof(*new), GFP_KERNEL);
@@ -75,6 +79,8 @@ void amd_sfh_work(struct work_struct *work)
7579
u8 report_id, node_type;
7680
u8 report_size = 0;
7781

82+
mp2 = container_of(in_data, struct amd_mp2_dev, in_data);
83+
guard(mutex)(&mp2->lock);
7884
req_node = list_last_entry(&req_list->list, struct request_list, list);
7985
list_del(&req_node->list);
8086
current_index = req_node->current_index;
@@ -83,7 +89,6 @@ void amd_sfh_work(struct work_struct *work)
8389
node_type = req_node->report_type;
8490
kfree(req_node);
8591

86-
mp2 = container_of(in_data, struct amd_mp2_dev, in_data);
8792
mp2_ops = mp2->mp2_ops;
8893
if (node_type == HID_FEATURE_REPORT) {
8994
report_size = mp2_ops->get_feat_rep(sensor_index, report_id,
@@ -107,6 +112,8 @@ void amd_sfh_work(struct work_struct *work)
107112
cli_data->cur_hid_dev = current_index;
108113
cli_data->sensor_requested_cnt[current_index] = 0;
109114
amdtp_hid_wakeup(cli_data->hid_sensor_hubs[current_index]);
115+
if (!list_empty(&req_list->list))
116+
schedule_delayed_work(&cli_data->work, 0);
110117
}
111118

112119
void amd_sfh_work_buffer(struct work_struct *work)
@@ -117,9 +124,10 @@ void amd_sfh_work_buffer(struct work_struct *work)
117124
u8 report_size;
118125
int i;
119126

127+
mp2 = container_of(in_data, struct amd_mp2_dev, in_data);
128+
guard(mutex)(&mp2->lock);
120129
for (i = 0; i < cli_data->num_hid_devices; i++) {
121130
if (cli_data->sensor_sts[i] == SENSOR_ENABLED) {
122-
mp2 = container_of(in_data, struct amd_mp2_dev, in_data);
123131
report_size = mp2->mp2_ops->get_in_rep(i, cli_data->sensor_idx[i],
124132
cli_data->report_id[i], in_data);
125133
hid_input_report(cli_data->hid_sensor_hubs[i], HID_INPUT_REPORT,

drivers/hid/amd-sfh-hid/amd_sfh_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef AMD_SFH_COMMON_H
1111
#define AMD_SFH_COMMON_H
1212

13+
#include <linux/mutex.h>
1314
#include <linux/pci.h>
1415
#include "amd_sfh_hid.h"
1516

@@ -59,6 +60,8 @@ struct amd_mp2_dev {
5960
u32 mp2_acs;
6061
struct sfh_dev_status dev_en;
6162
struct work_struct work;
63+
/* mp2 to protect data */
64+
struct mutex lock;
6265
u8 init_done;
6366
u8 rver;
6467
};

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,10 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
466466
if (!privdata->cl_data)
467467
return -ENOMEM;
468468

469+
rc = devm_mutex_init(&pdev->dev, &privdata->lock);
470+
if (rc)
471+
return rc;
472+
469473
privdata->sfh1_1_ops = (const struct amd_sfh1_1_ops *)id->driver_data;
470474
if (privdata->sfh1_1_ops) {
471475
if (boot_cpu_data.x86 >= 0x1A)

0 commit comments

Comments
 (0)