All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: (w83793) add error handling for i2c_new_dummy
@ 2018-06-12  3:32 ` Zhouyang Jia
  0 siblings, 0 replies; 3+ messages in thread
From: Zhouyang Jia @ 2018-06-12  3:32 UTC (permalink / raw)
  Cc: Zhouyang Jia, Rudolf Marek, Jean Delvare, Guenter Roeck,
	linux-hwmon, linux-kernel

When i2c_new_dummy fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling i2c_new_dummy.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
 drivers/hwmon/w83793.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 0af0f62..4aa3a0e 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -1603,8 +1603,15 @@ w83793_detect_subclients(struct i2c_client *client)
 	}
 
 	tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR);
-	if (!(tmp & 0x08))
+	if (!(tmp & 0x08)) {
 		data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7));
+		if (data->lm75[0] == NULL) {
+			dev_err(&client->dev,
+				"Failed to allocate I2C device\n");
+			err = -ENODEV;
+			goto ERROR_SC_1;
+		}
+	}
 	if (!(tmp & 0x80)) {
 		if ((data->lm75[0] != NULL)
 		    && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) {
@@ -1616,6 +1623,12 @@ w83793_detect_subclients(struct i2c_client *client)
 		}
 		data->lm75[1] = i2c_new_dummy(adapter,
 					      0x48 + ((tmp >> 4) & 0x7));
+		if (data->lm75[1] == NULL) {
+			dev_err(&client->dev,
+				"Failed to allocate I2C device\n");
+			err = -ENODEV;
+			goto ERROR_SC_1;
+		}
 	}
 
 	return 0;
-- 
2.7.4

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

* [PATCH] hwmon: (w83793) add error handling for i2c_new_dummy
@ 2018-06-12  3:32 ` Zhouyang Jia
  0 siblings, 0 replies; 3+ messages in thread
From: Zhouyang Jia @ 2018-06-12  3:32 UTC (permalink / raw)
  Cc: Zhouyang Jia, Rudolf Marek, Jean Delvare, Guenter Roeck,
	linux-hwmon, linux-kernel

When i2c_new_dummy fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling i2c_new_dummy.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
 drivers/hwmon/w83793.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 0af0f62..4aa3a0e 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -1603,8 +1603,15 @@ w83793_detect_subclients(struct i2c_client *client)
 	}
 
 	tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR);
-	if (!(tmp & 0x08))
+	if (!(tmp & 0x08)) {
 		data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7));
+		if (data->lm75[0] == NULL) {
+			dev_err(&client->dev,
+				"Failed to allocate I2C device\n");
+			err = -ENODEV;
+			goto ERROR_SC_1;
+		}
+	}
 	if (!(tmp & 0x80)) {
 		if ((data->lm75[0] != NULL)
 		    && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) {
@@ -1616,6 +1623,12 @@ w83793_detect_subclients(struct i2c_client *client)
 		}
 		data->lm75[1] = i2c_new_dummy(adapter,
 					      0x48 + ((tmp >> 4) & 0x7));
+		if (data->lm75[1] == NULL) {
+			dev_err(&client->dev,
+				"Failed to allocate I2C device\n");
+			err = -ENODEV;
+			goto ERROR_SC_1;
+		}
 	}
 
 	return 0;
-- 
2.7.4


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

* Re: [PATCH] hwmon: (w83793) add error handling for i2c_new_dummy
  2018-06-12  3:32 ` Zhouyang Jia
  (?)
@ 2018-06-12 13:21 ` Guenter Roeck
  -1 siblings, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2018-06-12 13:21 UTC (permalink / raw)
  To: Zhouyang Jia; +Cc: Rudolf Marek, Jean Delvare, linux-hwmon, linux-kernel

On 06/11/2018 08:32 PM, Zhouyang Jia wrote:
> When i2c_new_dummy fails, the lack of error-handling code may
> cause unexpected results.
> 

There are no unexpected results.

> This patch adds error-handling code after calling i2c_new_dummy.
> 

Making a non-fatal error fatal doesn't serve a useful purpose.

NACK

Guenter

> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> ---
>   drivers/hwmon/w83793.c | 15 ++++++++++++++-
>   1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
> index 0af0f62..4aa3a0e 100644
> --- a/drivers/hwmon/w83793.c
> +++ b/drivers/hwmon/w83793.c
> @@ -1603,8 +1603,15 @@ w83793_detect_subclients(struct i2c_client *client)
>   	}
>   
>   	tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR);
> -	if (!(tmp & 0x08))
> +	if (!(tmp & 0x08)) {
>   		data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7));
> +		if (data->lm75[0] == NULL) {
> +			dev_err(&client->dev,
> +				"Failed to allocate I2C device\n");
> +			err = -ENODEV;
> +			goto ERROR_SC_1;
> +		}
> +	}
>   	if (!(tmp & 0x80)) {
>   		if ((data->lm75[0] != NULL)
>   		    && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) {
> @@ -1616,6 +1623,12 @@ w83793_detect_subclients(struct i2c_client *client)
>   		}
>   		data->lm75[1] = i2c_new_dummy(adapter,
>   					      0x48 + ((tmp >> 4) & 0x7));
> +		if (data->lm75[1] == NULL) {
> +			dev_err(&client->dev,
> +				"Failed to allocate I2C device\n");
> +			err = -ENODEV;
> +			goto ERROR_SC_1;
> +		}
>   	}
>   
>   	return 0;
> 


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

end of thread, other threads:[~2018-06-12 13:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12  3:32 [PATCH] hwmon: (w83793) add error handling for i2c_new_dummy Zhouyang Jia
2018-06-12  3:32 ` Zhouyang Jia
2018-06-12 13:21 ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.