Skip to contentSkip to conversation

hwmon: (adm1275) Free allocated memory if

PATCH In review Guenter Roeck 2 participants 3 messages Jun 30, 2011 – Jul 3, 2011 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 hwmon: (adm1275) Free allocated memory if

Probe function did not free allocated memory if it failed. Fix it.

---
 drivers/hwmon/adm1275.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
drivers/hwmon/adm1275.c +13 -3
index c2ee204..b9b7caf 100644
@@ -32,6 +32,7 @@ static int adm1275_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
 	int config;
+	int ret;
 	struct pmbus_driver_info *info;
 
 	if (!i2c_check_functionality(client->adapter,
@@ -43,8 +44,10 @@ static int adm1275_probe(struct i2c_client *client,
 		return -ENOMEM;
 
 	config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
-	if (config < 0)
-		return config;
+	if (config < 0) {
+		ret = config;
+		goto err_mem;
+	}
 
 	info->pages = 1;
 	info->direct[PSC_VOLTAGE_IN] = true;
@@ -76,7 +79,14 @@ static int adm1275_probe(struct i2c_client *client,
 	else
 		info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
 
-	return pmbus_do_probe(client, id, info);
+	ret = pmbus_do_probe(client, id, info);
+	if (ret)
+		goto err_mem;
+	return 0;
+
+err_mem:
+	kfree(info);
+	return ret;
 }
 
 static int adm1275_remove(struct i2c_client *client)
Signature · 7 lines
1.7.3.1


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v1 2/4
#1 lore raw

Re: [lm-sensors] [PATCH 2/4] hwmon: (adm1275) Free allocated memory

Quoted 3 lines · Guenter Roeck

Probe function did not free allocated memory if it failed. Fix it.

Good catch.

Quoted 45 lines
---
 drivers/hwmon/adm1275.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
drivers/hwmon/adm1275.c +13 -3
index c2ee204..b9b7caf 100644
@@ -32,6 +32,7 @@ static int adm1275_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
 	int config;
+	int ret;
 	struct pmbus_driver_info *info;
 
 	if (!i2c_check_functionality(client->adapter,
@@ -43,8 +44,10 @@ static int adm1275_probe(struct i2c_client *client,
 		return -ENOMEM;
 
 	config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
-	if (config < 0)
-		return config;
+	if (config < 0) {
+		ret = config;
+		goto err_mem;
+	}
 
 	info->pages = 1;
 	info->direct[PSC_VOLTAGE_IN] = true;
@@ -76,7 +79,14 @@ static int adm1275_probe(struct i2c_client *client,
 	else
 		info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
 
-	return pmbus_do_probe(client, id, info);
+	ret = pmbus_do_probe(client, id, info);
+	if (ret)
+		goto err_mem;
+	return 0;
+
+err_mem:
+	kfree(info);
+	return ret;
 }
 
 static int adm1275_remove(struct i2c_client *client)
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw

Re: [lm-sensors] [PATCH 2/4] hwmon: (adm1275) Free allocated memory

In reply to Guenter Roeck
Quoted 9 lines · Jean Delvare
Quoted 3 lines · Guenter Roeck

Probe function did not free allocated memory if it failed. Fix it.

Good catch.

Embarassing, actually, since I had that same piece of code in other drivers and got it right there ;).

Thanks for the review,

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors