From nobody Fri Jul 24 21:27:35 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2651A35203D for ; Fri, 24 Jul 2026 13:12:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784898744; cv=none; b=SW7PEqbzqMyX9UtykMy5/Y/4vFDyzxU0sC+/jBRvBAcQNsgPlbRxUBpjCS9SXkEbN74wJh/7dP7H+2bdsVlp3E3ofpEQzXeGQwdbEqtWaLvzEgviRhac9+bxlAFkj+XUVhNuyO68QxWIXtgSItP1x9t0+buMyOjMU0dkkVM79mY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784898744; c=relaxed/simple; bh=S7Y8t4dcIthKykzBNL2s+eXrDh6GtFtLucUjWpYDR94=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QnL12vg3OzxXZPxVpnNQ2nZ+vXTDymil5V/GBpzMvBlgEFOGEbPbOelxJ3bo/ArkEaCKeMWgxX1KLsI0gGjgSafs9JsHD38FldyHEPTmuqz8B9t8Z7/jAE+PmWjfPoSim4MJP6Ou0I8sD/UiS0OoCSqTIXR6Yp3cPB2Scs+AHKA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ICqWoo/5; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ICqWoo/5" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-84e27035206so323615b3a.3 for ; Fri, 24 Jul 2026 06:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784898742; x=1785503542; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sFKNVa2uScHavigTP/Jv9UBdhKrx9CJ9eCeBI3gBJk4=; b=ICqWoo/5041SzBHquvqNjV5fCmetXkdgRMuA+qUFy+94R0qymSeVtm3EAN1MxTyn6p VptsxD0jscFh5XxO1CunRaR69aTHiJxwGW6dnyg3lD4xzQPrxuhwn8I1Ava/YhDxgkOX +kRIx6YiAmoynRumoeXAe8rqfzzuxGPo3i9tnK3sx0blNax1em9uUAEFrW145OjHkkaT tvTyRKIP6S8Tnr3Bfey3W3bkmHZdu7dfg2EU+GxYP33xraCn7cNlE0JuIbBhwr9l43CF UcoxWNA0falNxVDbBfoJAwGCIsF808GDhYE1W+uMA1XugBlOj3BT+TBJ6/XNZwi2DLAf 9rxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784898742; x=1785503542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=sFKNVa2uScHavigTP/Jv9UBdhKrx9CJ9eCeBI3gBJk4=; b=LkEqwG/G3hE5Jp183Pp+7wDBdgdGkCRO7lRifegxd+o3dhsxmX5kuXVd3kT6GYbkTI 2Aci5omOv1V2F6L0D8ZPy72m4jtW7YoWdXanSrgdwwJnbD8cK647AJsauH35jZk3J2d5 VTjc2o9sCof/t12+bnChwUltsKWPw5LHY/GooU54ymGUSMkh7i+8QM+krsrgvr/L9I+W eu735EneWuvES+ZZaLY1DKJIRctPCWyFot+6p5MbxmQ1t6vwrkeq8N9F9g3/sQ+IBXJ0 cpZMYYBppMCUcboI+EqEg/zxNAwWrPdSbAE6NCkULwYMF2CXX2xcfuJ+Q7Shmv88HqCh +tvg== X-Forwarded-Encrypted: i=1; AHgh+Ro0FF0xXmw8zNyjnmVNMOevCuVGugk9jQ6VYJW7gP23cqR9LKfHtAzIyQfU56SVWBkmpnlzt9ODAzdwBvQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwrxTDnlJ0IXEykisfkD168BNQK0gjDrCyfxQn7/moWxrwHNWAt aaOvHvtIbsQU2ej44JReo50vOb0s3SxzZixgR0+j+h6UMphGn/uvS0+s X-Gm-Gg: AR+sD10qPUDThJw79GKWcWgVza+tEie6622PYDO8+SN9yx2mkcfL4DIxSgV8OK29obA IyUQAic6UrGce0hWpN/xGI5CeEqfo8tTludrHC0TdGZngXbzk+Oel7N0yIklZIpOL9QMRkKykCf QWmu9leK3YuPvaTww0/f4zGcB+uMT3SQxBA38If2VYa5l1eYGsYfKEpMB/UGcfAOSJy2e8eTyyI DaisePjSFYaF5rkFY8CjYNVNY7eQSUN21s/LnZrLpNH4CmA3IovJqGLiOSkt/xZNi54XvVYFI+2 A1ferIaDVvPXfSC0UYFnYvxtPj2V5KzkBbAYca8klMUBHkeJb+5Nfmf0poosUU9r8kdIX5u/4Pf ujo06ZN56DHDkOLF4CgdDL6CFR6dXOevQyvEDZwWWtD02cBcPBWdRvEWvZJOQaKQVdUZXGV/Gt7 qyL/wF7fshbkH5WXPeZGkJy9a4JzRZwq4QRsI1DqCmS/Mk7wTAgrALZBEmsUd2 X-Received: by 2002:a05:6a00:139c:b0:848:4c3d:659f with SMTP id d2e1a72fcca58-84e2c29b83fmr8147681b3a.75.1784898742361; Fri, 24 Jul 2026 06:12:22 -0700 (PDT) Received: from debian-rockchip-rock5b-rk3588.. ([184.22.139.118]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84e175ce455sm4666968b3a.48.2026.07.24.06.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2026 06:12:21 -0700 (PDT) From: Tharit Tangkijwanichakul To: Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Mauro Carvalho Chehab , Heiko Stuebner Cc: Ezequiel Garcia , Hans Verkuil , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org, me@brighamcampbell.com, jkoolstra@xs4all.nl, Tharit Tangkijwanichakul Subject: [PATCH v2] media: hantro: release runtime resources when device_run fails Date: Fri, 24 Jul 2026 13:12:08 +0000 Message-ID: <20260724131208.2315-1-tharitt97@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" device_run() acquires a runtime PM reference and enables the VPU clocks before invoking the codec-specific run callback. If clk_bulk_enable() fails, the runtime PM reference is left held. If the codec-specific run callback fails, both the enabled clocks and the runtime PM reference are left held. Add separate error paths to release the resources acquired by device_run(). Disable the clocks when the codec run callback fails, and drop the runtime PM reference when either clock enabling or the codec run callback fails. Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver") Signed-off-by: Tharit Tangkijwanichakul --- Changes in v2: - Fix the codec run failure path to disable the clocks before dropping the runtime PM reference. - Use a local vpu variable in device_run(). Tested on a Rockchip RK3588 (Rock 5B) board with Fluster: H.264 (JVT-AVC_V1): 129/135, unchanged MPEG-2 (MPEG2_VIDEO-MAIN): 23/43, unchanged VP8 (VP8-TEST-VECTORS): 61/61, unchanged drivers/media/platform/verisilicon/hantro_drv.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/medi= a/platform/verisilicon/hantro_drv.c index 2e81877f640f..72250bb56872 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -170,29 +170,34 @@ void hantro_end_prepare_run(struct hantro_ctx *ctx) static void device_run(void *priv) { struct hantro_ctx *ctx =3D priv; + struct hantro_dev *vpu =3D ctx->dev; struct vb2_v4l2_buffer *src, *dst; int ret; =20 src =3D hantro_get_src_buf(ctx); dst =3D hantro_get_dst_buf(ctx); =20 - ret =3D pm_runtime_resume_and_get(ctx->dev->dev); + ret =3D pm_runtime_resume_and_get(vpu->dev); if (ret < 0) goto err_cancel_job; =20 - ret =3D clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks); + ret =3D clk_bulk_enable(vpu->variant->num_clocks, vpu->clocks); if (ret) - goto err_cancel_job; + goto err_pm_put_autosuspend; =20 v4l2_m2m_buf_copy_metadata(src, dst); =20 if (ctx->codec_ops->run(ctx)) - goto err_cancel_job; + goto err_disable_clock; =20 return; =20 +err_disable_clock: + clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks); +err_pm_put_autosuspend: + pm_runtime_put_autosuspend(vpu->dev); err_cancel_job: - hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR); + hantro_job_finish_no_pm(vpu, ctx, VB2_BUF_STATE_ERROR); } =20 static const struct v4l2_m2m_ops vpu_m2m_ops =3D { --=20 2.47.3