From 5e982dac9920eb4ddad25373571d8d54b98db4bd Mon Sep 17 00:00:00 2001 From: Praveen Kurapati Date: Wed, 29 Jan 2020 14:56:35 +0530 Subject: [PATCH] msm: ipa4: Fix race condition in adpl pipe open Observing race condition during odl pipe open simultaneously. Add changes to protect the scenario with mutex lock. Change-Id: Ib79df57fe871ed8ce8ce480589a93235d030cba0 Signed-off-by: Praveen Kurapati --- drivers/platform/msm/ipa/ipa_v3/ipa_odl.c | 7 ++++++- drivers/platform/msm/ipa/ipa_v3/ipa_odl.h | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/platform/msm/ipa/ipa_v3/ipa_odl.c b/drivers/platform/msm/ipa/ipa_v3/ipa_odl.c index 69d35a35215b..84d760b49f5f 100644 --- a/drivers/platform/msm/ipa/ipa_v3/ipa_odl.c +++ b/drivers/platform/msm/ipa/ipa_v3/ipa_odl.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. */ #include "ipa_i.h" @@ -418,6 +418,7 @@ static int ipa_adpl_open(struct inode *inode, struct file *filp) int ret = 0; IPADBG("Called the function :\n"); + mutex_lock(&ipa3_odl_ctx->pipe_lock); if (ipa3_odl_ctx->odl_state.odl_init && !ipa3_odl_ctx->odl_state.adpl_open) { /* Activate ipa_pm*/ @@ -431,6 +432,7 @@ static int ipa_adpl_open(struct inode *inode, struct file *filp) print_ipa_odl_state_bit_mask(); ret = -ENODEV; } + mutex_unlock(&ipa3_odl_ctx->pipe_lock); return ret; } @@ -439,6 +441,7 @@ static int ipa_adpl_release(struct inode *inode, struct file *filp) { int ret = 0; /* Deactivate ipa_pm */ + mutex_lock(&ipa3_odl_ctx->pipe_lock); ret = ipa_pm_deactivate_sync(ipa3_odl_ctx->odl_pm_hdl); if (ret) IPAERR("failed to activate pm\n"); @@ -451,6 +454,7 @@ static int ipa_adpl_release(struct inode *inode, struct file *filp) IPAERR("mpm failed to disable ADPL over ODL\n"); } + mutex_unlock(&ipa3_odl_ctx->pipe_lock); return ret; } @@ -667,6 +671,7 @@ int ipa_odl_init(void) odl_cdev = ipa3_odl_ctx->odl_cdev; INIT_LIST_HEAD(&ipa3_odl_ctx->adpl_msg_list); mutex_init(&ipa3_odl_ctx->adpl_msg_lock); + mutex_init(&ipa3_odl_ctx->pipe_lock); odl_cdev[loop].class = class_create(THIS_MODULE, "ipa_adpl"); diff --git a/drivers/platform/msm/ipa/ipa_v3/ipa_odl.h b/drivers/platform/msm/ipa/ipa_v3/ipa_odl.h index 8090a8d7d892..e6ad73f7b25f 100644 --- a/drivers/platform/msm/ipa/ipa_v3/ipa_odl.h +++ b/drivers/platform/msm/ipa/ipa_v3/ipa_odl.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. */ #ifndef _IPA3_ODL_H_ @@ -51,6 +51,7 @@ struct ipa_odl_context { struct ipa3_odl_char_device_context odl_cdev[2]; struct list_head adpl_msg_list; struct mutex adpl_msg_lock; + struct mutex pipe_lock; struct ipa_sys_connect_params odl_sys_param; u32 odl_client_hdl; struct odl_state_bit_mask odl_state;