Skip to contentSkip to conversation

misc: eeprom: assignment outside the if statement

PATCH In review Parth Y Shah 2 participants 2 messages Aug 3, 2018 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: eeprom: assignment outside the if statement

Assignment of any variable should be kept outside the if statement

---
 drivers/misc/eeprom/max6875.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/misc/eeprom/max6875.c +2 -1
index 0e32709..fc0cf9a 100644
@@ -148,7 +148,8 @@ static int max6875_probe(struct i2c_client *client,
 	if (client->addr & 1)
 		return -ENODEV;
 
-	if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL)))
+	data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL);
+	if (!data)
 		return -ENOMEM;
 
 	/* A fake client is created on the odd address */
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Parth Y Shah

Assignment of any variable should be kept outside the if statement

Actually there are exceptions to that rule, but this isn't one of them.

Quoted 10 lines
---
 drivers/misc/eeprom/max6875.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/misc/eeprom/max6875.c +0 -0
index 0e32709..fc0cf9a 100644

drivers/misc/eeprom/max6875.c static int max6875_probe(struct i2c_client *client, · line 155

Quoted 9 lines
drivers/misc/eeprom/max6875.c +2 -1
@@ -148,7 +148,8 @@ static int max6875_probe(struct i2c_client *client,
 	if (client->addr & 1)
 		return -ENODEV;
 
-	if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL)))
+	data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL);
+	if (!data)
 		return -ENOMEM;
 
 	/* A fake client is created on the odd address */

Thanks,

Signature · 2 lines
Jean Delvare
SUSE L3 Support