From mboxrd@z Thu Jan 1 00:00:00 1970 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=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 851FCC11F8E for ; Sun, 4 Jul 2021 23:13:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CB95613F1 for ; Sun, 4 Jul 2021 23:13:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232339AbhGDXPg (ORCPT ); Sun, 4 Jul 2021 19:15:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:50748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233983AbhGDXOt (ORCPT ); Sun, 4 Jul 2021 19:14:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 62A9F613FB; Sun, 4 Jul 2021 23:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625440249; bh=w65wNTosxvkJpMQt77u2qGKGhUFqRbRGDrcnbeQE4FU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gdtf3QYdx46yNYvdwHvcTOMmFEwS8BrsfDjqkWSQp83ESx3IkmOwXhfyV0LrPMO2J ivmFvTOYeTQejFm2T3SU1EdOPIpshUmBXf9hKjgAC+zkdx5JlJMEJq2gTd2owKU7Jm YOtjsiobTmhCI8+5+jxfmlaZEGq2YSWPeiiZOVeK2oMu/5vZ5bxUAfspyA4kD3px0b ZBa6+ga5qK27C1e5p/vw++fAB571lB8lz49mwdjNS24JKzVr90GFq+p8F3nDCPzWm4 LrNgzvNPOslLGpP1IUJ4p6Flt0StRKxsaRcqg7ce0efyAOXtoGrGxlaYzviAz+IVQ9 i+Td+g8pgfHUQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mauro Carvalho Chehab , Jonathan Cameron , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 04/31] media: sti/bdisp: fix pm_runtime_get_sync() usage count Date: Sun, 4 Jul 2021 19:10:16 -0400 Message-Id: <20210704231043.1491209-4-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704231043.1491209-1-sashal@kernel.org> References: <20210704231043.1491209-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Mauro Carvalho Chehab [ Upstream commit c44eac5b72e23c31eefc0e10a71d9650036b8341 ] The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors. The bdisp_start_streaming() doesn't take it into account, which would unbalance PM usage counter at bdisp_stop_streaming(). The logic at bdisp_probe() is correct, but the best is to use the same call along the driver. So, 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, avoiding a potential PM usage counter leak. Reviewed-by: Jonathan Cameron Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/sti/bdisp/bdisp-v4l2.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c index 00f6e3f06dac..1fb04dc0f7d0 100644 --- a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c +++ b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c @@ -499,7 +499,7 @@ static int bdisp_start_streaming(struct vb2_queue *q, unsigned int count) { struct bdisp_ctx *ctx = q->drv_priv; struct vb2_v4l2_buffer *buf; - int ret = pm_runtime_get_sync(ctx->bdisp_dev->dev); + int ret = pm_runtime_resume_and_get(ctx->bdisp_dev->dev); if (ret < 0) { dev_err(ctx->bdisp_dev->dev, "failed to set runtime PM\n"); @@ -1368,10 +1368,10 @@ static int bdisp_probe(struct platform_device *pdev) /* Power management */ pm_runtime_enable(dev); - ret = pm_runtime_get_sync(dev); + ret = pm_runtime_resume_and_get(dev); if (ret < 0) { dev_err(dev, "failed to set PM\n"); - goto err_pm; + goto err_remove; } /* Filters */ @@ -1399,6 +1399,7 @@ static int bdisp_probe(struct platform_device *pdev) bdisp_hw_free_filters(bdisp->dev); err_pm: pm_runtime_put(dev); +err_remove: bdisp_debugfs_remove(bdisp); err_v4l2: v4l2_device_unregister(&bdisp->v4l2_dev); -- 2.30.2