From 117a9ea276a058194ebb4ef0be24ffca56934748 Mon Sep 17 00:00:00 2001 From: Konstantin Dorfman Date: Sun, 8 Nov 2020 17:01:21 +0200 Subject: [PATCH] soc: spcom: fix race during spcom channel create spcom_register_rpmsg_drv() can hit race from different contexts: when create channel occurs for uefi loaded sp application and spdaemon uses the cryptoapp channel early, and at the same time sec_nvm channel also creates new channel. This change locks globally access to the channel table for spcom_create_channel_chardev() command. Change-Id: Ic4daee06591427146602f41227e77b3ccc3f3151 Signed-off-by: Konstantin Dorfman --- drivers/soc/qcom/spcom.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/soc/qcom/spcom.c b/drivers/soc/qcom/spcom.c index 78cb79444cc2..ef9859348e79 100644 --- a/drivers/soc/qcom/spcom.c +++ b/drivers/soc/qcom/spcom.c @@ -360,7 +360,9 @@ static int spcom_create_predefined_channels_chardev(void) if (name[0] == 0) break; + mutex_lock(&spcom_dev->chdev_count_lock); ret = spcom_create_channel_chardev(name, false); + mutex_unlock(&spcom_dev->chdev_count_lock); if (ret) { spcom_pr_err("failed to create chardev [%s], ret [%d]\n", name, ret); @@ -653,7 +655,11 @@ static int spcom_handle_create_channel_command(void *cmd_buf, int cmd_size) return -EINVAL; } + mutex_lock(&spcom_dev->chdev_count_lock); ret = spcom_create_channel_chardev(cmd->ch_name, cmd->is_sharable); + mutex_unlock(&spcom_dev->chdev_count_lock); + if (ret) + spcom_pr_err("failed to create ch[%s], ret [%d]\n", cmd->ch_name, ret); return ret; } @@ -1981,7 +1987,6 @@ static int spcom_create_channel_chardev(const char *name, bool is_sharable) goto exit_unregister_drv; } - mutex_lock(&spcom_dev->chdev_count_lock); devt = spcom_dev->device_no + spcom_dev->chdev_count; priv = ch; dev = device_create(cls, parent, devt, priv, name); @@ -2001,7 +2006,6 @@ static int spcom_create_channel_chardev(const char *name, bool is_sharable) goto exit_destroy_device; } spcom_dev->chdev_count++; - mutex_unlock(&spcom_dev->chdev_count_lock); mutex_lock(&ch->lock); ch->cdev = cdev; @@ -2015,7 +2019,6 @@ exit_destroy_device: device_destroy(spcom_dev->driver_class, devt); exit_free_cdev: kfree(cdev); - mutex_unlock(&spcom_dev->chdev_count_lock); exit_unregister_drv: ret = spcom_unregister_rpmsg_drv(ch); if (ret != 0)