From: Pankaj Gupta <pankaj.gupta@nxp.com>
To: linux-kernel@vger.kernel.org
Cc: imx@lists.linux.dev, frank.li@nxp.com,
Pankaj Gupta <pankaj.gupta@nxp.com>,
sashiko-bot <sashiko-bot@kernel.org>
Subject: [PATCH -next] firmware: imx: se_ctrl: serialize command receiver registration
Date: Thu, 28 May 2026 14:46:34 +0530 [thread overview]
Message-ID: <20260528091634.3331090-1-pankaj.gupta@nxp.com> (raw)
SE_IOCTL_ENABLE_CMD_RCV updates the global command receiver state in
priv->cmd_receiver_clbk_hdl, but it is currently protected only by the
per-file dev_ctx->fops_lock. Concurrent ioctl calls from different file
descriptors can therefore race and register multiple receivers against
the same priv instance.
Protect command receiver registration with priv->priv_dev_ctx->fops_lock,
which serializes access to the shared callback state.
Fixes: 3ae9dcce8400 ("firmware: drivers: imx: adds miscdev")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260514090457.2186933-1-pankaj.gupta@nxp.com?part=1
Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
---
drivers/firmware/imx/se_ctrl.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c
index 995e2b5c2b05..2efeed180f2a 100644
--- a/drivers/firmware/imx/se_ctrl.c
+++ b/drivers/firmware/imx/se_ctrl.c
@@ -919,21 +919,22 @@ static long se_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
scoped_cond_guard(mutex_intr, return -EBUSY, &dev_ctx->fops_lock) {
switch (cmd) {
case SE_IOCTL_ENABLE_CMD_RCV:
- if (!priv->cmd_receiver_clbk_hdl.dev_ctx) {
+ scoped_guard(mutex, &priv->priv_dev_ctx->fops_lock) {
+ if (priv->cmd_receiver_clbk_hdl.dev_ctx) {
+ err = -EBUSY;
+ goto out_enable_cmd_rcv;
+ }
+ priv->cmd_receiver_clbk_hdl.rx_msg =
+ kzalloc(MAX_NVM_MSG_LEN,
+ GFP_KERNEL);
if (!priv->cmd_receiver_clbk_hdl.rx_msg) {
- priv->cmd_receiver_clbk_hdl.rx_msg =
- kzalloc(MAX_NVM_MSG_LEN,
- GFP_KERNEL);
- if (!priv->cmd_receiver_clbk_hdl.rx_msg) {
- err = -ENOMEM;
- break;
- }
+ err = -ENOMEM;
+ goto out_enable_cmd_rcv;
}
priv->cmd_receiver_clbk_hdl.rx_msg_sz = MAX_NVM_MSG_LEN;
priv->cmd_receiver_clbk_hdl.dev_ctx = dev_ctx;
err = 0;
- } else {
- err = -EBUSY;
+out_enable_cmd_rcv:
}
break;
case SE_IOCTL_GET_MU_INFO:
--
2.43.0
next reply other threads:[~2026-05-28 9:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 9:16 Pankaj Gupta [this message]
2026-05-29 2:10 ` kernel test robot
2026-05-29 4:40 ` kernel test robot
2026-05-29 4:40 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260528091634.3331090-1-pankaj.gupta@nxp.com \
--to=pankaj.gupta@nxp.com \
--cc=frank.li@nxp.com \
--cc=imx@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®