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

Commit 025196c4 authored by Sreelakshmi Gownipalli's avatar Sreelakshmi Gownipalli
Browse files

diag: Avoid race while closing and opening mhi channels



Add protection while closing mhi channels to ensure that close
has finished completely before calling open.

Change-Id: Ib112f5b7d38aee154f2938dab8b314eb1c3b7e7a
Signed-off-by: default avatarSreelakshmi Gownipalli <sgownipa@codeaurora.org>
parent a5c36deb
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -225,9 +225,11 @@ static int __mhi_close(struct diag_mhi_info *mhi_info, int close_flag)

	flush_workqueue(mhi_info->mhi_wq);

	if (close_flag == CLOSE_CHANNELS)
	if (close_flag == CLOSE_CHANNELS) {
		mutex_lock(&mhi_info->ch_mutex);
		mhi_unprepare_from_transfer(mhi_info->mhi_dev);

		mutex_unlock(&mhi_info->ch_mutex);
	}
	mhi_buf_tbl_clear(mhi_info);
	diag_remote_dev_close(mhi_info->dev_id);
	return 0;
@@ -276,7 +278,9 @@ static int __mhi_open(struct diag_mhi_info *mhi_info, int open_flag)
		if ((atomic_read(&(mhi_info->read_ch.opened))) &&
			(atomic_read(&(mhi_info->write_ch.opened))))
			return 0;
		mutex_lock(&mhi_info->ch_mutex);
		err = mhi_prepare_for_transfer(mhi_info->mhi_dev);
		mutex_unlock(&mhi_info->ch_mutex);
		if (err) {
			pr_err("diag: In %s, unable to open ch, err: %d\n",
				__func__, err);
@@ -693,6 +697,7 @@ int diag_mhi_init(void)
		spin_lock_init(&mhi_info->lock);
		spin_lock_init(&mhi_info->read_ch.lock);
		spin_lock_init(&mhi_info->write_ch.lock);
		mutex_init(&mhi_info->ch_mutex);
		INIT_LIST_HEAD(&mhi_info->read_ch.buf_tbl);
		INIT_LIST_HEAD(&mhi_info->write_ch.buf_tbl);
		atomic_set(&(mhi_info->read_ch.opened), 0);
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ struct diag_mhi_info {
	wait_queue_head_t mhi_wait_q;
	struct diag_mhi_ch_t read_ch;
	struct diag_mhi_ch_t write_ch;
	struct mutex ch_mutex;
	spinlock_t lock;
};