Skip to content

Commit edeae8b

Browse files
basuamdgregkh
authored andcommitted
HID: amd_sfh: Add sync across amd sfh work functions
[ Upstream commit bba920e ] 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 <matthew.schwartz@linux.dev> Closes: https://lore.kernel.org/all/a21abca5-4268-449d-95f1-bdd7a25894a5@linux.dev/ Tested-by: Prakruthi SP <Prakruthi.SP@amd.com> Co-developed-by: Akshata MukundShetty <akshata.mukundshetty@amd.com> Signed-off-by: Akshata MukundShetty <akshata.mukundshetty@amd.com> Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com> Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org> Signed-off-by: Jiri Kosina <jkosina@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7a7bb18 commit edeae8b

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

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

@@ -57,6 +58,8 @@ struct amd_mp2_dev {
5758
u32 mp2_acs;
5859
struct sfh_dev_status dev_en;
5960
struct work_struct work;
61+
/* mp2 to protect data */
62+
struct mutex lock;
6063
u8 init_done;
6164
u8 rver;
6265
};

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

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

408+
rc = devm_mutex_init(&pdev->dev, &privdata->lock);
409+
if (rc)
410+
return rc;
411+
408412
privdata->sfh1_1_ops = (const struct amd_sfh1_1_ops *)id->driver_data;
409413
if (privdata->sfh1_1_ops) {
410414
if (boot_cpu_data.x86 >= 0x1A)

0 commit comments

Comments
 (0)