From patchwork Wed Apr 28 14:51:32 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: 12228971 X-Patchwork-Delegate: kieran@bingham.xyz 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=ham 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 3F46FC433B4 for ; Wed, 28 Apr 2021 14:52:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81A7361435 for ; Wed, 28 Apr 2021 14:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240287AbhD1Oxa (ORCPT ); Wed, 28 Apr 2021 10:53:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:35766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240269AbhD1Ox3 (ORCPT ); Wed, 28 Apr 2021 10:53:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C0EE461447; Wed, 28 Apr 2021 14:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619621563; bh=vSVgVx9oCI4BykR40BTa4+7tin+dlK2U4+Benc8+UkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IjmvDkezJvua0hzghdBZ4nL75WLBAmx7//xkI7b0W/JXRMiVDeYzNgmx38tXV6rku 2q68MMjEiNSRUwocDaahV8E0WBTtGDrvkm8d6v+ORAoUXoy+S9eKyGbvHPmYTzrsCN eSZufzbPLh+8YA1rodM3dX3zHPoH0mlG71MUW7LVl8VrwLLxZapIP3SvpTTOy2YG// +IdV1llrv2lUlxrSAluaiNTWrVadyvKZohfQJ0U5ee90AstCGV1sYU+jJTX17V2M7a ZV12rplqUy8Gv8Is3Nqj0ojpD43bBz44OSk4aP7/TMKJe8LkybBF4Uimksyv1CVLLz yf2W3T81gkrrQ== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lblYP-001Dq7-ST; Wed, 28 Apr 2021 16:52:41 +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 v4 11/79] media: rcar_fdp1: fix pm_runtime_get_sync() usage count Date: Wed, 28 Apr 2021 16:51:32 +0200 Message-Id: <6fb49df1ba7c80c2e6c51fb95322e025243ce36c.1619621413.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-renesas-soc@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) {