From nobody Wed Apr 8 03:07:13 2026 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (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 19160248F73 for ; Tue, 10 Mar 2026 23:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773186383; cv=none; b=DmY8iDb0DtWhYTzp47td4OYUJuN5JolcufdFxB7/uNsNZLRdvJ7ztqsDLRown+Uo2OQm27Dq80zEpJ0q3YJm2In8pPr8BPQOejEjnTNK32WOlLCgadwmGsbuQ3EkIMBnAfjLdUmKvt7oUPKf/O0txRhfJy7gld8MXxdkaWvHgGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773186383; c=relaxed/simple; bh=U09VAlYZtepSHJnDwaOYwtZBxca3erTNfRi+ufNc93s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=graPHCRNi/6XxyZyofJLv0Qzx7lD1nJIhFDjOkEp9oWWB6J6KpeZu8xZOmW8mXYFi6vrV3MIm4hCca2uA1qAI1FFOsPfxVPbSoQQeUCkDRMYRVYkcP0e0GDJo9lL79GSJxJqa7f1t70mH6RsZdXRDqI8hbuK4sOpPVuxLz/57I4= 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=WPHRVDlq; arc=none smtp.client-ip=209.85.160.174 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="WPHRVDlq" Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-509101189edso28286151cf.3 for ; Tue, 10 Mar 2026 16:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773186381; x=1773791181; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=s0juBqeCko82pCJebHwGlvA35GBc5RhQHhw+nPjinhU=; b=WPHRVDlq53vO/hAs9h5vSVqfnbEBsvy9zNm0otBYPlE2NajvnHJb92BiYv28/XWiTz sUwz7/e30kXs84HGuxgeRHgs576CTfkIa2fMRmAIfzrPCF1uZnWvB/3RgNboapuP4NLc DGKbmE77Qfqge4Pjg8eSyFvf640IZfKbSGZv9PszdU387i1eo7XoUqwsQ70dxq8N90ET XtR6NVbsOAlAomN1gvIEyuQzv9HfNFtxg55j06kmknkVDLtU+OwtfrXotKMtnzmjG65b 3Wf4FQhBDjX8xQUiq8lKZWj8oOZbOm7+dcHHEbYkfKdnm8VqV5r0Tq0p2lEXZcuYv/n7 IRBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773186381; x=1773791181; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=s0juBqeCko82pCJebHwGlvA35GBc5RhQHhw+nPjinhU=; b=HWEAapW9o57S8ltkk9B2dTpSQBBIGsidOwuetFLblderyCctUyb0l45TuaUcQfsVYP qlaVXdmwbAwGYPzj6Y0q//Um82zAM5qII9py5ko1kJz1cKgstT3YtEOtt40ma7UjVqRj NZROGPIhW6m4LAAkD7l153TVmZWjgn6vqhMQ3MbvHWWPmjVemkgdu+i/OSE8YJP2Kh7/ CJ1wUZBlt/7BBdNkOzWYN1UrWD4uQ6z2eDy8TVEOrBUZswExptV/8hRi8dDOp7CvEoeR sXUQ8d7FpO6QVz+ceFxJfiiqrpi8JVAiG2sgXAmzxvt0n3LT7c0iZh80IFZ+FLewcJ9I /9ZQ== X-Gm-Message-State: AOJu0Yx71krHrTOFDyXufplFbE3YlpNgLIQME+n2jd1LuxhQzaJzTmDM PMgDsFXVrK6NMHAlPj3FAgWSw7/nKdCw02WdFqcpkSFXv40DhVWfgxmmr4UhOrzf X-Gm-Gg: ATEYQzwo1/DnoA0uqM3QIQrATnuHCet0PAt5IUFmFZ5x/zcT/r4Dfy6ul+fV1MnqVTK zoh3pS035ah+7+EIlXXwvqMjw6i7MB366hfYLf7OV2WlNmCD4hXVeOIqcjn5a7/9u1RZ3rlhf9k AIvCtaej3/E/oLAyacT2qk4+Rkpq/Pc9diyspHFx8ygA6V5wpFBQE3Ky36GL2LHfI6u3OFLURM+ Xn7QQC6H24tLmxiZ2KuRe/Prfvgj0F0rUOgnlS8Q3OIP1gSoR5QDDbTsIz0RtCETZNrRh2++ts3 FFT9j4ZDUjTeZXiXkJvJ2Nr6OBwWSI5aaOylON9n29qrjYUaycKVZo6dCQLCQVOWkvZIMVcydbM yJPLQtOHPz3Q63SQBsKmnUFK98Ebeu9e6bw+IwODB20/JayjAMD5E5nEeKGyPUELL8AMCfUTUWz ASVNDVuU+7LLYhPmTMM3GxvmYPSbo/tXZ+b7QfviVSPIC80vD5HfjWXNVEYRuYqeU7Uzjr2ack0 6FUlDoli+yjNA== X-Received: by 2002:a05:622a:1451:b0:509:29d7:9078 with SMTP id d75a77b69052e-5093a188020mr7274911cf.44.1773186380742; Tue, 10 Mar 2026 16:46:20 -0700 (PDT) Received: from Desktop-PC.. (wnpgmb0311w-ds01-161-217-39.dynamic.bellmts.net. [142.161.217.39]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-5093a146218sm2496941cf.30.2026.03.10.16.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2026 16:46:20 -0700 (PDT) From: jassisinghbrar@gmail.com To: linux-kernel@vger.kernel.org Cc: arnd@arndb.de, dianders@chromium.org, Jassi Brar Subject: [PATCH] RFC: mailbox: Fix NULL message support in mbox_send_message() Date: Tue, 10 Mar 2026 18:46:16 -0500 Message-ID: <20260310234616.334498-1-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.43.0 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" From: Jassi Brar The active_req field serves double duty as both the "is a TX in flight" flag (NULL means idle) and the storage for the in-flight message pointer. When a client sends NULL via mbox_send_message(), active_req is set to NULL, which the framework misinterprets as "no active request." This breaks the TX state machine by: - tx_tick() short-circuits on (!mssg), skipping the tx_done callback and the tx_complete completion - txdone_hrtimer() skips the channel entirely since active_req is NULL, so poll-based TX-done detection never fires. Fix this by introducing a MBOX_NO_MSG sentinel value that means "no active request," freeing NULL to be valid message data. The sentinel is internal to the mailbox core and is never exposed to controller drivers or clients. The only tradeoff is that 'MBOX_NO_MSG' can not be used as a message by clients. Signed-off-by: Jassi Brar --- drivers/mailbox/mailbox.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 617ba505691d..d06f6d49deaf 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -20,6 +20,9 @@ =20 #include "mailbox.h" =20 +/* Sentinel value distinguishing "no active request" from "NULL message da= ta" */ +#define MBOX_NO_MSG ((void *)-1) + static LIST_HEAD(mbox_cons); static DEFINE_MUTEX(con_mutex); =20 @@ -52,7 +55,7 @@ static void msg_submit(struct mbox_chan *chan) int err =3D -EBUSY; =20 scoped_guard(spinlock_irqsave, &chan->lock) { - if (!chan->msg_count || chan->active_req) + if (!chan->msg_count || chan->active_req !=3D MBOX_NO_MSG) break; =20 count =3D chan->msg_count; @@ -87,13 +90,13 @@ static void tx_tick(struct mbox_chan *chan, int r) =20 scoped_guard(spinlock_irqsave, &chan->lock) { mssg =3D chan->active_req; - chan->active_req =3D NULL; + chan->active_req =3D MBOX_NO_MSG; } =20 /* Submit next message */ msg_submit(chan); =20 - if (!mssg) + if (mssg =3D=3D MBOX_NO_MSG) return; =20 /* Notify the client */ @@ -114,7 +117,7 @@ static enum hrtimer_restart txdone_hrtimer(struct hrtim= er *hrtimer) for (i =3D 0; i < mbox->num_chans; i++) { struct mbox_chan *chan =3D &mbox->chans[i]; =20 - if (chan->active_req && chan->cl) { + if (chan->active_req !=3D MBOX_NO_MSG && chan->cl) { txdone =3D chan->mbox->ops->last_tx_done(chan); if (txdone) tx_tick(chan, 0); @@ -319,7 +322,7 @@ static int __mbox_bind_client(struct mbox_chan *chan, s= truct mbox_client *cl) scoped_guard(spinlock_irqsave, &chan->lock) { chan->msg_free =3D 0; chan->msg_count =3D 0; - chan->active_req =3D NULL; + chan->active_req =3D MBOX_NO_MSG; chan->cl =3D cl; init_completion(&chan->tx_complete); =20 @@ -477,7 +480,7 @@ void mbox_free_channel(struct mbox_chan *chan) /* The queued TX requests are simply aborted, no callbacks are made */ scoped_guard(spinlock_irqsave, &chan->lock) { chan->cl =3D NULL; - chan->active_req =3D NULL; + chan->active_req =3D MBOX_NO_MSG; if (chan->txdone_method =3D=3D TXDONE_BY_ACK) chan->txdone_method =3D TXDONE_BY_POLL; } --=20 2.43.0