Skip to contentSkip to conversation

i2c: qup: Fix order of runtime pm initialization

PATCH Applied Andy Gross 4 participants 6 messages Sep 29, 2014 – Oct 3, 2014

Subsystems (2)
lore
Share & tools
lore

Andy Gross

author
#0 lore raw

PATCH 1/1 i2c: qup: Fix order of runtime pm initialization

The runtime pm calls need to be done before populating the children via the i2c_add_adapter call. If this is not done, a child can run into issues trying to do i2c read/writes due to the pm_runtime_sync failing.

---
 drivers/i2c/busses/i2c-qup.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-qup.c +8 -4
index 3a4d64e..092d89b 100644
@@ -674,16 +674,20 @@ static int qup_i2c_probe(struct platform_device *pdev)
 	qup->adap.dev.of_node = pdev->dev.of_node;
 	strlcpy(qup->adap.name, "QUP I2C adapter", sizeof(qup->adap.name));
 
-	ret = i2c_add_adapter(&qup->adap);
-	if (ret)
-		goto fail;
-
 	pm_runtime_set_autosuspend_delay(qup->dev, MSEC_PER_SEC);
 	pm_runtime_use_autosuspend(qup->dev);
 	pm_runtime_set_active(qup->dev);
 	pm_runtime_enable(qup->dev);
+
+	ret = i2c_add_adapter(&qup->adap);
+	if (ret)
+		goto fail_runtime;
+
 	return 0;
 
+fail_runtime:
+	pm_runtime_disable(qup->dev);
+	pm_runtime_set_suspended(qup->dev);
 fail:
 	qup_i2c_disable_clocks(qup);
 	return ret;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Andy Gross

The runtime pm calls need to be done before populating the children via the i2c_add_adapter call. If this is not done, a child can run into issues trying to do i2c read/writes due to the pm_runtime_sync failing.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140929/bbd394d1/attachment.sig>
Acked-by on v1 1/1
#2 lore raw
In reply to Andy Gross
Quoted 4 lines · Andy Gross

The runtime pm calls need to be done before populating the children via the i2c_add_adapter call. If this is not done, a child can run into issues trying to do i2c read/writes due to the pm_runtime_sync failing.

May I ask in what case this would fail? I thought we tested this as we found the faulty error check after calling pm_runtime_get_sync().

Nontheless,

Regards,
Bjorn

Quoted 38 lines
---
 drivers/i2c/busses/i2c-qup.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-qup.c +8 -4
index 3a4d64e..092d89b 100644
@@ -674,16 +674,20 @@ static int qup_i2c_probe(struct platform_device *pdev)
 	qup->adap.dev.of_node = pdev->dev.of_node;
 	strlcpy(qup->adap.name, "QUP I2C adapter", sizeof(qup->adap.name));
 
-	ret = i2c_add_adapter(&qup->adap);
-	if (ret)
-		goto fail;
-
 	pm_runtime_set_autosuspend_delay(qup->dev, MSEC_PER_SEC);
 	pm_runtime_use_autosuspend(qup->dev);
 	pm_runtime_set_active(qup->dev);
 	pm_runtime_enable(qup->dev);
+
+	ret = i2c_add_adapter(&qup->adap);
+	if (ret)
+		goto fail_runtime;
+
 	return 0;
 
+fail_runtime:
+	pm_runtime_disable(qup->dev);
+	pm_runtime_set_suspended(qup->dev);
 fail:
 	qup_i2c_disable_clocks(qup);
 	return ret;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
author
#3 lore raw
Quoted 9 lines · Bjorn Andersson
Quoted 4 lines · Andy Gross

The runtime pm calls need to be done before populating the children via the i2c_add_adapter call. If this is not done, a child can run into issues trying to do i2c read/writes due to the pm_runtime_sync failing.

May I ask in what case this would fail? I thought we tested this as we found the faulty error check after calling pm_runtime_get_sync().

This is a different kind of failure. If during probe, the children do some I2C
activity, they will encounter issues with the runtime_sync due to the pm_runtime not being initialized. However, once the qup probe completes, everything works fine.

The original runtime_sync issue revolved around the runtime_sync return value being misinterpreted due to the incorrect check.

<snip>

Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#4 lore raw
Quoted 11 lines · Andy Gross
Quoted 9 lines · Bjorn Andersson
Quoted 4 lines · Andy Gross

The runtime pm calls need to be done before populating the children via the i2c_add_adapter call. If this is not done, a child can run into issues trying to do i2c read/writes due to the pm_runtime_sync failing.

May I ask in what case this would fail? I thought we tested this as we found the faulty error check after calling pm_runtime_get_sync().

Quoted 8 lines

This is a different kind of failure. If during probe, the children do some I2C
activity, they will encounter issues with the runtime_sync due to the pm_runtime not being initialized. However, once the qup probe completes, everything works fine.

The original runtime_sync issue revolved around the runtime_sync return value being misinterpreted due to the incorrect check.

Yeah, I just wondered why my testing didn't trigger this. But I suspect that the answer is simply that the client I ran with did not do i2c accesses from probe.

Regards,
Bjorn

Applied
#5 lore raw
In reply to Andy Gross
Quoted 5 lines · Andy Gross

The runtime pm calls need to be done before populating the children via the i2c_add_adapter call. If this is not done, a child can run into issues trying to do i2c read/writes due to the pm_runtime_sync failing.

Applied to for-current, thanks!