* [PATCH] [v2] i2c: stm32f7: Fix runtime PM imbalance on error
@ 2020-05-27 1:38 Dinghao Liu
2020-06-01 5:56 ` Alain Volmat
0 siblings, 1 reply; 3+ messages in thread
From: Dinghao Liu @ 2020-05-27 1:38 UTC (permalink / raw)
To: dinghao.liu, kjlu
Cc: Pierre-Yves MORDRET, Maxime Coquelin, Alexandre Torgue,
linux-i2c, linux-stm32, linux-arm-kernel, linux-kernel
pm_runtime_get_sync() increments the runtime PM usage counter even
the call returns an error code. Thus a pairing decrement is needed
on the error handling path to keep the counter balanced.
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
Changelog:
v2: - Use pm_runtime_put_noidle() instead of
pm_runtime_put_autosuspend(). Fix 5 more
similar cases within this dirver.
---
drivers/i2c/busses/i2c-stm32f7.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index 330ffed011e0..822fd1f5b5ae 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -1620,8 +1620,10 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
f7_msg->smbus = false;
ret = pm_runtime_get_sync(i2c_dev->dev);
- if (ret < 0)
+ if (ret < 0) {
+ pm_runtime_put_noidle(i2c_dev->dev);
return ret;
+ }
ret = stm32f7_i2c_wait_free_bus(i2c_dev);
if (ret)
@@ -1666,8 +1668,10 @@ static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
f7_msg->smbus = true;
ret = pm_runtime_get_sync(dev);
- if (ret < 0)
+ if (ret < 0) {
+ pm_runtime_put_noidle(dev);
return ret;
+ }
ret = stm32f7_i2c_wait_free_bus(i2c_dev);
if (ret)
@@ -1767,8 +1771,10 @@ static int stm32f7_i2c_reg_slave(struct i2c_client *slave)
return ret;
ret = pm_runtime_get_sync(dev);
- if (ret < 0)
+ if (ret < 0) {
+ pm_runtime_put_noidle(dev);
return ret;
+ }
if (!stm32f7_i2c_is_slave_registered(i2c_dev))
stm32f7_i2c_enable_wakeup(i2c_dev, true);
@@ -1837,8 +1843,10 @@ static int stm32f7_i2c_unreg_slave(struct i2c_client *slave)
WARN_ON(!i2c_dev->slave[id]);
ret = pm_runtime_get_sync(i2c_dev->dev);
- if (ret < 0)
+ if (ret < 0) {
+ pm_runtime_put_noidle(i2c_dev->dev);
return ret;
+ }
if (id == 0) {
mask = STM32F7_I2C_OAR1_OA1EN;
@@ -2182,8 +2190,10 @@ static int stm32f7_i2c_regs_backup(struct stm32f7_i2c_dev *i2c_dev)
struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs;
ret = pm_runtime_get_sync(i2c_dev->dev);
- if (ret < 0)
+ if (ret < 0) {
+ pm_runtime_put_noidle(i2c_dev->dev);
return ret;
+ }
backup_regs->cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1);
backup_regs->cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2);
@@ -2204,8 +2214,10 @@ static int stm32f7_i2c_regs_restore(struct stm32f7_i2c_dev *i2c_dev)
struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs;
ret = pm_runtime_get_sync(i2c_dev->dev);
- if (ret < 0)
+ if (ret < 0) {
+ pm_runtime_put_noidle(i2c_dev->dev);
return ret;
+ }
cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1);
if (cr1 & STM32F7_I2C_CR1_PE)
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] [v2] i2c: stm32f7: Fix runtime PM imbalance on error
2020-05-27 1:38 [PATCH] [v2] i2c: stm32f7: Fix runtime PM imbalance on error Dinghao Liu
@ 2020-06-01 5:56 ` Alain Volmat
2020-11-13 8:27 ` Pierre Yves MORDRET
0 siblings, 1 reply; 3+ messages in thread
From: Alain Volmat @ 2020-06-01 5:56 UTC (permalink / raw)
To: Dinghao Liu
Cc: kjlu, Pierre Yves MORDRET, Maxime Coquelin, Alexandre TORGUE,
linux-i2c, linux-stm32, linux-arm-kernel, linux-kernel
Hi,
Reviewed-by: Alain Volmat <alain.volmat@st.com>
Thanks,
Alain
On Wed, May 27, 2020 at 01:38:53AM +0000, Dinghao Liu wrote:
> pm_runtime_get_sync() increments the runtime PM usage counter even
> the call returns an error code. Thus a pairing decrement is needed
> on the error handling path to keep the counter balanced.
>
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>
> Changelog:
>
> v2: - Use pm_runtime_put_noidle() instead of
> pm_runtime_put_autosuspend(). Fix 5 more
> similar cases within this dirver.
> ---
> drivers/i2c/busses/i2c-stm32f7.c | 24 ++++++++++++++++++------
> 1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
> index 330ffed011e0..822fd1f5b5ae 100644
> --- a/drivers/i2c/busses/i2c-stm32f7.c
> +++ b/drivers/i2c/busses/i2c-stm32f7.c
> @@ -1620,8 +1620,10 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
> f7_msg->smbus = false;
>
> ret = pm_runtime_get_sync(i2c_dev->dev);
> - if (ret < 0)
> + if (ret < 0) {
> + pm_runtime_put_noidle(i2c_dev->dev);
> return ret;
> + }
>
> ret = stm32f7_i2c_wait_free_bus(i2c_dev);
> if (ret)
> @@ -1666,8 +1668,10 @@ static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
> f7_msg->smbus = true;
>
> ret = pm_runtime_get_sync(dev);
> - if (ret < 0)
> + if (ret < 0) {
> + pm_runtime_put_noidle(dev);
> return ret;
> + }
>
> ret = stm32f7_i2c_wait_free_bus(i2c_dev);
> if (ret)
> @@ -1767,8 +1771,10 @@ static int stm32f7_i2c_reg_slave(struct i2c_client *slave)
> return ret;
>
> ret = pm_runtime_get_sync(dev);
> - if (ret < 0)
> + if (ret < 0) {
> + pm_runtime_put_noidle(dev);
> return ret;
> + }
>
> if (!stm32f7_i2c_is_slave_registered(i2c_dev))
> stm32f7_i2c_enable_wakeup(i2c_dev, true);
> @@ -1837,8 +1843,10 @@ static int stm32f7_i2c_unreg_slave(struct i2c_client *slave)
> WARN_ON(!i2c_dev->slave[id]);
>
> ret = pm_runtime_get_sync(i2c_dev->dev);
> - if (ret < 0)
> + if (ret < 0) {
> + pm_runtime_put_noidle(i2c_dev->dev);
> return ret;
> + }
>
> if (id == 0) {
> mask = STM32F7_I2C_OAR1_OA1EN;
> @@ -2182,8 +2190,10 @@ static int stm32f7_i2c_regs_backup(struct stm32f7_i2c_dev *i2c_dev)
> struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs;
>
> ret = pm_runtime_get_sync(i2c_dev->dev);
> - if (ret < 0)
> + if (ret < 0) {
> + pm_runtime_put_noidle(i2c_dev->dev);
> return ret;
> + }
>
> backup_regs->cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1);
> backup_regs->cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2);
> @@ -2204,8 +2214,10 @@ static int stm32f7_i2c_regs_restore(struct stm32f7_i2c_dev *i2c_dev)
> struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs;
>
> ret = pm_runtime_get_sync(i2c_dev->dev);
> - if (ret < 0)
> + if (ret < 0) {
> + pm_runtime_put_noidle(i2c_dev->dev);
> return ret;
> + }
>
> cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1);
> if (cr1 & STM32F7_I2C_CR1_PE)
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [v2] i2c: stm32f7: Fix runtime PM imbalance on error
2020-06-01 5:56 ` Alain Volmat
@ 2020-11-13 8:27 ` Pierre Yves MORDRET
0 siblings, 0 replies; 3+ messages in thread
From: Pierre Yves MORDRET @ 2020-11-13 8:27 UTC (permalink / raw)
To: Dinghao Liu, kjlu, Maxime Coquelin, Alexandre TORGUE, linux-i2c,
linux-stm32, linux-arm-kernel, linux-kernel
Hello
Looks good to me
Reviewed-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
Thx
Regards
On 6/1/20 7:56 AM, Alain Volmat wrote:
> Hi,
>
> Reviewed-by: Alain Volmat <alain.volmat@st.com>
>
> Thanks,
> Alain
>
> On Wed, May 27, 2020 at 01:38:53AM +0000, Dinghao Liu wrote:
>> pm_runtime_get_sync() increments the runtime PM usage counter even
>> the call returns an error code. Thus a pairing decrement is needed
>> on the error handling path to keep the counter balanced.
>>
>> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
>> ---
>>
>> Changelog:
>>
>> v2: - Use pm_runtime_put_noidle() instead of
>> pm_runtime_put_autosuspend(). Fix 5 more
>> similar cases within this dirver.
>> ---
>> drivers/i2c/busses/i2c-stm32f7.c | 24 ++++++++++++++++++------
>> 1 file changed, 18 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
>> index 330ffed011e0..822fd1f5b5ae 100644
>> --- a/drivers/i2c/busses/i2c-stm32f7.c
>> +++ b/drivers/i2c/busses/i2c-stm32f7.c
>> @@ -1620,8 +1620,10 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
>> f7_msg->smbus = false;
>>
>> ret = pm_runtime_get_sync(i2c_dev->dev);
>> - if (ret < 0)
>> + if (ret < 0) {
>> + pm_runtime_put_noidle(i2c_dev->dev);
>> return ret;
>> + }
>>
>> ret = stm32f7_i2c_wait_free_bus(i2c_dev);
>> if (ret)
>> @@ -1666,8 +1668,10 @@ static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
>> f7_msg->smbus = true;
>>
>> ret = pm_runtime_get_sync(dev);
>> - if (ret < 0)
>> + if (ret < 0) {
>> + pm_runtime_put_noidle(dev);
>> return ret;
>> + }
>>
>> ret = stm32f7_i2c_wait_free_bus(i2c_dev);
>> if (ret)
>> @@ -1767,8 +1771,10 @@ static int stm32f7_i2c_reg_slave(struct i2c_client *slave)
>> return ret;
>>
>> ret = pm_runtime_get_sync(dev);
>> - if (ret < 0)
>> + if (ret < 0) {
>> + pm_runtime_put_noidle(dev);
>> return ret;
>> + }
>>
>> if (!stm32f7_i2c_is_slave_registered(i2c_dev))
>> stm32f7_i2c_enable_wakeup(i2c_dev, true);
>> @@ -1837,8 +1843,10 @@ static int stm32f7_i2c_unreg_slave(struct i2c_client *slave)
>> WARN_ON(!i2c_dev->slave[id]);
>>
>> ret = pm_runtime_get_sync(i2c_dev->dev);
>> - if (ret < 0)
>> + if (ret < 0) {
>> + pm_runtime_put_noidle(i2c_dev->dev);
>> return ret;
>> + }
>>
>> if (id == 0) {
>> mask = STM32F7_I2C_OAR1_OA1EN;
>> @@ -2182,8 +2190,10 @@ static int stm32f7_i2c_regs_backup(struct stm32f7_i2c_dev *i2c_dev)
>> struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs;
>>
>> ret = pm_runtime_get_sync(i2c_dev->dev);
>> - if (ret < 0)
>> + if (ret < 0) {
>> + pm_runtime_put_noidle(i2c_dev->dev);
>> return ret;
>> + }
>>
>> backup_regs->cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1);
>> backup_regs->cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2);
>> @@ -2204,8 +2214,10 @@ static int stm32f7_i2c_regs_restore(struct stm32f7_i2c_dev *i2c_dev)
>> struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs;
>>
>> ret = pm_runtime_get_sync(i2c_dev->dev);
>> - if (ret < 0)
>> + if (ret < 0) {
>> + pm_runtime_put_noidle(i2c_dev->dev);
>> return ret;
>> + }
>>
>> cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1);
>> if (cr1 & STM32F7_I2C_CR1_PE)
>> --
>> 2.17.1
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-13 8:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27 1:38 [PATCH] [v2] i2c: stm32f7: Fix runtime PM imbalance on error Dinghao Liu
2020-06-01 5:56 ` Alain Volmat
2020-11-13 8:27 ` Pierre Yves MORDRET
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).