From patchwork Fri Dec 15 10:45:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 179167 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9180154dys; Fri, 15 Dec 2023 02:46:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJR/SCYRshwksdWv7VwAtNd5JGp/PNX9JyjVCDYLnzqUTvMjM2ZXjITP7MLq7c/a6X2ONt X-Received: by 2002:a50:9b1d:0:b0:551:7f8c:fb63 with SMTP id o29-20020a509b1d000000b005517f8cfb63mr3019869edi.5.1702637211238; Fri, 15 Dec 2023 02:46:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702637211; cv=none; d=google.com; s=arc-20160816; b=Gf2ftnO8yxhozZjw0uQW9DtNJfGTrJAcTULseISLFkjloNiULFjz6ahM4YuH5tJQwd uje3vJfPp95djS50lgbX8Eby1RT6JU+53vjanUhTo7T2QGjuYI9hrXWlvdymr5pqpwno sMW3JZOrdXXdNOvYn9s6tOJAkvSXxnN29Vdt3/Afkdlf2OE9SL1SnRoH2Ex1HQAzbr8+ wH6VIUtv70cJIDCsszKTyyP41sszhuntmfgfmiIKRwqV5tcx9dC6q7LKO67rlS22xDlB kIl684SGzwgJJ7yqkgdk5+5GZ2ATjKRWTxhnG9/3QKIlEaIRFz82Rv4jiUw9orO91Y+1 k8dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=LdJTPTDnLTf9kEJ7PkTvN4wTkh0mh5SbB73dk5lwsxI=; fh=uXuiAKCIzcls/bVWehiPG5bGSzwyo88Xr298kNzj2n4=; b=P+RsEzBR3pAFehdoE2Go2GxyjXcpBT4BLikxhurG3VgWvKvgcCXm/ZHSuSN7AN/D+U 2enk8+r53KtRB4SBGCdu1wa1IGu4ivGyMVFA4Yb7ssCBi17jWThznTr09+YmB/lwc1ia dDYvVOMP+F6iWMUi08oE+0BsH4N3Cp40B/btPunufAZI06hrDeF6hU/kWBi899JOFCo/ ZwSd2YClaplmhYKdZbSy/DRE/9Okf1X7JFdXb6+A7tlyV63gdsXq4Azz216QefScsJlx 3rg6V7Y5mhvul5NzD5/i2UuUMf2zl3Ix0TJV42AOYJd7t0gzSna/OhBS3wIoNxT0BBSq 7tXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=pb8PJbqp; spf=pass (google.com: domain of linux-kernel+bounces-776-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-776-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ch5-20020a0564021bc500b0055290b37b57si857054edb.243.2023.12.15.02.46.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 02:46:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-776-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=pb8PJbqp; spf=pass (google.com: domain of linux-kernel+bounces-776-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-776-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D45A71F2170D for ; Fri, 15 Dec 2023 10:46:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1533250E8; Fri, 15 Dec 2023 10:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="pb8PJbqp" X-Original-To: linux-kernel@vger.kernel.org Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6350C1A70D; Fri, 15 Dec 2023 10:46:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1702637164; bh=vBgnugLtJ2ksG5oto5YXrGX8SezSV/Kyn/381DDZeYc=; h=From:To:Cc:Subject:Date:From; b=pb8PJbqphVWYId84ZtJMvFx1CSLEHxwibQFvmpAV6BPTT5zPu4AEd59vDh7i6d1By y53CNsHbMrgc2CEi94oADY0uGtBCNQpWRRCyDBK/Zc0BcZ891quCtKhe6q+6gcLx+j L2UJkfxoaFXO69OGz+62j0dy0CsX1J8KsDhd6ZBEAokxqtSSZU+rJvmefOEwkb9D7W FS6I+6ZMMAuNnWIMGFxtMOw+IKwTr/On/GaIMWe2x+10JqnFqyfnqnqtitpUjs3b8L xbvoEaKKSxY7c9Q9sonGldx3Bg0Gs+GfsA6nhU9zxm2IwMAbsSe9imTTo99Ty3Q72y K0Hq1FGidKiCA== 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 B3207378107D; Fri, 15 Dec 2023 10:46:03 +0000 (UTC) From: Eugen Hristev To: linux-mediatek@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, angelogioacchino.delregno@collabora.com, matthias.bgg@gmail.com, linux-media@vger.kernel.org, tiffany.lin@mediatek.com, andrew-ct.chen@mediatek.com, Eugen Hristev Subject: [PATCH v2 1/7] media: mediatek: vcodec: fix possible unbalanced PM counter Date: Fri, 15 Dec 2023 12:45:45 +0200 Message-Id: <20231215104551.233679-1-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785344516801843444 X-GMAIL-MSGID: 1785344516801843444 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 Reviewed-by: AngeloGioacchino Del Regno --- Changes in v2: - collect R-b .../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; }