Skip to contentSkip to conversation

i2c: Remove redundant comparison in npcm_i2c_reg_slave

PATCH Applied Rand Deeb 3 participants 3 messages Feb 6, 2024 – Feb 14, 2024

Subsystems (2)
lore
Share & tools
lore

Rand Deeb

author
#0 lore raw

PATCH 1/1 i2c: Remove redundant comparison in npcm_i2c_reg_slave

In the npcm_i2c_reg_slave() function, there was a redundant comparison that checked if 'bus->slave' was null immediately after assigning it the 'client' value. There were concerns about a potential null dereference because of client->adapter, but according to Wolfram Sang, "we trusted ourselves here" Therefore, this comparison is unnecessary.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 drivers/i2c/busses/i2c-npcm7xx.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +0 -3
index c1b679737240..bdf35b86e559 100644
@@ -1247,9 +1247,6 @@ static int npcm_i2c_reg_slave(struct i2c_client *client)
 
 	bus->slave = client;
 
-	if (!bus->slave)
-		return -EINVAL;
-
 	if (client->flags & I2C_CLIENT_TEN)
 		return -EAFNOSUPPORT;
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Rand Deeb

In the npcm_i2c_reg_slave() function, there was a redundant comparison that checked if 'bus->slave' was null immediately after assigning it the 'client' value. There were concerns about a potential null dereference because of client->adapter, but according to Wolfram Sang, "we trusted ourselves here" Therefore, this comparison is unnecessary.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

maintainer Applied
#2 lore raw
In reply to Rand Deeb

Hi

Quoted 8 lines · Rand Deeb

In the npcm_i2c_reg_slave() function, there was a redundant comparison that checked if 'bus->slave' was null immediately after assigning it the 'client' value. There were concerns about a potential null dereference because of client->adapter, but according to Wolfram Sang, "we trusted ourselves here" Therefore, this comparison is unnecessary.

[...]

Applied to i2c/i2c-host on

git://git.kernel.org/pub/scm/linux/kernel/git/andi.shyti/linux.git

Thank you,
Andi

Patches applied
===============
[1/1] i2c: Remove redundant comparison in npcm_i2c_reg_slave

      commit: 48acf8292280f257fb0047478153a81471ee7f4d