From nobody Mon Sep 28 06:37:32 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.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 6C080486B8A for ; Tue, 25 Aug 2026 17:34:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787679268; cv=none; b=S0MqE1fMEWeSZal66Xy74XqwsgQ4gUiWyJCb2h+cSZDk9DGEYN091aFsB3gvPeKD98Dg3DVekDMIEsgHz5FTG2pxhC4Hf6Y3N2OfUHnU5XbzzPEt1rG12MELYI9zEybad9tfb29YlcrBDCG+99QnRos/8wrpn+IZ2WylZ+JrEIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787679268; c=relaxed/simple; bh=el5u/uzfnjQoekOn8fL6ipokPGPfXCdBAO+xTEzOups=; h=Message-ID:MIME-Version:From:To:Cc:Date:Subject:Content-Type; b=Ulz5V717WxXU3ByLp5gnb5UOqAMc+hpbAswnOUvP6yBqlAVDNkVoMACjIJwQGe6+V/ztAUlIm1yML1DzKM3t2SNqQV8J8Jjd5GRcXiSpl0kJ23oyfJN5v24C+9TB8UjFnsD7NoL+ZzhpZNHClpQGkr0vIFazumrR5vvm/dLw+tU= 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=nc0dU+7S; arc=none smtp.client-ip=209.85.214.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="nc0dU+7S" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2d032846c95so1688775ad.1 for ; Tue, 25 Aug 2026 10:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787679263; x=1788284063; darn=vger.kernel.org; h=content-transfer-encoding:content-type:subject:date:cc:to:from :mime-version:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=57hPk6B4v1KETwUArfZSnqqRqUE15uxO2Lfbtp7crWY=; b=nc0dU+7SebjA8MEH3HQ4mCIRT4CtLZtpnkRW5AmXQYzLeN1EPOr/lmM4y6kJ9FWB5o dWmjTQ/fKlOinYi7Dj4jUiP6KqMWc6zv+tBYhOB86QdPggmtcj5JRBLZT4FrAq6QsQ+3 iIohQaD8ciyLHtXPBf9+FccbHoh9FaHxoi0dknxjJ+qBWkJDvWpi+Z31xt7om4BgNvzY J84WEx54lWjx/2XkuWuCU1jJXJflCMz+Oa0oLymnh0hXwi1Wrek8UmCLd3eJ1xve76iE sbZxCG8ULscdbiHdHBuaRKTKxiSKRAEtubVX8wBErpedbC/7RyBW8bVR0epO46Zm+nWi X+cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787679263; x=1788284063; h=content-transfer-encoding:content-type:subject:date:cc:to:from :mime-version:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=57hPk6B4v1KETwUArfZSnqqRqUE15uxO2Lfbtp7crWY=; b=dHq1gJPg1KZQpHlG23cd6nX33mVxMgBigD/MkfwUFgs65BnwFecGij95EQ1N75caPz JIqD6OUNQ4b44gRWtt5UVuFSmLD38/5a26p+vsvdVBKjvfXhujPQkYGaxZbYi5OLFRFe sf5RwY7ChSoAqYtF1atCqyb9ZRGHHNr4O49+VaH7ojv9zNvnoHZ9ueNLmQNF4NiXFOY2 +KBajHpLav110qbbDWwYCF/DEoBJ5tvuO+Eg0BH5naOYPGtJgMctoznLA62tUkgTCKRT YrQt8x/y8caLDToVbhfRlX/xrlWuqEfVJUQ7w8qhOQh2gFyo/2pXaNSXiFlraEinm7Iw Di2Q== X-Gm-Message-State: AFuF++npatdBwOqQXzrtDDJkJBeaDBGgkVyHe78fHRg/26X4JvV61/tf E3thGFIxP+1sEzX75bteXlZHF4Fj6GPsexWagMlomk35fl91XevcWIL2 X-Gm-Gg: AR+sD12mDMKD1tEgJco5B4hIHIVOqXQU7Oafg6jZb8zcsXIZxNHuJGhI0dTHM9uuG+T nWW8kThlC95VRG5BBS3WX43CrX36x3nIqRsNlfVV8ZOWnhLpIM7UD10xYF0R+IWdTe+qvBv+Wgq Bu2+UBX8SKwoD+Cce3WP4B9DEMRXWvhmy8UU+r2EjhZGgNect20GaV0VeG/GePSr2HkcHmO2kgd dr1gazu6rFF5xFh2QR3SctpUn+DJ7PE0iuHi0RBIRG/oqRZengOLZwZ50rmSOw+Wbz0UGcorU9p 4J0wFH3eIUv/KxULxnJ6op6RD34PgLgkR96wUtSNHNj4LEv0yMC+5pNE95oe4H+HIzAPcvo4vA9 dp1s67udHFZ8RXX5iDh/T8MDkPGtC1U3dZmYoaQ69KVYf9ShWAuYallNIEVfJHO8JoHKXOgrUWz IkcI5s0hcj+AOUwGtzCIhiTmq9764rwxkcjlKERj/FKjeSZwCdGmMqg0DZae0G9wfBetXoyuaoD rCtD9r9Cwfc/Y7ezSn2qlNW06SeHFQyBIqSGmknBeCSlyn00GGFPsgUkA== X-Received: by 2002:a17:902:e949:b0:2d6:3c2f:6a5 with SMTP id d9443c01a7336-2d64b1d68bemr710709365ad.14.1787679262972; Tue, 25 Aug 2026 10:34:22 -0700 (PDT) Received: from manush ([2406:7400:94:a5e3:4d43:ded5:1c68:7d38]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3283d884d5esm465303eec.17.2026.08.25.10.34.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 10:34:22 -0700 (PDT) Message-ID: <6a8dd21e.b12cec6a.f9ff0.b637@mx.google.com> X-Mailer: git-send-email-equivalent-ps1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Manush Prajwal" To: jassisinghbrar@gmail.com, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com Cc: linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Markus.Elfring@web.de Date: 25 Aug 2026 23:04:22 +0530 Subject: [PATCH v4] mailbox: mtk-cmdq: fix runtime PM usage counter leak in cmdq_mbox_flush() Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" cmdq_mbox_flush() calls pm_runtime_get_sync() and returns its error code directly on failure. Per Documentation/power/runtime_pm.rst, pm_runtime_get_sync() does not drop the usage counter on error, so the caller is expected to release the reference itself. The early return here skipped that, leaking a runtime PM usage count on cmdq->mbox.dev on every failed resume. v2 fixed this by switching to pm_runtime_resume_and_get(), which performs the get-and-put internally on failure. Markus Elfring additionally pointed out that the "out:" and "wait:" labels duplicate the same pm_runtime_mark_last_busy() + pm_runtime_put_autosuspend() + return sequence. That duplication hides a second, separate leak: the "wait:" path's timeout branch (readl_poll_timeout_atomic() failing) returns -EFAULT directly, without ever calling pm_runtime_mark_last_busy() / pm_runtime_put_autosuspend(), so the pm_runtime reference taken at function entry is leaked on every polling timeout too. Fix both by merging the two exit sequences into one common "out_pm:" label reached by both "out:" and "wait:", using "ret" to carry the return value. "ret" is explicitly reset to 0 on both success paths before reaching "out_pm:", since pm_runtime_resume_and_get() can return a positive value (e.g. 1) on success, not just 0, and that stale value must not leak into the function's return value. Verified the merged exit path with a standalone model of the four possible outcomes (initial get failure, "out:" success, "wait:" success, "wait:" timeout): the runtime PM refcount returns to its starting value and the return code is correct on every path. Signed-off-by: Manush Prajwal --- v4: - Add parentheses to the function name in the summary phrase (cmdq_mbox_flush -> cmdq_mbox_flush()), per Markus Elfring's review. - Reformat this changelog so each version identifier stands on its own line and blocks are separated by blank lines, per Markus Elfring's review. - No functional change from v3. Still no Fixes tag: I don't have a git history for this file available in my current environment to identify the commit that introduced this exit path with confidence, and would rather leave the tag off than guess a SHA. Still happy to add it in a v5 if Markus or anyone else on Cc can point at the right commit. v3: - Fix the pm_runtime leak on the "wait:" timeout path found while addressing Markus Elfring's duplicate-code comment, by merging the "out:" and "wait:" exit sequences into a single "out_pm:" label. - Add Matthias Brugger and AngeloGioacchino Del Regno plus the linux-mediatek and linux-arm-kernel lists to Cc, per MAINTAINERS' "ARM/Mediatek SoC support" entry (matches any drivers/mailbox/mtk-*.c filename), per Markus Elfring's review. v2: - Use pm_runtime_resume_and_get() instead of pm_runtime_get_sync() plus a manual pm_runtime_put_noidle() on the error path, per Markus Elfring's review. drivers/mailbox/mtk-cmdq-mailbox.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-= mailbox.c index e523c84b4..d4e5f6a7b 100644 --- a/drivers/mailbox/mtk-cmdq-mailbox.c +++ b/drivers/mailbox/mtk-cmdq-mailbox.c @@ -565,7 +565,7 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, unsi= gned long timeout) int ret; - ret =3D pm_runtime_get_sync(cmdq->mbox.dev); + ret =3D pm_runtime_resume_and_get(cmdq->mbox.dev); if (ret < 0) return ret; @@ -590,22 +590,21 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, un= signed long timeout) cmdq_thread_disable(cmdq, thread); out: spin_unlock_irqrestore(&thread->chan->lock, flags); - pm_runtime_mark_last_busy(cmdq->mbox.dev); - pm_runtime_put_autosuspend(cmdq->mbox.dev); - - return 0; + ret =3D 0; + goto out_pm; wait: cmdq_thread_resume(thread); spin_unlock_irqrestore(&thread->chan->lock, flags); + ret =3D 0; if (readl_poll_timeout_atomic(thread->base + CMDQ_THR_ENABLE_TASK, enable, enable =3D=3D 0, 1, timeout))= { dev_err(cmdq->mbox.dev, "Fail to wait GCE thread 0x%x done\= n", (u32)(thread->base - cmdq->base)); - - return -EFAULT; + ret =3D -EFAULT; } + +out_pm: pm_runtime_mark_last_busy(cmdq->mbox.dev); pm_runtime_put_autosuspend(cmdq->mbox.dev); - return 0; + return ret; } -- 2.46.2.windows.1