From: Rand Deeb <rand.sec96@gmail.com>
To: Avi Fishman <avifishman70@gmail.com>,
Tomer Maimon <tmaimon77@gmail.com>,
Tali Perry <tali.perry1@gmail.com>,
Patrick Venture <venture@google.com>,
Nancy Yuen <yuenn@google.com>,
Benjamin Fair <benjaminfair@google.com>,
openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: deeb.rand@confident.ru, lvc-project@linuxtesting.org,
voskresenski.stanislav@confident.ru,
Rand Deeb <rand.sec96@gmail.com>
Subject: [PATCH] i2c: Fix NULL pointer dereference in npcm_i2c_reg_slave
Date: Tue, 9 Jan 2024 17:51:21 +0300 [thread overview]
Message-ID: <20240109145121.8850-1-rand.sec96@gmail.com> (raw)
In the npcm_i2c_reg_slave function, a potential NULL pointer dereference
issue occurs when 'client' is NULL. This patch adds a proper NULL check for
'client' at the beginning of the function to prevent undefined behavior.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Rand Deeb <rand.sec96@gmail.com>
---
drivers/i2c/busses/i2c-npcm7xx.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
index c1b679737240..cfabfb50211d 100644
--- a/drivers/i2c/busses/i2c-npcm7xx.c
+++ b/drivers/i2c/busses/i2c-npcm7xx.c
@@ -1243,13 +1243,14 @@ static irqreturn_t npcm_i2c_int_slave_handler(struct npcm_i2c *bus)
static int npcm_i2c_reg_slave(struct i2c_client *client)
{
unsigned long lock_flags;
- struct npcm_i2c *bus = i2c_get_adapdata(client->adapter);
-
- bus->slave = client;
+ struct npcm_i2c *bus;
- if (!bus->slave)
+ if (!client)
return -EINVAL;
+ bus = i2c_get_adapdata(client->adapter);
+ bus->slave = client;
+
if (client->flags & I2C_CLIENT_TEN)
return -EAFNOSUPPORT;
--
2.34.1
next reply other threads:[~2024-01-09 14:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-09 14:51 Rand Deeb [this message]
2024-01-10 8:43 ` [PATCH] i2c: Fix NULL pointer dereference in npcm_i2c_reg_slave Tali Perry
2024-01-10 9:23 ` Re: [lvc-project] " Fedor Pchelkin
2024-02-03 20:44 ` Wolfram Sang
2024-02-04 8:54 ` Fedor Pchelkin
2024-02-04 10:12 ` Rand Deeb
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=20240109145121.8850-1-rand.sec96@gmail.com \
--to=rand.sec96@gmail.com \
--cc=avifishman70@gmail.com \
--cc=benjaminfair@google.com \
--cc=deeb.rand@confident.ru \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=openbmc@lists.ozlabs.org \
--cc=tali.perry1@gmail.com \
--cc=tmaimon77@gmail.com \
--cc=venture@google.com \
--cc=voskresenski.stanislav@confident.ru \
--cc=yuenn@google.com \
/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