From: <enachman@marvell.com>
To: <gregory.clement@bootlin.com>, <andi.shyti@kernel.org>,
<linux-i2c@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <enachman@marvell.com>
Subject: [PATCH] i2c: mv64xxx: prevent illegal pointer access
Date: Tue, 29 Jul 2025 11:45:23 +0300 [thread overview]
Message-ID: <20250729084523.3220002-1-enachman@marvell.com> (raw)
From: Elad Nachman <enachman@marvell.com>
Spurious interrupts left while i2c controller still
at RX or TX state would try to access the RX or TX
buffer pointer, which is NULL.
Add check to verify buffer pointer is not NULL before
reading or writing the buffer for additional TX or RX
operations.
Signed-off-by: Elad Nachman <enachman@marvell.com>
---
drivers/i2c/busses/i2c-mv64xxx.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 8fc26a511320..e6baa9c520b4 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -390,14 +390,18 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
break;
case MV64XXX_I2C_ACTION_SEND_DATA:
- writel(drv_data->msg->buf[drv_data->byte_posn++],
- drv_data->reg_base + drv_data->reg_offsets.data);
+ if (drv_data->msg && drv_data->msg->buf)
+ writel(drv_data->msg->buf[drv_data->byte_posn++],
+ drv_data->reg_base + drv_data->reg_offsets.data);
writel(drv_data->cntl_bits,
drv_data->reg_base + drv_data->reg_offsets.control);
break;
case MV64XXX_I2C_ACTION_RCV_DATA:
- drv_data->msg->buf[drv_data->byte_posn++] =
+ if (drv_data->msg && drv_data->msg->buf)
+ drv_data->msg->buf[drv_data->byte_posn++] =
+ readl(drv_data->reg_base + drv_data->reg_offsets.data);
+ else
readl(drv_data->reg_base + drv_data->reg_offsets.data);
writel(drv_data->cntl_bits,
drv_data->reg_base + drv_data->reg_offsets.control);
--
2.25.1
next reply other threads:[~2025-07-29 8:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 8:45 enachman [this message]
2025-07-29 18:56 ` Markus Elfring
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=20250729084523.3220002-1-enachman@marvell.com \
--to=enachman@marvell.com \
--cc=andi.shyti@kernel.org \
--cc=gregory.clement@bootlin.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.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®