Skip to contentSkip to conversation

hwmon: (w83792d) add error handling for i2c_new_dummy

PATCH NAK Zhouyang Jia 2 participants 2 messages Jun 12, 2018 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (w83792d) add error handling for i2c_new_dummy

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.

---
 drivers/hwmon/w83792d.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/hwmon/w83792d.c +14 -1
index 76aa39e..2c168c5 100644
@@ -961,8 +961,15 @@ w83792d_detect_subclients(struct i2c_client *new_client)
 	}
 
 	val = w83792d_read_value(new_client, W83792D_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(&new_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))) {
@@ -974,6 +981,12 @@ w83792d_detect_subclients(struct i2c_client *new_client)
 		}
 		data->lm75[1] = i2c_new_dummy(adapter,
 					      0x48 + ((val >> 4) & 0x7));
+		if (data->lm75[1] == NULL) {
+			dev_err(&new_client->dev,
+				"Failed to allocate I2C device\n");
+			err = -ENODEV;
+			goto ERROR_SC_1;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.7.4
maintainer NAK
#1 lore raw
Quoted 3 lines · Zhouyang Jia

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

What are those unexpected results ? The i2c devicees are not really used; the only reason to allocate them was for address reservation purposes. This is why the result was ignored, since it does not really matter for driver operation. I don't see the point of making that fatal.

NACK, sorry.

Guenter

Quoted 42 lines

This patch adds error-handling code after calling i2c_new_dummy.

---
  drivers/hwmon/w83792d.c | 15 ++++++++++++++-
  1 file changed, 14 insertions(+), 1 deletion(-)
drivers/hwmon/w83792d.c +14 -1
index 76aa39e..2c168c5 100644
@@ -961,8 +961,15 @@ w83792d_detect_subclients(struct i2c_client *new_client)
  	}
 
  	val = w83792d_read_value(new_client, W83792D_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(&new_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))) {
@@ -974,6 +981,12 @@ w83792d_detect_subclients(struct i2c_client *new_client)
  		}
  		data->lm75[1] = i2c_new_dummy(adapter,
  					      0x48 + ((val >> 4) & 0x7));
+		if (data->lm75[1] == NULL) {
+			dev_err(&new_client->dev,
+				"Failed to allocate I2C device\n");
+			err = -ENODEV;
+			goto ERROR_SC_1;
+		}
  	}
 
  	return 0;