diff mbox

hwmon: (w83791d) add error handling for i2c_new_dummy

Message ID 1528774504-38755-1-git-send-email-jiazhouyang09@gmail.com (mailing list archive)
State Rejected
Headers show

Commit Message

Zhouyang Jia June 12, 2018, 3:35 a.m. UTC
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/w83791d.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Guenter Roeck June 12, 2018, 1:21 p.m. UTC | #1
On 06/11/2018 08:35 PM, Zhouyang Jia wrote:
> 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>

As before, NACK, sorry.

Guenter

> ---
>   drivers/hwmon/w83791d.c | 15 ++++++++++++++-
>   1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
> index 28fa3bd..a183432 100644
> --- a/drivers/hwmon/w83791d.c
> +++ b/drivers/hwmon/w83791d.c
> @@ -1295,8 +1295,15 @@ static int w83791d_detect_subclients(struct i2c_client *client)
>   	}
>   
>   	val = w83791d_read(client, W83791D_REG_I2C_SUBADDR);
> -	if (!(val & 0x08))
> +	if (!(val & 0x08)) {
>   		data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7));
> +		if (data->lm75[0] == NULL) {
> +			dev_err(&client->dev,
> +				"Failed to allocate I2C device\n");
> +			err = -ENODEV;
> +			goto error_sc_1;
> +		}
> +	}
>   	if (!(val & 0x80)) {
>   		if ((data->lm75[0] != NULL) &&
>   				((val & 0x7) == ((val >> 4) & 0x7))) {
> @@ -1309,6 +1316,12 @@ static int w83791d_detect_subclients(struct i2c_client *client)
>   		}
>   		data->lm75[1] = i2c_new_dummy(adapter,
>   					      0x48 + ((val >> 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;
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index 28fa3bd..a183432 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -1295,8 +1295,15 @@  static int w83791d_detect_subclients(struct i2c_client *client)
 	}
 
 	val = w83791d_read(client, W83791D_REG_I2C_SUBADDR);
-	if (!(val & 0x08))
+	if (!(val & 0x08)) {
 		data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7));
+		if (data->lm75[0] == NULL) {
+			dev_err(&client->dev,
+				"Failed to allocate I2C device\n");
+			err = -ENODEV;
+			goto error_sc_1;
+		}
+	}
 	if (!(val & 0x80)) {
 		if ((data->lm75[0] != NULL) &&
 				((val & 0x7) == ((val >> 4) & 0x7))) {
@@ -1309,6 +1316,12 @@  static int w83791d_detect_subclients(struct i2c_client *client)
 		}
 		data->lm75[1] = i2c_new_dummy(adapter,
 					      0x48 + ((val >> 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;