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

Commit 121fb2ac authored by raghavendra ambadas's avatar raghavendra ambadas
Browse files

msm: mhl: sii8334: Add mutex lock to avoid race condition



Add mutex lock betweeen mhl_sii_config and mhl_sii_device_discovery
functions to avoid accesing the variable flag before it is updated.
This will avoid accessing the mhl init settings i2c register
before turning on the mhl regulator's and gpio's.

Change-Id: If3f7fbe3d6ab84f101c407c43ac8b410e6df38fe
Signed-off-by: default avatarRaghavendra Ambadas <rambad@codeaurora.org>
parent 08fae6be
Loading
Loading
Loading
Loading
+16 −12
Original line number Diff line number Diff line
@@ -399,19 +399,22 @@ static int mhl_sii_config(struct mhl_tx_ctrl *mhl_ctrl, bool on)

	client = mhl_ctrl->i2c_handle;

	mutex_lock(&mhl_ctrl->sii_config_lock);
	if (on && !mhl_ctrl->irq_req_done) {
		rc = mhl_vreg_config(mhl_ctrl, 1);
		if (rc) {
			pr_err("%s: vreg init failed [%d]\n",
				__func__, rc);
			return -ENODEV;
			rc = -ENODEV;
			goto vreg_config_error;
		}

		rc = mhl_gpio_config(mhl_ctrl, 1);
		if (rc) {
			pr_err("%s: gpio init failed [%d]\n",
				__func__, rc);
			return -ENODEV;
			rc = -ENODEV;
			goto vreg_config_error;
		}

		rc = request_threaded_irq(mhl_ctrl->i2c_handle->irq, NULL,
@@ -420,9 +423,12 @@ static int mhl_sii_config(struct mhl_tx_ctrl *mhl_ctrl, bool on)
		if (rc) {
			pr_err("%s: request_threaded_irq failed, status: %d\n",
			       __func__, rc);
			return -ENODEV;
			rc = -ENODEV;
			goto vreg_config_error;
		} else {
			mhl_ctrl->irq_req_done = true;
			/* wait for i2c interrupt line to be activated */
			msleep(100);
		}
	} else if (!on && mhl_ctrl->irq_req_done) {
		free_irq(mhl_ctrl->i2c_handle->irq, mhl_ctrl);
@@ -431,6 +437,8 @@ static int mhl_sii_config(struct mhl_tx_ctrl *mhl_ctrl, bool on)
		mhl_ctrl->irq_req_done = false;
	}

vreg_config_error:
	mutex_unlock(&mhl_ctrl->sii_config_lock);
	return rc;
}

@@ -472,17 +480,12 @@ static int mhl_sii_device_discovery(void *data, int id,

	flush_work(&mhl_ctrl->mhl_intr_work);

	if (!mhl_ctrl->irq_req_done) {
	rc = mhl_sii_config(mhl_ctrl, true);
	if (rc) {
		pr_err("%s: Failed to config vreg/gpio\n", __func__);
		return rc;
	}

		/* wait for i2c interrupt line to be activated */
		msleep(100);
	}

	if (!mhl_ctrl->disc_enabled) {
		spin_lock_irqsave(&mhl_ctrl->lock, flags);
		mhl_ctrl->tx_powered_off = false;
@@ -1866,6 +1869,7 @@ static int mhl_i2c_probe(struct i2c_client *client,


	init_completion(&mhl_ctrl->rgnd_done);
	mutex_init(&mhl_ctrl->sii_config_lock);


	mhl_ctrl->mhl_psy.name = "ext-vbus";
+5 −0
Original line number Diff line number Diff line
@@ -163,6 +163,11 @@ struct mhl_tx_ctrl {
	int wr_burst_pending;
	struct completion req_write_done;
	spinlock_t lock;
	/*
	 * Lock between mhl_sii_config and
	 * mhl_sii_device_discovery functions
	*/
	struct mutex sii_config_lock;
	bool tx_powered_off;
	uint8_t dwnstream_hpd;
	bool mhl_det_discon;