From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 8D5183B71BE for ; Wed, 29 Jul 2026 06:07:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785305253; cv=none; b=hso+5CkrbifzcvOeQGtzx0Dwefx0o/tDN0TtGsvyHvxYueuFTETTQDvWqFf9NmYlzSM2sWUb5Wjy2f1GOxsUXNok4yDuZDv/287v8bo31kU9cNys6ZshHA+lvUfwoc9PL/zT7gIVEuzO3qUJCVDcaUoeo3AObmsBfpiLFoI49Jg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785305253; c=relaxed/simple; bh=BPHiLpsWld1Ew5XUZl5sR5LEspPsATRgJZe6tzn6vfA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hAjG4q528cHXE65dBpWhMeU9pn8X8sjjQ0EZd7ATvjbh3vch7mGo74peU7aesNjZlz+QCp7GWsVBZ2ryzUGmkmB4tKKfJFENPlfZxEOSAo6lrPAbKXI23YrFNSqAf2cbMFNgJvxe2KCUzgT5t+TaXDSV8VNQsBXBxHdQyR9zgF4= 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=D358vBhU; arc=none smtp.client-ip=209.85.210.171 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="D358vBhU" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-84e0688b859so268784b3a.0 for ; Tue, 28 Jul 2026 23:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785305252; x=1785910052; 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=Hu86WNjJ+kA/XeSuM7zN7dq8Faj07B8lKH5Il6BqR+4=; b=D358vBhUFIM+9QiLHc8VLy6bNQy2CokbiEPbYM2zGsqlBcIeD/JzaMu/MDmdrlS2E+ WGR7L0IM0r5ORf+iwW21oemHM5p+HBLptTkDYisebxlq75D8vprqTG85qcbWOgpq3ABg PkxRDmW9MKJAhGgvuV2tjvj7pj/YBCjlQvJrS/+TuumaVgpJxWo9rVmD+gSYbJGVYMVF fxPqC90Ei8ViC0VMrY9j304+Q8w1wivqwutUCWYbxQMd7sx1VrLrw/NChM7TvdI3MyB3 pSl+JTiHm6mzgQCN9jzxcf4G/efH9TgfmyCyJfzDE6uanPfJ9SR9tiKSqamARWOPYmHF e/Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785305252; x=1785910052; 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=Hu86WNjJ+kA/XeSuM7zN7dq8Faj07B8lKH5Il6BqR+4=; b=UF8oY3u9Wf9ySHxeeQEzR3gEoREf73jMV9YITFItz5OCMpIitj3IzxPsBo1xI0muxJ pRPe15FmFWE3pVbi0iKMdIw1D34QB2LAmeV0GBf6ELLvI0VLeIng+OXdtt05Pndtp8op jxpGAyFs5ruNSCxx63fKqbmE8ojADWRkXg8dkn80FSOiUcEIsMhvaTINesvhvgaZZWto Y7xOSERldfJYgafWAW9hvXFDAHcavLTKZquT5F0v5sN2/62XZCvSYSbqIvllO0xA4+yI oCU9DBcW2ay+YtvRElb3531XImTNc2+UIMB89SfllqJGhA+lPkD6oq3RXmjseKpVPYgC 36VA== X-Forwarded-Encrypted: i=1; AHgh+Rpsf8tvD0P6WHORi2Zq65G/CQZa4A6UoemnZUJZjtu+VDj8FYvKHrddkGbf+VDZunJC3s3TL3AIyO1pDd0=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7eBxAcGn+7uurV5E5xnOfqMR2R997cqE8kmuly2JnJNg4u6o0 vy2hEIbh2dZ5h2VN9BkBQFQfb8tpQeY8x7EiCcjvhAd03ex31dpf87MV X-Gm-Gg: AR+sD13RGG36z2MzLCwL2vd+e+hgu/6vYiqYMJi0B5q+SgWztYN2UClxHh8U4iQNsJ6 tzLJJyAseVQrXlDRpRzOR0LMgVs7342M0Q2eXjDKLaaF2uWeCeVat/Bia+agZH3ZpaXoLRctsc9 4O4gsfAvko7tGyOhInLRSlVlPjzWugxFYZJmK/RnV3FYYGfC85ffiNkMCm6MO5vjKL9QJx9EImY llu/HAy7WXmKESOkCqh22lJ4E9YhzEBMrmXLlbCQBItUYI8xdfuNMPMpLeRbQM6AVixxuKl5zq9 VeyX4TUleI84R/ZPvsMLUi/MknR7nBcD0mPcawJ65MhBvd99x1Y/lfJiTLV7MlRLpula/hqS1dK IKVZj2LpcbRhomgELMDQaJY8CXQV72JslUk2ZJQg28mCJdyVcKJIqQ4ncEeZr/AHIyFQ3Mr/bPq VuX1NWCKY7ja8Y7RNLwfduZ9aq+yP89apS/YDLomJ6/Qw1bxP7nYMOlOhmdW/dx70JOw/+3TOf/ IkeHwfsBzTbsKH3xY1gChXEYTlVVmoD6kLl9Mkab1tx/4uqaco= X-Received: by 2002:a05:6a00:b91:b0:82f:38df:681c with SMTP id d2e1a72fcca58-84e931ec99amr5885268b3a.6.1785305251710; Tue, 28 Jul 2026 23:07:31 -0700 (PDT) Received: from debian-rockchip-rock5b-rk3588.. ([2405:9800:b670:b64b:1c6e:95da:41c0:e7b6]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84ea02f8473sm805504b3a.31.2026.07.28.23.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 23:07:31 -0700 (PDT) From: Tharit Tangkijwanichakul To: Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Mauro Carvalho Chehab 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, Frank.li@oss.nxp.com, Tharit Tangkijwanichakul Subject: [PATCH v5 1/2] media: hantro: release runtime resources when device_run fails Date: Wed, 29 Jul 2026 06:04:39 +0000 Message-ID: <20260729060440.2092-2-tharitt97@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260729060440.2092-1-tharitt97@gmail.com> References: <20260729060440.2092-1-tharitt97@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Make the clocks part of the device's runtime PM state by enabling them from the runtime-resume callback and disabling them from the runtime-suspend callback. Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver") Signed-off-by: Tharit Tangkijwanichakul --- .../media/platform/verisilicon/hantro_drv.c | 66 +++++++++++-------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c index 2e81877f640f..d6fcd4f7f9da 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -59,8 +59,7 @@ static const struct v4l2_event hantro_eos_event = { .type = V4L2_EVENT_EOS }; -static void hantro_job_finish_no_pm(struct hantro_dev *vpu, - struct hantro_ctx *ctx, +static void hantro_job_finish_no_pm(struct hantro_ctx *ctx, enum vb2_buffer_state result) { struct vb2_v4l2_buffer *src, *dst; @@ -86,15 +85,13 @@ static void hantro_job_finish_no_pm(struct hantro_dev *vpu, result); } -static void hantro_job_finish(struct hantro_dev *vpu, - struct hantro_ctx *ctx, +static void hantro_job_finish(struct hantro_ctx *ctx, enum vb2_buffer_state result) { - pm_runtime_put_autosuspend(vpu->dev); - - clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks); + struct hantro_dev *vpu = ctx->dev; - hantro_job_finish_no_pm(vpu, ctx, result); + pm_runtime_put_autosuspend(vpu->dev); + hantro_job_finish_no_pm(ctx, result); } void hantro_irq_done(struct hantro_dev *vpu, @@ -111,7 +108,7 @@ void hantro_irq_done(struct hantro_dev *vpu, if (cancel_delayed_work(&vpu->watchdog_work)) { if (result == VB2_BUF_STATE_DONE && ctx->codec_ops->done) ctx->codec_ops->done(ctx); - hantro_job_finish(vpu, ctx, result); + hantro_job_finish(ctx, result); } } @@ -127,7 +124,7 @@ void hantro_watchdog(struct work_struct *work) vpu_err("frame processing timed out!\n"); if (ctx->codec_ops->reset) ctx->codec_ops->reset(ctx); - hantro_job_finish(vpu, ctx, VB2_BUF_STATE_ERROR); + hantro_job_finish(ctx, VB2_BUF_STATE_ERROR); } } @@ -170,29 +167,24 @@ void hantro_end_prepare_run(struct hantro_ctx *ctx) static void device_run(void *priv) { struct hantro_ctx *ctx = priv; + struct hantro_dev *vpu = ctx->dev; struct vb2_v4l2_buffer *src, *dst; int ret; src = hantro_get_src_buf(ctx); dst = hantro_get_dst_buf(ctx); - ret = pm_runtime_resume_and_get(ctx->dev->dev); - if (ret < 0) - goto err_cancel_job; - - ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks); - if (ret) - goto err_cancel_job; + ret = pm_runtime_resume_and_get(vpu->dev); + if (ret < 0) { + hantro_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR); + return; + } v4l2_m2m_buf_copy_metadata(src, dst); - if (ctx->codec_ops->run(ctx)) - goto err_cancel_job; - - return; - -err_cancel_job: - hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR); + ret = ctx->codec_ops->run(ctx); + if (ret) + hantro_job_finish(ctx, VB2_BUF_STATE_ERROR); } static const struct v4l2_m2m_ops vpu_m2m_ops = { @@ -1296,10 +1288,30 @@ static void hantro_remove(struct platform_device *pdev) static int hantro_runtime_resume(struct device *dev) { struct hantro_dev *vpu = dev_get_drvdata(dev); + int ret; + + ret = clk_bulk_enable(vpu->variant->num_clocks, vpu->clocks); + if (ret) + return ret; + + if (vpu->variant->runtime_resume) { + ret = vpu->variant->runtime_resume(vpu); + if (ret) + goto err_disable_clocks; + } + + return 0; - if (vpu->variant->runtime_resume) - return vpu->variant->runtime_resume(vpu); +err_disable_clocks: + clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks); + return ret; +} +static int hantro_runtime_suspend(struct device *dev) +{ + struct hantro_dev *vpu = dev_get_drvdata(dev); + + clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks); return 0; } #endif @@ -1307,7 +1319,7 @@ static int hantro_runtime_resume(struct device *dev) static const struct dev_pm_ops hantro_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) - SET_RUNTIME_PM_OPS(NULL, hantro_runtime_resume, NULL) + SET_RUNTIME_PM_OPS(hantro_runtime_suspend, hantro_runtime_resume, NULL) }; static struct platform_driver hantro_driver = { -- 2.47.3