From patchwork Fri Apr 14 02:10:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 673508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E898AC77B6E for ; Fri, 14 Apr 2023 02:10:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229564AbjDNCKe (ORCPT ); Thu, 13 Apr 2023 22:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229840AbjDNCKd (ORCPT ); Thu, 13 Apr 2023 22:10:33 -0400 Received: from www381.your-server.de (www381.your-server.de [78.46.137.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7A614C0D for ; Thu, 13 Apr 2023 19:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=InujrgYEpnGjaxQTOSXV/JHSF24qxaxhamGsR4Tx3+4=; b=en4+18f8kFYwJa3g6TMEcCKFJW cvubvCNB95WMwotoH/vvMjuWHs01vIMsMwX5ICG/ya8R0fIGzNf1AgFDqLy0B99/Wn7vL7PQtxERY K8Ik8etAvRSTY7h/U1mr/cQpruOlAYfPfOHoxIL5yIaMUs82f5sxvTXCO5ZIltnt4R6Au8Vb/3Gg+ 4MMYn1A3z3P7HuhsWneRvUDOoL2Inh+LfvrSm293GyPD0e5wJvjVyJsfL3ZUZezfsp/42TyE50/mL nlaHXw8jell02V4qv5HbEH+G2Z2HWC4WxmHOaV9YbJ2ScEG1/qJ60UbzUTqaiTf4CcNI9gp1MFvIW DodjFJew==; Received: from sslproxy05.your-server.de ([78.46.172.2]) by www381.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pn8tR-0001Rt-2Y; Fri, 14 Apr 2023 04:10:29 +0200 Received: from [136.25.87.181] (helo=lars-desktop.lan) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pn8tQ-000U2N-JY; Fri, 14 Apr 2023 04:10:28 +0200 From: Lars-Peter Clausen To: Wolfram Sang Cc: Michal Simek , Shubhrajyoti Datta , linux-i2c@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path Date: Thu, 13 Apr 2023 19:10:21 -0700 Message-Id: <20230414021022.505291-1-lars@metafoo.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.103.8/26874/Thu Apr 13 09:30:39 2023) Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The cdns_i2c_master_xfer() function gets a runtime PM reference when the function is entered. This reference is released when the function is exited. There is currently one error path where the function exits directly, which leads to a leak of the runtime PM reference. Make sure that this error path also releases the runtime PM reference. Fixes: 1a351b10b967 ("i2c: cadence: Added slave support") Signed-off-by: Lars-Peter Clausen --- drivers/i2c/busses/i2c-cadence.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index f1a67c410ad3..3a4edf7e75f9 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -834,8 +834,10 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, #if IS_ENABLED(CONFIG_I2C_SLAVE) /* Check i2c operating mode and switch if possible */ if (id->dev_mode == CDNS_I2C_MODE_SLAVE) { - if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE) - return -EAGAIN; + if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE) { + ret = -EAGAIN; + goto out; + } /* Set mode to master */ cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id); From patchwork Fri Apr 14 02:10:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 673275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35E2CC77B61 for ; Fri, 14 Apr 2023 02:10:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229840AbjDNCKf (ORCPT ); Thu, 13 Apr 2023 22:10:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbjDNCKd (ORCPT ); Thu, 13 Apr 2023 22:10:33 -0400 Received: from www381.your-server.de (www381.your-server.de [78.46.137.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2855D4EE7 for ; Thu, 13 Apr 2023 19:10:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=S3giKPZigRuTFiX3FzI7sBaXFQd9G5Kio3JWhJ3R0vI=; b=IriTMC+mvZvdgZcg/V36XWk/NM PNxvTImoEkXUEQotoKr3gFir977fmzv8E30z0QNRZ1sJX0Sxyep9WGF8v4J7fEmZRS8S7kkc3xVrW KVeb6gqn4y+QofB383yd0/dWKt+fV/zu6jy2DwkFvpP4Mp+zo9Uw3PdTEXgKgnLhwTHtg1zzZTtmX Knu1XDYbJQCdNA5aCPj1+vGD8r6S8ljr4qNK6dY/MHlSJn+vH6rpKdunic46fr8BOq1usXJhH69Tl wlnaFfrgqhAxs56Q0K4+UE0ueOb1mbIKem1DRp6yOroSXsFIzTuiwUMettLxFB+0vv7d/t7A3UzK6 /KXlq6+w==; Received: from sslproxy05.your-server.de ([78.46.172.2]) by www381.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pn8tS-0001SF-Em; Fri, 14 Apr 2023 04:10:30 +0200 Received: from [136.25.87.181] (helo=lars-desktop.lan) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pn8tS-000U2N-00; Fri, 14 Apr 2023 04:10:30 +0200 From: Lars-Peter Clausen To: Wolfram Sang Cc: Michal Simek , Shubhrajyoti Datta , linux-i2c@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH 2/2] i2c: xiic: xiic_xfer(): Fix runtime PM leak on error path Date: Thu, 13 Apr 2023 19:10:22 -0700 Message-Id: <20230414021022.505291-2-lars@metafoo.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230414021022.505291-1-lars@metafoo.de> References: <20230414021022.505291-1-lars@metafoo.de> MIME-Version: 1.0 X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.103.8/26874/Thu Apr 13 09:30:39 2023) Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The xiic_xfer() function gets a runtime PM reference when the function is entered. This reference is released when the function is exited. There is currently one error path where the function exits directly, which leads to a leak of the runtime PM reference. Make sure that this error path also releases the runtime PM reference. Fixes: fdacc3c7405d ("i2c: xiic: Switch from waitqueue to completion") Signed-off-by: Lars-Peter Clausen --- drivers/i2c/busses/i2c-xiic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index e7d37eb20f2b..8a3d9817cb41 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -1164,7 +1164,7 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) err = xiic_start_xfer(i2c, msgs, num); if (err < 0) { dev_err(adap->dev.parent, "Error xiic_start_xfer\n"); - return err; + goto out; } err = wait_for_completion_timeout(&i2c->completion, XIIC_XFER_TIMEOUT); @@ -1178,6 +1178,8 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) err = (i2c->state == STATE_DONE) ? num : -EIO; } mutex_unlock(&i2c->lock); + +out: pm_runtime_mark_last_busy(i2c->dev); pm_runtime_put_autosuspend(i2c->dev); return err;