From nobody Mon Sep 28 08:01:16 2026 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 6F60E381AF4 for ; Mon, 24 Aug 2026 18:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787595315; cv=none; b=t8ljNZEAFJfbn7mlYKUXxQjbSEoMpEE/3wFpDmVM8KjuWx3Z+Anh9k4iXm9DXR4dZ0pAhAceWB8TK3E0NZPpVzK0YnjZLTf3Y8ektgQBWhlK3gV6N/BoztNIgqfabU7ZrsCgi/AwdasgV/xVoHIn4SNrLwB/LFOwrgQiEGlJ5ls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787595315; c=relaxed/simple; bh=MSzzJXiNDBh+p/OTrToII6YqY6/qcFSkxFjxe/7EkXU=; h=Message-ID:MIME-Version:From:To:Cc:Date:Subject:Content-Type; b=ejeeypw964OaUwTDCJqy+LwBgIcYtRYDSPheqIEEKlri1l9Mwc1+JBb+ku8TUKXKeVPDRo/6Cn1pYGLAzyLza/AbuLg+5J+XSdHOFe4rUknlE1oOcYufdTGbK1DN4V6i7jyA7lFDsye+mAnUeea+LUxikfFOSVTCNP/cHfDQaY4= 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=SAMzJ11t; arc=none smtp.client-ip=209.85.216.43 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="SAMzJ11t" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-38125cebfdaso5822082a91.1 for ; Mon, 24 Aug 2026 11:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787595314; x=1788200114; 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=d/rpMCJfGm+xUSp3I6jJkmErPbYp+urUEQMWu8yYzcE=; b=SAMzJ11tQibYAx6UzBPOgUVKxl34Oys3h0/+nCgJdaD0yh1N/nSR51CTUmfEw7dP0m L5AEVczstZIZ3onQuVGMPNdBhep+78X4jl+TuRc40f071w58bF1fBDj2iNslfn74Q9e2 Ws+ivcF5ZW+QvyVkDxvckOQDhofhbz1BLh4763WS2UhOSqPmYlXA1Q2zTBlI5hjXZKdD U/CHDIW0XmDcApvL+AvozjByX0NAU/9NMoFe7H6n219+l1Xv2lYnqjUBdKShQw5N44QR WPt7MwSi+5FeDlz77oAu7vqYV/Xjg1oqMx6mbva84zLBASdcdHQzLtZm6Xq2RslwALDM ti/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787595314; x=1788200114; 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=d/rpMCJfGm+xUSp3I6jJkmErPbYp+urUEQMWu8yYzcE=; b=gMiQdudezRCjW0nd4rcfMX1fYuzJk2nyfi/4fOwkdOKd8A5N9+EkIgJgb84L4Alyv1 +UNPvb6oFkFl5MZjOkBYgmwLJlUect7g+df5bZkT+rZGXsluKmMsHnDSxMdktkz+xgrF m0gRweRPiv4liEajgutcGVB7nbFExCpTKVKN4emS93b4RcrotcZScCw4Kok9P6U/zI8O aihmZuhbY1aM8cj+dJfcSD2bdeKzp+uKJRAG7364Qf9IIpk3lhpm9U9n6/piMarGOeDy B6cihSH5z41UnnzCJ8Ccw7rHi0hfh6OW3QTomovaDOtWcprEo2M/lpGEAGjY1fX0QnxN Jgkg== X-Gm-Message-State: AFuF++nCb+ukmUioaBV6WY/NzSAmTBApiU40AbgBasqHxy/GsovKY0Ak 1LOUhr6CkfrcjDXzqT9NyR+LZf/ouO92opIScnThD0CLsO9GoA4hzfML X-Gm-Gg: AR+sD12XGNEvHvr4IhTZlSVyt10WiTalEZCb7Qv9cSYYC13h25bIbFkBfhP7b6THjpG C8+blsvP6dwiu91MJOBBOrW98KmTvudFDU0NQxmxdfiMRLPXd87XkkJUq3yJkbnYaccflyl04Wk ib8UwFPbPtF5ZNnl0GFJEpx8DNKrb9LuFTPKMDyPv/on8NY+q5b/gtFdMaUMa3UZG0kG5+Lkkrd 8/bFKrab0wj3y4UHCR+i/SFSbVjFrr93QmhpZ54zelFubI/PLr7+h2nQmN6oeZrDveaDImccaV7 cndTWQLUApnUP1F1oZwejRcS7HREKjzeTBvciyx2R5dtSvRre1AweYTBN3pRW6bcDZKttQB15bM Ygy6RgcK4qs+WBVUVOYUe7mbidBopwy4pYU3NLRvmKOJsYO7Ud93vYBRsJVqLfqOQxxCxifZU84 726R8G8+PNk197ENG+db3jLoVpQVuszKnD0tuxxgUeqHQYEj7wMfJRIbsw4THQam3sf+Ef5V7EQ yjuvWlj/2O9cAZfol6EnTBJfuvB7wnNSp0SY7w0ZC0fbgdI38z2k7XeAA== X-Received: by 2002:a17:90b:3a4b:b0:36d:b424:4f17 with SMTP id 98e67ed59e1d1-39646308515mr1602252a91.1.1787595313785; Mon, 24 Aug 2026 11:15:13 -0700 (PDT) Received: from manush ([2406:7400:94:a5e3:4d43:ded5:1c68:7d38]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-141860ef75esm26716169c88.7.2026.08.24.11.15.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 11:15:13 -0700 (PDT) Message-ID: <6a8c8a31.ee10049a.195cf8.c6da@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: 24 Aug 2026 23:45:12 +0530 Subject: [PATCH v3] 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. Signed-off-by: Manush Prajwal --- 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