linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] misc: eeprom: assignment outside the if statement
@ 2018-08-03  9:20 Parth Y Shah
  2018-08-03 12:36 ` Jean Delvare
  0 siblings, 1 reply; 2+ messages in thread
From: Parth Y Shah @ 2018-08-03  9:20 UTC (permalink / raw)
  To: arnd, gregkh, jdelvare, bhumirks; +Cc: linux-kernel, Parth Y Shah

Assignment of any variable should be kept outside the if statement

Signed-off-by: Parth Y Shah <sparth1292@gmail.com>
---
 drivers/misc/eeprom/max6875.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/eeprom/max6875.c b/drivers/misc/eeprom/max6875.c
index 0e32709..fc0cf9a 100644
--- a/drivers/misc/eeprom/max6875.c
+++ b/drivers/misc/eeprom/max6875.c
@@ -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 */
-- 
2.7.4


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

* Re: [PATCH] misc: eeprom: assignment outside the if statement
  2018-08-03  9:20 [PATCH] misc: eeprom: assignment outside the if statement Parth Y Shah
@ 2018-08-03 12:36 ` Jean Delvare
  0 siblings, 0 replies; 2+ messages in thread
From: Jean Delvare @ 2018-08-03 12:36 UTC (permalink / raw)
  To: Parth Y Shah; +Cc: arnd, gregkh, bhumirks, linux-kernel

On Fri,  3 Aug 2018 14:50:43 +0530, Parth Y Shah wrote:
> 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.

> Signed-off-by: Parth Y Shah <sparth1292@gmail.com>
> ---
>  drivers/misc/eeprom/max6875.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/eeprom/max6875.c b/drivers/misc/eeprom/max6875.c
> index 0e32709..fc0cf9a 100644
> --- a/drivers/misc/eeprom/max6875.c
> +++ b/drivers/misc/eeprom/max6875.c
> @@ -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 */

Reviewed-by: Jean Delvare <jdelvare@suse.de>

Thanks,
-- 
Jean Delvare
SUSE L3 Support

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

end of thread, other threads:[~2018-08-03 12:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-03  9:20 [PATCH] misc: eeprom: assignment outside the if statement Parth Y Shah
2018-08-03 12:36 ` Jean Delvare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).