Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 117a9ea2 authored by Konstantin Dorfman's avatar Konstantin Dorfman
Browse files

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: default avatarKonstantin Dorfman <kdorfman@codeaurora.org>
parent 8543fd31
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -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 @@ static int spcom_create_channel_chardev(const char *name, bool is_sharable)
	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)