diff mbox series

i2c: fix missing pm_runtime_put_sync in i2c_device_probe

Message ID 1588261401-11914-1-git-send-email-alain.volmat@st.com (mailing list archive)
State Mainlined
Commit 3c3dd56f760da056e821ac177e3ad0de4209a435
Headers show
Series i2c: fix missing pm_runtime_put_sync in i2c_device_probe | expand

Commit Message

Alain Volmat April 30, 2020, 3:43 p.m. UTC
In case of the I2C client exposes the flag I2C_CLIENT_HOST_NOTIFY,
pm_runtime_get_sync is called in order to always keep active the
adapter. However later on, pm_runtime_put_sync is never called
within the function in case of an error. This commit add this
error handling.

Fixes: 72bfcee11cf8 ("i2c: Prevent runtime suspend of adapter when Host Notify is required")
Signed-off-by: Alain Volmat <alain.volmat@st.com>
---
 drivers/i2c/i2c-core-base.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

Comments

Wolfram Sang April 30, 2020, 4:35 p.m. UTC | #1
On Thu, Apr 30, 2020 at 05:43:21PM +0200, Alain Volmat wrote:
> In case of the I2C client exposes the flag I2C_CLIENT_HOST_NOTIFY,
> pm_runtime_get_sync is called in order to always keep active the
> adapter. However later on, pm_runtime_put_sync is never called
> within the function in case of an error. This commit add this
> error handling.
> 
> Fixes: 72bfcee11cf8 ("i2c: Prevent runtime suspend of adapter when Host Notify is required")

Adding the patch author to CC.

> Signed-off-by: Alain Volmat <alain.volmat@st.com>
> ---
>  drivers/i2c/i2c-core-base.c | 22 ++++++++++++++++------
>  1 file changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 139aea351ffb..2e4560671183 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -338,8 +338,10 @@ static int i2c_device_probe(struct device *dev)
>  		} else if (ACPI_COMPANION(dev)) {
>  			irq = i2c_acpi_get_irq(client);
>  		}
> -		if (irq == -EPROBE_DEFER)
> -			return irq;
> +		if (irq == -EPROBE_DEFER) {
> +			status = irq;
> +			goto put_sync_adapter;
> +		}
>  
>  		if (irq < 0)
>  			irq = 0;
> @@ -353,15 +355,19 @@ static int i2c_device_probe(struct device *dev)
>  	 */
>  	if (!driver->id_table &&
>  	    !i2c_acpi_match_device(dev->driver->acpi_match_table, client) &&
> -	    !i2c_of_match_device(dev->driver->of_match_table, client))
> -		return -ENODEV;
> +	    !i2c_of_match_device(dev->driver->of_match_table, client)) {
> +		status = -ENODEV;
> +		goto put_sync_adapter;
> +	}
>  
>  	if (client->flags & I2C_CLIENT_WAKE) {
>  		int wakeirq;
>  
>  		wakeirq = of_irq_get_byname(dev->of_node, "wakeup");
> -		if (wakeirq == -EPROBE_DEFER)
> -			return wakeirq;
> +		if (wakeirq == -EPROBE_DEFER) {
> +			status = wakeirq;
> +			goto put_sync_adapter;
> +		}
>  
>  		device_init_wakeup(&client->dev, true);
>  
> @@ -408,6 +414,10 @@ static int i2c_device_probe(struct device *dev)
>  err_clear_wakeup_irq:
>  	dev_pm_clear_wake_irq(&client->dev);
>  	device_init_wakeup(&client->dev, false);
> +put_sync_adapter:
> +	if (client->flags & I2C_CLIENT_HOST_NOTIFY)
> +		pm_runtime_put_sync(&client->adapter->dev);
> +
>  	return status;
>  }
>  
> -- 
> 2.17.1
>
Jarkko Nikula May 4, 2020, 5:46 a.m. UTC | #2
On 4/30/20 7:35 PM, Wolfram Sang wrote:
> On Thu, Apr 30, 2020 at 05:43:21PM +0200, Alain Volmat wrote:
>> In case of the I2C client exposes the flag I2C_CLIENT_HOST_NOTIFY,
>> pm_runtime_get_sync is called in order to always keep active the
>> adapter. However later on, pm_runtime_put_sync is never called
>> within the function in case of an error. This commit add this
>> error handling.
>>
>> Fixes: 72bfcee11cf8 ("i2c: Prevent runtime suspend of adapter when Host Notify is required")
> 
Right, I was blind to see this.

Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Wolfram Sang May 5, 2020, 2:28 p.m. UTC | #3
On Thu, Apr 30, 2020 at 05:43:21PM +0200, Alain Volmat wrote:
> In case of the I2C client exposes the flag I2C_CLIENT_HOST_NOTIFY,
> pm_runtime_get_sync is called in order to always keep active the
> adapter. However later on, pm_runtime_put_sync is never called
> within the function in case of an error. This commit add this
> error handling.
> 
> Fixes: 72bfcee11cf8 ("i2c: Prevent runtime suspend of adapter when Host Notify is required")
> Signed-off-by: Alain Volmat <alain.volmat@st.com>

Applied to for-current, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 139aea351ffb..2e4560671183 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -338,8 +338,10 @@  static int i2c_device_probe(struct device *dev)
 		} else if (ACPI_COMPANION(dev)) {
 			irq = i2c_acpi_get_irq(client);
 		}
-		if (irq == -EPROBE_DEFER)
-			return irq;
+		if (irq == -EPROBE_DEFER) {
+			status = irq;
+			goto put_sync_adapter;
+		}
 
 		if (irq < 0)
 			irq = 0;
@@ -353,15 +355,19 @@  static int i2c_device_probe(struct device *dev)
 	 */
 	if (!driver->id_table &&
 	    !i2c_acpi_match_device(dev->driver->acpi_match_table, client) &&
-	    !i2c_of_match_device(dev->driver->of_match_table, client))
-		return -ENODEV;
+	    !i2c_of_match_device(dev->driver->of_match_table, client)) {
+		status = -ENODEV;
+		goto put_sync_adapter;
+	}
 
 	if (client->flags & I2C_CLIENT_WAKE) {
 		int wakeirq;
 
 		wakeirq = of_irq_get_byname(dev->of_node, "wakeup");
-		if (wakeirq == -EPROBE_DEFER)
-			return wakeirq;
+		if (wakeirq == -EPROBE_DEFER) {
+			status = wakeirq;
+			goto put_sync_adapter;
+		}
 
 		device_init_wakeup(&client->dev, true);
 
@@ -408,6 +414,10 @@  static int i2c_device_probe(struct device *dev)
 err_clear_wakeup_irq:
 	dev_pm_clear_wake_irq(&client->dev);
 	device_init_wakeup(&client->dev, false);
+put_sync_adapter:
+	if (client->flags & I2C_CLIENT_HOST_NOTIFY)
+		pm_runtime_put_sync(&client->adapter->dev);
+
 	return status;
 }