mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 05:31:37 -04:00
soc: qcom: llcc: Use guards for mutex handling
Replacing manual lock/unlock pairs with guard() removes the need to think about unlocking entirely and keeps the function trivially structured. Signed-off-by: Unnathi Chalicheemala <unnathi.chalicheemala@oss.qualcomm.com> Signed-off-by: Francisco Munoz Ruiz <francisco.ruiz@oss.qualcomm.com> Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Link: https://lore.kernel.org/r/20260305-external_llcc_changes1set-v1-2-6347e52e648e@oss.qualcomm.com Signed-off-by: Bjorn Andersson <andersson@kernel.org>
This commit is contained in:
committed by
Bjorn Andersson
parent
45c2a55d13
commit
eda32f68ce
@@ -4635,27 +4635,21 @@ int llcc_slice_activate(struct llcc_slice_desc *desc)
|
||||
if (IS_ERR_OR_NULL(desc))
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&drv_data->lock);
|
||||
guard(mutex)(&drv_data->lock);
|
||||
/* Already active; try to take another reference. */
|
||||
if (refcount_inc_not_zero(&desc->refcount)) {
|
||||
mutex_unlock(&drv_data->lock);
|
||||
if (refcount_inc_not_zero(&desc->refcount))
|
||||
return 0;
|
||||
}
|
||||
|
||||
act_ctrl_val = ACT_CTRL_OPCODE_ACTIVATE << ACT_CTRL_OPCODE_SHIFT;
|
||||
|
||||
ret = llcc_update_act_ctrl(desc->slice_id, act_ctrl_val,
|
||||
DEACTIVATE);
|
||||
if (ret) {
|
||||
mutex_unlock(&drv_data->lock);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Set first reference */
|
||||
refcount_set(&desc->refcount, 1);
|
||||
mutex_unlock(&drv_data->lock);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(llcc_slice_activate);
|
||||
|
||||
@@ -4677,27 +4671,21 @@ int llcc_slice_deactivate(struct llcc_slice_desc *desc)
|
||||
if (IS_ERR_OR_NULL(desc))
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&drv_data->lock);
|
||||
guard(mutex)(&drv_data->lock);
|
||||
/* refcount > 1, drop one ref and we’re done. */
|
||||
if (refcount_dec_not_one(&desc->refcount)) {
|
||||
mutex_unlock(&drv_data->lock);
|
||||
if (refcount_dec_not_one(&desc->refcount))
|
||||
return 0;
|
||||
}
|
||||
|
||||
act_ctrl_val = ACT_CTRL_OPCODE_DEACTIVATE << ACT_CTRL_OPCODE_SHIFT;
|
||||
|
||||
ret = llcc_update_act_ctrl(desc->slice_id, act_ctrl_val,
|
||||
ACTIVATE);
|
||||
if (ret) {
|
||||
mutex_unlock(&drv_data->lock);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Finalize: atomically transition 1 -> 0 */
|
||||
WARN_ON_ONCE(!refcount_dec_if_one(&desc->refcount));
|
||||
mutex_unlock(&drv_data->lock);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(llcc_slice_deactivate);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user