From mboxrd@z Thu Jan 1 00:00:00 1970 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-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable cmdq_mbox_flush() calls pm_runtime_get_sync() and returns its err= or=0D=0Acode directly on failure. Per Documentation/power/runtime= _pm.rst,=0D=0Apm_runtime_get_sync() does not drop the usage count= er on error, so the=0D=0Acaller is expected to release the refere= nce itself. The early return=0D=0Ahere skipped that, leaking a ru= ntime PM usage count on cmdq->mbox.dev=0D=0Aon every failed resum= e. v2 fixed this by switching to=0D=0Apm_runtime_resume_and_get()= , which performs the get-and-put=0D=0Ainternally on failure.=0D=0A= =0D=0AMarkus Elfring additionally pointed out that the "out:" and= "wait:"=0D=0Alabels duplicate the same pm_runtime_mark_last_busy= () +=0D=0Apm_runtime_put_autosuspend() + return sequence. That du= plication=0D=0Ahides a second, separate leak: the "wait:" path's = timeout branch=0D=0A(readl_poll_timeout_atomic() failing) returns= -EFAULT directly,=0D=0Awithout ever calling pm_runtime_mark_last= _busy() /=0D=0Apm_runtime_put_autosuspend(), so the pm_runtime re= ference taken at=0D=0Afunction entry is leaked on every polling t= imeout too.=0D=0A=0D=0AFix both by merging the two exit sequences= into one common "out_pm:"=0D=0Alabel reached by both "out:" and = "wait:", using "ret" to carry the=0D=0Areturn value. "ret" is exp= licitly reset to 0 on both success paths=0D=0Abefore reaching "ou= t_pm:", since pm_runtime_resume_and_get() can=0D=0Areturn a posit= ive value (e.g. 1) on success, not just 0, and that=0D=0Astale va= lue must not leak into the function's return value.=0D=0A=0D=0ASi= gned-off-by: Manush Prajwal =0D=0A---= =0D=0Av3: Fix the pm_runtime leak on the "wait:" timeout path fou= nd while=0D=0A addressing Markus Elfring's duplicate-code comm= ent, by merging=0D=0A the "out:" and "wait:" exit sequences in= to a single "out_pm:"=0D=0A label. Add Matthias Brugger and An= geloGioacchino Del Regno plus=0D=0A the linux-mediatek and lin= ux-arm-kernel lists to Cc, per=0D=0A MAINTAINERS' "ARM/Mediate= k SoC support" entry (matches any=0D=0A drivers/mailbox/mtk-*.= c filename), per Markus Elfring's review.=0D=0Av2: Use pm_runtime= _resume_and_get() instead of pm_runtime_get_sync()=0D=0A plus = a manual pm_runtime_put_noidle() on the error path, per=0D=0A = Markus Elfring's review.=0D=0A=0D=0A drivers/mailbox/mtk-cmdq-mai= lbox.c | 15 +++++++--------=0D=0A 1 file changed, 7 insertions(+)= , 8 deletions(-)=0D=0A=0D=0Adiff --git a/drivers/mailbox/mtk-cmdq= -mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c=0D=0Aindex e523c8= 4b4..d4e5f6a7b 100644=0D=0A--- a/drivers/mailbox/mtk-cmdq-mailbox= .c=0D=0A+++ b/drivers/mailbox/mtk-cmdq-mailbox.c=0D=0A@@ -565,7 += 565,7 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, unsig= ned long timeout)=0D=0A int ret;=0D=0A=0D=0A- ret =3D pm_runtime= _get_sync(cmdq->mbox.dev);=0D=0A+ ret =3D pm_runtime_resume_and_g= et(cmdq->mbox.dev);=0D=0A if (ret < 0)=0D=0A return ret;=0D=0A= =0D=0A@@ -590,22 +590,21 @@ static int cmdq_mbox_flush(struct mbo= x_chan *chan, unsigned long timeout)=0D=0A cmdq_thread_disable(c= mdq, thread);=0D=0A=0D=0A out:=0D=0A spin_unlock_irqrestore(&thr= ead->chan->lock, flags);=0D=0A- pm_runtime_mark_last_busy(cmdq->m= box.dev);=0D=0A- pm_runtime_put_autosuspend(cmdq->mbox.dev);=0D=0A= -=0D=0A- return 0;=0D=0A+ ret =3D 0;=0D=0A+ goto out_pm;=0D=0A=0D=0A= wait:=0D=0A cmdq_thread_resume(thread);=0D=0A spin_unlock_irqr= estore(&thread->chan->lock, flags);=0D=0A+ ret =3D 0;=0D=0A if (= readl_poll_timeout_atomic(thread->base + CMDQ_THR_ENABLE_TASK,=0D=0A= enable, enable =3D=3D 0, 1, timeout)) {=0D=0A dev_er= r(cmdq->mbox.dev, "Fail to wait GCE thread 0x%x done\n",=0D=0A = (u32)(thread->base - cmdq->base));=0D=0A-=0D=0A- return -EFAULT= ;=0D=0A+ ret =3D -EFAULT;=0D=0A }=0D=0A+=0D=0A+out_pm:=0D=0A p= m_runtime_mark_last_busy(cmdq->mbox.dev);=0D=0A pm_runtime_put_a= utosuspend(cmdq->mbox.dev);=0D=0A- return 0;=0D=0A+ return ret;=0D=0A= }=0D=0A--=0D=0A2.46.2.windows.1