Commit 918ddef3 authored by Guenter Roeck's avatar Guenter Roeck Committed by Guenter Roeck

hwmon: (max16065) Convert to use devm_kzalloc

Marginally less code and eliminate the possibility of memory leaks.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent b8a5a7ce
...@@ -554,7 +554,7 @@ static int max16065_probe(struct i2c_client *client, ...@@ -554,7 +554,7 @@ static int max16065_probe(struct i2c_client *client,
| I2C_FUNC_SMBUS_READ_WORD_DATA)) | I2C_FUNC_SMBUS_READ_WORD_DATA))
return -ENODEV; return -ENODEV;
data = kzalloc(sizeof(*data), GFP_KERNEL); data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
if (unlikely(!data)) if (unlikely(!data))
return -ENOMEM; return -ENOMEM;
...@@ -567,20 +567,16 @@ static int max16065_probe(struct i2c_client *client, ...@@ -567,20 +567,16 @@ static int max16065_probe(struct i2c_client *client,
if (have_secondary) { if (have_secondary) {
val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE); val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE);
if (unlikely(val < 0)) { if (unlikely(val < 0))
ret = val; return val;
goto out_free;
}
secondary_is_max = val & MAX16065_WARNING_OV; secondary_is_max = val & MAX16065_WARNING_OV;
} }
/* Read scale registers, convert to range */ /* Read scale registers, convert to range */
for (i = 0; i < DIV_ROUND_UP(data->num_adc, 4); i++) { for (i = 0; i < DIV_ROUND_UP(data->num_adc, 4); i++) {
val = i2c_smbus_read_byte_data(client, MAX16065_SCALE(i)); val = i2c_smbus_read_byte_data(client, MAX16065_SCALE(i));
if (unlikely(val < 0)) { if (unlikely(val < 0))
ret = val; return val;
goto out_free;
}
for (j = 0; j < 4 && i * 4 + j < data->num_adc; j++) { for (j = 0; j < 4 && i * 4 + j < data->num_adc; j++) {
data->range[i * 4 + j] = data->range[i * 4 + j] =
max16065_adc_range[(val >> (j * 2)) & 0x3]; max16065_adc_range[(val >> (j * 2)) & 0x3];
...@@ -595,10 +591,8 @@ static int max16065_probe(struct i2c_client *client, ...@@ -595,10 +591,8 @@ static int max16065_probe(struct i2c_client *client,
for (j = 0; j < data->num_adc; j++) { for (j = 0; j < data->num_adc; j++) {
val = i2c_smbus_read_byte_data(client, val = i2c_smbus_read_byte_data(client,
MAX16065_LIMIT(i, j)); MAX16065_LIMIT(i, j));
if (unlikely(val < 0)) { if (unlikely(val < 0))
ret = val; return val;
goto out_free;
}
data->limit[i][j] = LIMIT_TO_MV(val, data->range[j]); data->limit[i][j] = LIMIT_TO_MV(val, data->range[j]);
} }
} }
...@@ -661,8 +655,6 @@ static int max16065_probe(struct i2c_client *client, ...@@ -661,8 +655,6 @@ static int max16065_probe(struct i2c_client *client,
out: out:
max16065_cleanup(client); max16065_cleanup(client);
out_free:
kfree(data);
return ret; return ret;
} }
...@@ -672,7 +664,6 @@ static int max16065_remove(struct i2c_client *client) ...@@ -672,7 +664,6 @@ static int max16065_remove(struct i2c_client *client)
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
max16065_cleanup(client); max16065_cleanup(client);
kfree(data);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment