Skip to contentSkip to conversation

i2c-designware-pcidrv: fix the incorrect return of idle callback

PATCH In review xinhui.pan 3 participants 7 messages Jan 28, 2014 – Jan 29, 2014

Subsystems (3)
lore
Share & tools
lore

xinhui.pan

author
#0 lore raw

PATCH 1/1 i2c-designware-pcidrv: fix the incorrect return of idle callback

From: "xinhui.pan" <[email protected]>

i2c_dw_pci_runtime_idle should return -EBUSY rather than zero if it do success. Otherwise rpm_idle will call pm_suspend again and that may cause pm_schedule_suspend delay invalidate.

---
 drivers/i2c/busses/i2c-designware-pcidrv.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +2 -2
index f6ed06c..96e81f6 100644
@@ -190,8 +190,8 @@ static int i2c_dw_pci_runtime_idle(struct device *dev)
 	int err = pm_schedule_suspend(dev, 500);
 	dev_dbg(dev, "runtime_idle called\n");
 
-	if (err != 0)
-		return 0;
+	if (err)
+		return err;
 	return -EBUSY;
 }
 
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 3 lines · xinhui.pan

From: "xinhui.pan" <[email protected]>

i2c_dw_pci_runtime_idle should return -EBUSY rather than zero if it do success.

I don't understand...

Quoted 13 lines

Otherwise rpm_idle will call pm_suspend again and that may cause pm_schedule_suspend delay invalidate.

---
 drivers/i2c/busses/i2c-designware-pcidrv.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +0 -0
index f6ed06c..96e81f6 100644

drivers/i2c/busses/i2c-designware-pcidrv.c static int i2c_dw_pci_runtime_idle(struct device *dev) · line 195

Quoted 8 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +2 -2
@@ -190,8 +190,8 @@ static int i2c_dw_pci_runtime_idle(struct device *dev)
 	int err = pm_schedule_suspend(dev, 500);
 	dev_dbg(dev, "runtime_idle called\n");
 
-	if (err != 0)
-		return 0;
+	if (err)
+		return err;
 	return -EBUSY;

... it does return EBUSY when pm_schedule_suspend() succeeds? It only returns 0 if it does not succeed (for which I don't know if this is an apropriate behaviour). Mika?

Quoted 4 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +0 -0
 }
 
Signature · 1 line
1.7.9.5
author
#2 lore raw
Quoted 8 lines · xinhui.pan
Quoted 3 lines

From: "xinhui.pan" <[email protected]>

i2c_dw_pci_runtime_idle should return -EBUSY rather than zero if it do success.

I don't understand...

Sorry for my poor English.
Even if i2c_dw_pci_runtime_idle succeed ,it should return -EBUSY.

Quoted 30 lines
Quoted 13 lines

Otherwise rpm_idle will call pm_suspend again and that may cause pm_schedule_suspend delay invalidate.

---
 drivers/i2c/busses/i2c-designware-pcidrv.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +0 -0
index f6ed06c..96e81f6 100644

drivers/i2c/busses/i2c-designware-pcidrv.c static int i2c_dw_pci_runtime_idle(struct device *dev) · line 195

Quoted 8 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +2 -2
@@ -190,8 +190,8 @@ static int i2c_dw_pci_runtime_idle(struct device *dev)
 	int err = pm_schedule_suspend(dev, 500);
 	dev_dbg(dev, "runtime_idle called\n");
 
-	if (err != 0)
-		return 0;
+	if (err)
+		return err;
 	return -EBUSY;

... it does return EBUSY when pm_schedule_suspend() succeeds? It only returns 0 if it does not succeed (for which I don't know if this is an apropriate behaviour). Mika?

Quoted 4 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +0 -0
 }
 
Signature · 1 line
1.7.9.5
author
#3 lore raw
Quoted 36 lines · xinhui.pan
Quoted 8 lines · xinhui.pan
Quoted 3 lines

From: "xinhui.pan" <[email protected]>

i2c_dw_pci_runtime_idle should return -EBUSY rather than zero if it do success.

I don't understand...

Sorry for my poor English.
Even if i2c_dw_pci_runtime_idle succeed ,it should return -EBUSY.

Quoted 26 lines
Quoted 13 lines

Otherwise rpm_idle will call pm_suspend again and that may cause pm_schedule_suspend delay invalidate.

---
 drivers/i2c/busses/i2c-designware-pcidrv.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +0 -0
index f6ed06c..96e81f6 100644

drivers/i2c/busses/i2c-designware-pcidrv.c static int i2c_dw_pci_runtime_idle(struct device *dev) · line 195

Quoted 8 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +2 -2
@@ -190,8 +190,8 @@ static int i2c_dw_pci_runtime_idle(struct device *dev)
 	int err = pm_schedule_suspend(dev, 500);
 	dev_dbg(dev, "runtime_idle called\n");
 
-	if (err != 0)
-		return 0;
+	if (err)
+		return err;
 	return -EBUSY;

... it does return EBUSY when pm_schedule_suspend() succeeds? It only returns 0 if it does not succeed (for which I don't know if this is an apropriate behaviour). Mika?

hi ,
I found one sentence in /Documentation/power/runtime_pm.txt
"If there is no idle callback, or if the callback returns 0,
then the PM core will attempt to carry out a runtime suspend of the device, also respecting devices configured for autosuspend."
so is this a right way to prevent this?
Br. xinhui

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +0 -0
 }
 
Signature · 1 line
1.7.9.5
maintainer
#4 lore raw
In reply to Wolfram Sang
Quoted 23 lines · Wolfram Sang
Quoted 3 lines · xinhui.pan

From: "xinhui.pan" <[email protected]>

i2c_dw_pci_runtime_idle should return -EBUSY rather than zero if it do success.

I don't understand...

Quoted 16 lines

Otherwise rpm_idle will call pm_suspend again and that may cause pm_schedule_suspend delay invalidate.

---
 drivers/i2c/busses/i2c-designware-pcidrv.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +0 -0
index f6ed06c..96e81f6 100644
@@ -190,8 +190,8 @@ static int i2c_dw_pci_runtime_idle(struct device *dev)
 	int err = pm_schedule_suspend(dev, 500);
 	dev_dbg(dev, "runtime_idle called\n");
 
Quoted 9 lines

drivers/i2c/busses/i2c-designware-pcidrv.c static int i2c_dw_pci_runtime_idle(struct device *dev) · line 195

Quoted 5 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +2 -2
-	if (err != 0)
-		return 0;
+	if (err)
+		return err;
 	return -EBUSY;

... it does return EBUSY when pm_schedule_suspend() succeeds? It only returns 0 if it does not succeed (for which I don't know if this is an apropriate behaviour). Mika?

If I understand correctly, pm_schedule_suspend(dev, 500) is there because we want to runtime suspend in 500 ms. It then returns -EBUSY to prevent PM runtime from carrying on suspend on it's own. However, I have no idea where this magical 500 ms requirement comes from.

If we fail to schedule suspend we let the PM core to do whatever it thinks suitable (in this case I suppose it suspends the device).

I think the whole idle dance could be replaced with a use of runtime PM autosuspend, just like we do in the platform version of the driver.

Xinghui,

Is this a real problem that you are trying to solve?

author
#5 lore raw
Quoted 34 lines · Mika Westerberg
Quoted 23 lines · Wolfram Sang
Quoted 3 lines · xinhui.pan

From: "xinhui.pan" <[email protected]>

i2c_dw_pci_runtime_idle should return -EBUSY rather than zero if it do success.

I don't understand...

Quoted 16 lines

Otherwise rpm_idle will call pm_suspend again and that may cause pm_schedule_suspend delay invalidate.

---
 drivers/i2c/busses/i2c-designware-pcidrv.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +0 -0
index f6ed06c..96e81f6 100644
@@ -190,8 +190,8 @@ static int i2c_dw_pci_runtime_idle(struct device *dev)
 	int err = pm_schedule_suspend(dev, 500);
 	dev_dbg(dev, "runtime_idle called\n");
 
Quoted 9 lines

drivers/i2c/busses/i2c-designware-pcidrv.c static int i2c_dw_pci_runtime_idle(struct device *dev) · line 195

Quoted 5 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +2 -2
-	if (err != 0)
-		return 0;
+	if (err)
+		return err;
 	return -EBUSY;

... it does return EBUSY when pm_schedule_suspend() succeeds? It only returns 0 if it does not succeed (for which I don't know if this is an apropriate behaviour). Mika?

Quoted 8 lines

If I understand correctly, pm_schedule_suspend(dev, 500) is there because we want to runtime suspend in 500 ms. It then returns -EBUSY to prevent PM runtime from carrying on suspend on it's own. However, I have no idea where this magical 500 ms requirement comes from.

If we fail to schedule suspend we let the PM core to do whatever it thinks suitable (in this case I suppose it suspends the device).

Hi ,Mika
If the callback returns 0,it means pm_schedule_suspend fails,
also means rpm_check_suspend_allowed(pm_schedule_suspend calls it) returns nonzero value.As a result,rpm_suspend will be called by rpm_idle.
However in rpm_idle, rpm_check_suspend_allowed is called at first,too.
and the return value is treated as it is.But rpm_idle just returns without doing anything(rpm_suspend is not called).
in both case above,why goes in different ways? I am confused.

Quoted 7 lines

I think the whole idle dance could be replaced with a use of runtime PM autosuspend, just like we do in the platform version of the driver.

Xinghui,

Is this a real problem that you are trying to solve?

To be honest,we got many panic when testing.
But is not caused by this driver I think.
while checking problems,we found these confusing codes by accident.

maintainer
#6 lore raw
Quoted 46 lines · xinhui.pan
Quoted 34 lines · Mika Westerberg
Quoted 23 lines · Wolfram Sang
Quoted 3 lines · xinhui.pan

From: "xinhui.pan" <[email protected]>

i2c_dw_pci_runtime_idle should return -EBUSY rather than zero if it do success.

I don't understand...

Quoted 16 lines

Otherwise rpm_idle will call pm_suspend again and that may cause pm_schedule_suspend delay invalidate.

---
 drivers/i2c/busses/i2c-designware-pcidrv.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +0 -0
index f6ed06c..96e81f6 100644
@@ -190,8 +190,8 @@ static int i2c_dw_pci_runtime_idle(struct device *dev)
 	int err = pm_schedule_suspend(dev, 500);
 	dev_dbg(dev, "runtime_idle called\n");
 
Quoted 9 lines

drivers/i2c/busses/i2c-designware-pcidrv.c static int i2c_dw_pci_runtime_idle(struct device *dev) · line 195

Quoted 5 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +2 -2
-	if (err != 0)
-		return 0;
+	if (err)
+		return err;
 	return -EBUSY;

... it does return EBUSY when pm_schedule_suspend() succeeds? It only returns 0 if it does not succeed (for which I don't know if this is an apropriate behaviour). Mika?

Quoted 8 lines

If I understand correctly, pm_schedule_suspend(dev, 500) is there because we want to runtime suspend in 500 ms. It then returns -EBUSY to prevent PM runtime from carrying on suspend on it's own. However, I have no idea where this magical 500 ms requirement comes from.

If we fail to schedule suspend we let the PM core to do whatever it thinks suitable (in this case I suppose it suspends the device).

Quoted 8 lines

Hi ,Mika
If the callback returns 0,it means pm_schedule_suspend fails,
also means rpm_check_suspend_allowed(pm_schedule_suspend calls it) returns nonzero value.As a result,rpm_suspend will be called by rpm_idle.
However in rpm_idle, rpm_check_suspend_allowed is called at first,too.
and the return value is treated as it is.But rpm_idle just returns without doing anything(rpm_suspend is not called).
in both case above,why goes in different ways? I am confused.

To be honest, I don't know ;-)

Quoted 11 lines
Quoted 7 lines

I think the whole idle dance could be replaced with a use of runtime PM autosuspend, just like we do in the platform version of the driver.

Xinghui,

Is this a real problem that you are trying to solve?

To be honest,we got many panic when testing.
But is not caused by this driver I think.
while checking problems,we found these confusing codes by accident.

OK, so if this is not a problem, I would suggest keeping the code as is for now as someone who introduced the pm_schedule_suspend() thing probably tested it and it worked then.

In fact, I think that the PCI part of that driver needs an audit since it does some PCI power management magic itself which drivers aren't supposed to do anymore.