public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: Fix NULL pointer dereference in npcm_i2c_reg_slave
@ 2024-01-09 14:51 Rand Deeb
  2024-01-10  8:43 ` Tali Perry
  0 siblings, 1 reply; 6+ messages in thread
From: Rand Deeb @ 2024-01-09 14:51 UTC (permalink / raw)
  To: Avi Fishman, Tomer Maimon, Tali Perry, Patrick Venture,
	Nancy Yuen, Benjamin Fair, openbmc, linux-i2c, linux-kernel
  Cc: deeb.rand, lvc-project, voskresenski.stanislav, Rand Deeb

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-02-04 10:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-09 14:51 [PATCH] i2c: Fix NULL pointer dereference in npcm_i2c_reg_slave Rand Deeb
2024-01-10  8:43 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox