Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4627149pxj; Wed, 12 May 2021 09:32:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHd7wXVcBJc/e8g5FQWiZeezymLIDSMn44N/nO4RgC3DUWgfEaFUuBK8nLyaxeG4Ynfb8Z X-Received: by 2002:a05:6512:21af:: with SMTP id c15mr25613161lft.184.1620837144678; Wed, 12 May 2021 09:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837144; cv=none; d=google.com; s=arc-20160816; b=zO/EJoUlYyB9OSYe8hlXe8eXBqkgDO7Siw/fJrr5+f68D7ZCzSVyIJNCPXiAhhcxe4 FTshZxtIxjdnbhYm+M3011d6lwwAoxDP4KcFHfsNEobaox73tC2sU9r+X5dJ1uF5UIPT MLVGhnotSTWJ6gJl9iNNyLHJPqUQwS3y09OWqlolMsC/kEVjKPw65VhznzRpdZspQPp4 RX6dOLPubzwMcDuTNeLvsPOLX3eZzepDUC9Skwd8fKonCpSVYpPqZNie43pTsbVBdwjp dAx+0Du+Rz9lI7CdiuIRHn4Xx5k1No5QEJmDwWs3XQyPCvrKdlKgCuv0IRXmg3BTJmvk r1rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=c2UIbnFvrkmlJHYP9zmsKnhngqlJhMQ5qTgNqGB9wKw=; b=WdFuf+hUNMrDkvi4HhyfSm10fn09tpDUxgQe0Y3uv7REpRUvWlzhN3l066WUDJkLzm zKZUBMEHXoMt77+Kfovkd0MyWtbfdOa9tmxW0UdDJD2WuED1u1orso7dyL/mUolPUXgK GLQZOAza3UnFiOW1X934Q/YU1dKog/KIO5MyVqj6FIaIRjgFoRltEVd7IGmds/v9RVOb jzmzGRxnqm/9zvemHLqpNaUxXcGrVjyL3N6mwyw0NN6HFw7w5e/7BdjZ12KNYZg60KCW YJMFR3lTc8Qbaw4fQObwC1ZW9kx77fjXsvAvBAV+2RTey53140MaIyc8LRFWesf19V+u dTiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TohWWTfE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z14si351006lji.387.2021.05.12.09.31.53; Wed, 12 May 2021 09:32:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TohWWTfE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241698AbhELQ1x (ORCPT + 99 others); Wed, 12 May 2021 12:27:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:55166 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231665AbhELPiU (ORCPT ); Wed, 12 May 2021 11:38:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1234E61997; Wed, 12 May 2021 15:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832817; bh=uJBrqYu6Ci15ZgIruOM1b0abKixSdzZIsmkHEl1P39A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TohWWTfESHHb065h1BjmEu8KhzoQwo7zXlD2nlOvfskFIvKQEXYtEZs4rF7BV913/ 1dFYzCQwLnl0FhvxtS0+cuYKg60veW/eeCBtKxfTnY9C9MRcmW5vR1pF7FrTqp9ADc 0aQvZ1KnDwMS6bde14BNxXuMHT+aZMdptFSEIzPs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Qinglang Miao , Wolfram Sang , Sasha Levin Subject: [PATCH 5.10 434/530] i2c: stm32f7: fix reference leak when pm_runtime_get_sync fails Date: Wed, 12 May 2021 16:49:04 +0200 Message-Id: <20210512144834.025265233@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qinglang Miao [ Upstream commit 2c662660ce2bd3b09dae21a9a9ac9395e1e6c00b ] The PM reference count is not expected to be incremented on return in these stm32f7_i2c_xx serious functions. However, pm_runtime_get_sync will increment the PM reference count even failed. Forgetting to putting operation will result in a reference leak here. Replace it with pm_runtime_resume_and_get to keep usage counter balanced. Fixes: ea6dd25deeb5 ("i2c: stm32f7: add PM_SLEEP suspend/resume support") Reported-by: Hulk Robot Signed-off-by: Qinglang Miao Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-stm32f7.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c index 674735334547..1e800b65e20a 100644 --- a/drivers/i2c/busses/i2c-stm32f7.c +++ b/drivers/i2c/busses/i2c-stm32f7.c @@ -1652,7 +1652,7 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap, i2c_dev->msg_id = 0; f7_msg->smbus = false; - ret = pm_runtime_get_sync(i2c_dev->dev); + ret = pm_runtime_resume_and_get(i2c_dev->dev); if (ret < 0) return ret; @@ -1698,7 +1698,7 @@ static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, f7_msg->read_write = read_write; f7_msg->smbus = true; - ret = pm_runtime_get_sync(dev); + ret = pm_runtime_resume_and_get(dev); if (ret < 0) return ret; @@ -1799,7 +1799,7 @@ static int stm32f7_i2c_reg_slave(struct i2c_client *slave) if (ret) return ret; - ret = pm_runtime_get_sync(dev); + ret = pm_runtime_resume_and_get(dev); if (ret < 0) return ret; @@ -1880,7 +1880,7 @@ static int stm32f7_i2c_unreg_slave(struct i2c_client *slave) WARN_ON(!i2c_dev->slave[id]); - ret = pm_runtime_get_sync(i2c_dev->dev); + ret = pm_runtime_resume_and_get(i2c_dev->dev); if (ret < 0) return ret; @@ -2277,7 +2277,7 @@ static int stm32f7_i2c_regs_backup(struct stm32f7_i2c_dev *i2c_dev) int ret; struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs; - ret = pm_runtime_get_sync(i2c_dev->dev); + ret = pm_runtime_resume_and_get(i2c_dev->dev); if (ret < 0) return ret; @@ -2299,7 +2299,7 @@ static int stm32f7_i2c_regs_restore(struct stm32f7_i2c_dev *i2c_dev) int ret; struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs; - ret = pm_runtime_get_sync(i2c_dev->dev); + ret = pm_runtime_resume_and_get(i2c_dev->dev); if (ret < 0) return ret; -- 2.30.2