Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5274673rdb; Wed, 13 Dec 2023 04:22:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHezlbjp9A+hLj0WzUoAFX6G7j4Ja5NOGWZDSQPo80U596sMwFH6Vn97+aqdKAXmVRAkDuK X-Received: by 2002:a05:6a20:8f1e:b0:18c:7b7:8630 with SMTP id b30-20020a056a208f1e00b0018c07b78630mr4480909pzk.13.1702470143316; Wed, 13 Dec 2023 04:22:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702470143; cv=none; d=google.com; s=arc-20160816; b=gUiZrvU6vLtb2qrmPJbsQAGU0GVAjDnql06X+LKTZWoLhbTfLLN6gCaGAcibeqCRqu DCEffEO9lfVaU2NiAX08PPcAIzwgUfFFGArJ7J6KdRFWHbLhqT1Pssfr1qHmC6jfp5GC 8kFwo7s4GOLPshiAx8gn1iM8amZ4cXp+dffa0Fe23KaRId/MpcIU//7Xwqx27x0mJkfg xHCOybcHPI3kWF+UaoB04FkdYdn7NHf/VEPlztmz1tvYiTqk67XdX6LVSgsJFasDbRH6 7xEzKHkkG67xMglwm9cSiVivAQD9PvUpVtVaD+goE7F0A0I0kHK1TrDUGRySc8ZPCF/L qwGw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ynTN1IuO1zTDye8FiGonLkDqRsMwWw2lbWlIxqdkx8o=; fh=g4oV3f7iKx9VOWGuNPxSXFL04A61MFdA76fp5F+qbTY=; b=zF06axR7f2kx2pbnonduy4iA9yCWrPMBPyu4slKes1sea7lKLGKtUGtd0O/jcVId08 5PcL0hLkMw73vIm2Q+hbyTZ+/CTkYnNv1cFTVj8ZsucBTnharIa4nFR8k1kWdtxABUDj 1Bs26zQYqW7qVg0xfc7Yo/wxGNO3cUEX0PM2IDq5c5uGDnrlUKWireHBGLtRknDaE4SR sgStB1ZI/3DZWcaIrvK5ohDjHMBdOWBTK2dvWWBqtkei4zGeFuyuZusP+fkA9qTKUaI2 LDOp3o7aWbvp9MOGz8XZphZalzuJC2dEYgByWrG/bMKAtR5RvaPxHHjSlRckVBBWhvbi rA/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="JWgYlV/K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id ot4-20020a17090b3b4400b00285c4fd2ff0si9919580pjb.116.2023.12.13.04.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 04:22:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="JWgYlV/K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 39B43807E792; Wed, 13 Dec 2023 04:20:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377628AbjLMMU3 (ORCPT + 99 others); Wed, 13 Dec 2023 07:20:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233398AbjLMMU0 (ORCPT ); Wed, 13 Dec 2023 07:20:26 -0500 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [IPv6:2a00:1098:ed:100::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 710E5CF; Wed, 13 Dec 2023 04:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1702470030; bh=9nciZ1s7i4iPVYsAX6ZTDm0XS3kNJiPzFH0jLeN0v0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JWgYlV/K+sX/Xg4s92JYgwTzZOX/1IDaVvv9M5HDRPpldhCk8rQ/LGh6kVLjX7BO0 kgJabGOn+G+9yas1/kvmCS2n3V7Oeu/NtbWXpd7L7ymDFV5bVJJLv5FDZQl6sjLl1o EsLf0OAJ6DZw7HZ1ctmbWuVPiokcXNRjz3JSvbA0F4foify2H0xucCqf0lBuQWjMpl Uajg4uM/w3iXsRSBYbPyODUOQ7nBtDgv8fn1DR54msAWXIvL5CkdOezAv6JE4yLWF6 L3QIMLYW3oglsNNpPpABh1+L7hcPU8aRsLJUbyCf8O3ZA0RL4ivIZTk2VXFuLX51PB A1Fpn9jbwWSNw== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 2D2153781485; Wed, 13 Dec 2023 12:20:29 +0000 (UTC) From: Eugen Hristev To: linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-mediatek@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, angelogioacchino.delregno@collabora.com, kernel@collabora.com, eugen.hristev@collabora.com, tiffany.lin@mediatek.com, andrew-ct.chen@mediatek.com, matthias.bgg@gmail.com Subject: [PATCH 2/4] media: mediatek: vcodec: fix possible unbalanced PM counter Date: Wed, 13 Dec 2023 14:20:15 +0200 Message-Id: <20231213122017.102100-2-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231213122017.102100-1-eugen.hristev@collabora.com> References: <20231213122017.102100-1-eugen.hristev@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Dec 2023 04:20:51 -0800 (PST) It is possible that mtk_vcodec_enc_pw_on fails, and in that scenario the PM counter is not incremented, and subsequent call to mtk_vcodec_enc_pw_off decrements the counter, leading to a PM imbalance. Fix by bailing out of venc_if_encode in the case when mtk_vcodec_enc_pw_on fails. Fixes: 4e855a6efa54 ("[media] vcodec: mediatek: Add Mediatek V4L2 Video Encoder Driver") Signed-off-by: Eugen Hristev --- .../platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c | 4 +++- .../platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h | 2 +- drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c index a22b7dfc656e..1a2b14a3e219 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c @@ -58,13 +58,15 @@ int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev *mtkdev) return 0; } -void mtk_vcodec_enc_pw_on(struct mtk_vcodec_pm *pm) +int mtk_vcodec_enc_pw_on(struct mtk_vcodec_pm *pm) { int ret; ret = pm_runtime_resume_and_get(pm->dev); if (ret) dev_err(pm->dev, "pm_runtime_resume_and_get fail: %d", ret); + + return ret; } void mtk_vcodec_enc_pw_off(struct mtk_vcodec_pm *pm) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h index 157ea08ba9e3..2e28f25e36cc 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h @@ -10,7 +10,7 @@ #include "mtk_vcodec_enc_drv.h" int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev *dev); -void mtk_vcodec_enc_pw_on(struct mtk_vcodec_pm *pm); +int mtk_vcodec_enc_pw_on(struct mtk_vcodec_pm *pm); void mtk_vcodec_enc_pw_off(struct mtk_vcodec_pm *pm); void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm); void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm); diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c index c402a686f3cb..e83747b8d69a 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c @@ -64,7 +64,9 @@ int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx, ctx->dev->curr_ctx = ctx; spin_unlock_irqrestore(&ctx->dev->irqlock, flags); - mtk_vcodec_enc_pw_on(&ctx->dev->pm); + ret = mtk_vcodec_enc_pw_on(&ctx->dev->pm); + if (ret) + goto venc_if_encode_pw_on_err; mtk_vcodec_enc_clock_on(&ctx->dev->pm); ret = ctx->enc_if->encode(ctx->drv_handle, opt, frm_buf, bs_buf, result); @@ -75,6 +77,7 @@ int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx, ctx->dev->curr_ctx = NULL; spin_unlock_irqrestore(&ctx->dev->irqlock, flags); +venc_if_encode_pw_on_err: mtk_venc_unlock(ctx); return ret; } -- 2.34.1