Skip to content

Commit

Permalink
techpack: audio: Merge tag 'LA.UM.8.3.c25-00900-sdm845.0' into cantin…
Browse files Browse the repository at this point in the history
…g-4.9-q

* tag 'LA.UM.8.3.c25-00900-sdm845.0' of https://source.codeaurora.org/quic/la/platform/vendor/opensource/audio-kernel:
  dsp: add change to enable preemption at cal_utils_dealloc_cal.
  dsp: add change to handle use-after-free in cal_utils_is_cal_stale
  • Loading branch information
Khusika Dhamar Gusti committed Mar 4, 2021
2 parents bd693a2 + 6e040d5 commit af5b5ac
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
26 changes: 22 additions & 4 deletions techpack/audio/dsp/audio_cal_utils.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2014-2018, 2020, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
Expand All @@ -18,6 +18,8 @@
#include <linux/mutex.h>
#include <dsp/audio_cal_utils.h>

struct mutex cal_lock;

static int unmap_memory(struct cal_type_data *cal_type,
struct cal_block_data *cal_block);

Expand Down Expand Up @@ -937,7 +939,9 @@ int cal_utils_dealloc_cal(size_t data_size, void *data,
if (ret < 0)
goto err;

mutex_lock(&cal_lock);
delete_cal_block(cal_block);
mutex_unlock(&cal_lock);
err:
mutex_unlock(&cal_type->lock);
done:
Expand Down Expand Up @@ -1052,6 +1056,11 @@ void cal_utils_mark_cal_used(struct cal_block_data *cal_block)
}
EXPORT_SYMBOL(cal_utils_mark_cal_used);

int __init cal_utils_init(void)
{
mutex_init(&cal_lock);
return 0;
}
/**
* cal_utils_is_cal_stale
*
Expand All @@ -1061,9 +1070,18 @@ EXPORT_SYMBOL(cal_utils_mark_cal_used);
*/
bool cal_utils_is_cal_stale(struct cal_block_data *cal_block)
{
if ((cal_block) && (cal_block->cal_stale))
return true;
bool ret = false;

return false;
mutex_lock(&cal_lock);
if (!cal_block) {
pr_err("%s: cal_block is Null", __func__);
goto unlock;
}
if (cal_block->cal_stale)
ret = true;

unlock:
mutex_unlock(&cal_lock);
return ret;
}
EXPORT_SYMBOL(cal_utils_is_cal_stale);
3 changes: 2 additions & 1 deletion techpack/audio/dsp/audio_calibration.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2014, 2016-2017 The Linux Foundation. All rights reserved.
/* Copyright (c) 2014, 2016-2017, 2020, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
Expand Down Expand Up @@ -599,6 +599,7 @@ static int __init audio_cal_init(void)

pr_debug("%s\n", __func__);

cal_utils_init();
memset(&audio_cal, 0, sizeof(audio_cal));
mutex_init(&audio_cal.common_lock);
for (; i < MAX_CAL_TYPES; i++) {
Expand Down
10 changes: 8 additions & 2 deletions techpack/audio/dsp/q6asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -9530,9 +9530,15 @@ int q6asm_send_cal(struct audio_client *ac)

mutex_lock(&cal_data[ASM_AUDSTRM_CAL]->lock);
cal_block = cal_utils_get_only_cal_block(cal_data[ASM_AUDSTRM_CAL]);
if (cal_block == NULL || cal_utils_is_cal_stale(cal_block)) {
if (cal_block == NULL) {
pr_err("%s: cal_block is NULL\n",
__func__);
goto unlock;
}

if (cal_utils_is_cal_stale(cal_block)) {
rc = 0; /* not error case */
pr_err("%s: cal_block is NULL or stale\n",
pr_err("%s: cal_block is stale\n",
__func__);
goto unlock;
}
Expand Down
4 changes: 3 additions & 1 deletion techpack/audio/include/dsp/audio_cal_utils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2014, 2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2014, 2018, 2020, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
Expand Down Expand Up @@ -104,4 +104,6 @@ int32_t cal_utils_get_cal_type_version(void *cal_type_data);
void cal_utils_mark_cal_used(struct cal_block_data *cal_block);

bool cal_utils_is_cal_stale(struct cal_block_data *cal_block);

int cal_utils_init(void);
#endif

0 comments on commit af5b5ac

Please sign in to comment.