From patchwork Tue Apr 27 10:26:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 428163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70416C43470 for ; Tue, 27 Apr 2021 10:27:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DC4460FDC for ; Tue, 27 Apr 2021 10:27:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237728AbhD0K20 (ORCPT ); Tue, 27 Apr 2021 06:28:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:48146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235540AbhD0K2E (ORCPT ); Tue, 27 Apr 2021 06:28:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 27746613DD; Tue, 27 Apr 2021 10:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619519236; bh=vSVgVx9oCI4BykR40BTa4+7tin+dlK2U4+Benc8+UkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pLaCD4ofqL5rXZRv9KJFm6qqqJsqVPXNi3IXzSjhGRLDdW9MBRZ5iVhqvRmUsYonP pp/8ZGF5xrtnUbbOYSWlRQINpYubh4VTxzD3w4u0Iju9BCtsQan3Iqzo20e/4fiBj4 wxkWEB0iHbYNMPZGR53hBhM2d5U/JxEdM8oYQDBWebB1B9h5izn7/ETooQ6QCwhxkp G/c2H4Z7DdKUO7rT0RA2MTGfoywUxW7tdohSAPKwaQz3RKVmyG5tmdv4nX5r5k0ndt BUwSrcXKUpluwk7ocgeR1Fbk6KUhTz2o1P3azH9yfzFLwvWDkHsAL0dO/nTHDoVTb7 UU8L4DE3DAZDg== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lbKvv-000nzh-BP; Tue, 27 Apr 2021 12:27:11 +0200 From: Mauro Carvalho Chehab Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , Kieran Bingham , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v3 10/79] media: rcar_fdp1: fix pm_runtime_get_sync() usage count Date: Tue, 27 Apr 2021 12:26:00 +0200 Message-Id: <9a79a72f93981227f21cd8fa8fc8c2d26eeb4d7b.1619519080.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors. Replace it by the new pm_runtime_resume_and_get(), introduced by: commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter and avoid memory leaks. Also, right now, the driver is ignoring any troubles when trying to do PM resume. So, add the proper error handling for the code. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/rcar_fdp1.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/rcar_fdp1.c b/drivers/media/platform/rcar_fdp1.c index 01c1fbb97bf6..c32d237af618 100644 --- a/drivers/media/platform/rcar_fdp1.c +++ b/drivers/media/platform/rcar_fdp1.c @@ -2140,7 +2140,13 @@ static int fdp1_open(struct file *file) } /* Perform any power management required */ - pm_runtime_get_sync(fdp1->dev); + ret = pm_runtime_resume_and_get(fdp1->dev); + if (ret < 0) { + v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); + v4l2_ctrl_handler_free(&ctx->hdl); + kfree(ctx); + goto done; + } v4l2_fh_add(&ctx->fh); @@ -2351,7 +2357,9 @@ static int fdp1_probe(struct platform_device *pdev) /* Power up the cells to read HW */ pm_runtime_enable(&pdev->dev); - pm_runtime_get_sync(fdp1->dev); + ret = pm_runtime_resume_and_get(fdp1->dev); + if (ret < 0) + return ret; hw_version = fdp1_read(fdp1, FD1_IP_INTDATA); switch (hw_version) {