Skip to content

Commit

Permalink
dsp: mius: Protect afe_set_parameter critical section
Browse files Browse the repository at this point in the history
* Code from branch: odin-r-oss

Change-Id: I1fbd53d5ec0b346bfeb1ffb27ded8f5a45224874
  • Loading branch information
vantoman authored and itsshashanksp committed Jun 29, 2024
1 parent 60f7550 commit 0d2735f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions techpack/audio/dsp/apr_mius.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ static int afe_set_parameter(int port,
memcpy(&set_param_v3->param_data, packed_param_data,
packed_data_size);

mutex_lock(mius_afe.ptr_afe_apr_lock);
atomic_set(mius_afe.ptr_state, 1);
atomic_set(mius_afe.ptr_status, 0);
ret = apr_send_pkt(*mius_afe.ptr_apr, (uint32_t *) set_param_v3);
} else {
set_param_v2_size += packed_data_size;
Expand All @@ -132,28 +134,32 @@ static int afe_set_parameter(int port,
memcpy(&set_param_v2->param_data, packed_param_data,
packed_data_size);

mutex_lock(mius_afe.ptr_afe_apr_lock);
atomic_set(mius_afe.ptr_state, 1);
atomic_set(mius_afe.ptr_status, 0);
ret = apr_send_pkt(*mius_afe.ptr_apr, (uint32_t *) set_param_v2);
}
if (ret < 0) {
pr_err("%s: Setting param for port %d param[0x%x]failed\n",
__func__, port, param_id);
goto fail_cmd;
goto fail_cmd_lock;
}
ret = wait_event_timeout(mius_afe.ptr_wait[index],
(atomic_read(mius_afe.ptr_state) == 0),
msecs_to_jiffies(mius_afe.timeout_ms*10));
msecs_to_jiffies(mius_afe.timeout_ms));
if (!ret) {
pr_err("%s: wait_event timeout\n", __func__);
ret = -EINVAL;
goto fail_cmd;
goto fail_cmd_lock;
}
if (atomic_read(mius_afe.ptr_status) != 0) {
pr_err("%s: set param cmd failed\n", __func__);
ret = -EINVAL;
goto fail_cmd;
goto fail_cmd_lock;
}
ret = 0;
fail_cmd_lock:
mutex_unlock(mius_afe.ptr_afe_apr_lock);
fail_cmd:
pr_debug("%s param_id %x status %d\n", __func__, param_id, ret);
kfree(set_param_v2);
Expand Down
1 change: 1 addition & 0 deletions techpack/audio/dsp/q6afe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,7 @@ afe_mi_ultrasound_state_t mius_afe = {
.ptr_status = &this_afe.status,
.ptr_state = &this_afe.state,
.ptr_wait = this_afe.wait,
.ptr_afe_apr_lock= &this_afe.afe_apr_lock,
.timeout_ms = TIMEOUT_MS,
};
EXPORT_SYMBOL(mius_afe);
Expand Down
1 change: 1 addition & 0 deletions techpack/audio/include/dsp/apr_mius.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef struct afe_mi_ultrasound_state {
atomic_t *ptr_status;
atomic_t *ptr_state;
wait_queue_head_t *ptr_wait;
struct mutex *ptr_afe_apr_lock;
int timeout_ms;
} afe_mi_ultrasound_state_t;

Expand Down

0 comments on commit 0d2735f

Please sign in to comment.