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);