diff options
author | Bastian Germann <bastiangermann@fishpost.de> | 2018-06-01 11:14:19 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2018-06-01 12:38:36 -0400 |
commit | c9bdf291542e14dbc5b9a71aa11f995de0e54f0d (patch) | |
tree | 239c2f474707df6b22ca026a5dee07bfe41089f3 | |
parent | 3c60726d217b3e03cef2d9f785727a53fff49450 (diff) |
hwmon: (asus_atk0110) Make use of device managed memory
Use devm_* variants of kstrdup and kzalloc. Get rid of kfree cleanups.
Signed-off-by: Bastian Germann <bastiangermann@fishpost.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/asus_atk0110.c | 44 |
1 files changed, 8 insertions, 36 deletions
diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c index fcba2b82ec71..a6636fe42189 100644 --- a/drivers/hwmon/asus_atk0110.c +++ b/drivers/hwmon/asus_atk0110.c | |||
@@ -190,7 +190,6 @@ static int atk_add(struct acpi_device *device); | |||
190 | static int atk_remove(struct acpi_device *device); | 190 | static int atk_remove(struct acpi_device *device); |
191 | static void atk_print_sensor(struct atk_data *data, union acpi_object *obj); | 191 | static void atk_print_sensor(struct atk_data *data, union acpi_object *obj); |
192 | static int atk_read_value(struct atk_sensor_data *sensor, u64 *value); | 192 | static int atk_read_value(struct atk_sensor_data *sensor, u64 *value); |
193 | static void atk_free_sensors(struct atk_data *data); | ||
194 | 193 | ||
195 | static struct acpi_driver atk_driver = { | 194 | static struct acpi_driver atk_driver = { |
196 | .name = ATK_HID, | 195 | .name = ATK_HID, |
@@ -906,15 +905,13 @@ static int atk_add_sensor(struct atk_data *data, union acpi_object *obj) | |||
906 | limit1 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT1); | 905 | limit1 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT1); |
907 | limit2 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT2); | 906 | limit2 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT2); |
908 | 907 | ||
909 | sensor = kzalloc(sizeof(*sensor), GFP_KERNEL); | 908 | sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); |
910 | if (!sensor) | 909 | if (!sensor) |
911 | return -ENOMEM; | 910 | return -ENOMEM; |
912 | 911 | ||
913 | sensor->acpi_name = kstrdup(name->string.pointer, GFP_KERNEL); | 912 | sensor->acpi_name = devm_kstrdup(dev, name->string.pointer, GFP_KERNEL); |
914 | if (!sensor->acpi_name) { | 913 | if (!sensor->acpi_name) |
915 | err = -ENOMEM; | 914 | return -ENOMEM; |
916 | goto out; | ||
917 | } | ||
918 | 915 | ||
919 | INIT_LIST_HEAD(&sensor->list); | 916 | INIT_LIST_HEAD(&sensor->list); |
920 | sensor->type = type; | 917 | sensor->type = type; |
@@ -955,9 +952,6 @@ static int atk_add_sensor(struct atk_data *data, union acpi_object *obj) | |||
955 | (*num)++; | 952 | (*num)++; |
956 | 953 | ||
957 | return 1; | 954 | return 1; |
958 | out: | ||
959 | kfree(sensor); | ||
960 | return err; | ||
961 | } | 955 | } |
962 | 956 | ||
963 | static int atk_enumerate_old_hwmon(struct atk_data *data) | 957 | static int atk_enumerate_old_hwmon(struct atk_data *data) |
@@ -998,8 +992,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data) | |||
998 | dev_warn(dev, METHOD_OLD_ENUM_TMP ": ACPI exception: %s\n", | 992 | dev_warn(dev, METHOD_OLD_ENUM_TMP ": ACPI exception: %s\n", |
999 | acpi_format_exception(status)); | 993 | acpi_format_exception(status)); |
1000 | 994 | ||
1001 | ret = -ENODEV; | 995 | return -ENODEV; |
1002 | goto cleanup; | ||
1003 | } | 996 | } |
1004 | 997 | ||
1005 | pack = buf.pointer; | 998 | pack = buf.pointer; |
@@ -1020,8 +1013,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data) | |||
1020 | dev_warn(dev, METHOD_OLD_ENUM_FAN ": ACPI exception: %s\n", | 1013 | dev_warn(dev, METHOD_OLD_ENUM_FAN ": ACPI exception: %s\n", |
1021 | acpi_format_exception(status)); | 1014 | acpi_format_exception(status)); |
1022 | 1015 | ||
1023 | ret = -ENODEV; | 1016 | return -ENODEV; |
1024 | goto cleanup; | ||
1025 | } | 1017 | } |
1026 | 1018 | ||
1027 | pack = buf.pointer; | 1019 | pack = buf.pointer; |
@@ -1035,9 +1027,6 @@ static int atk_enumerate_old_hwmon(struct atk_data *data) | |||
1035 | ACPI_FREE(buf.pointer); | 1027 | ACPI_FREE(buf.pointer); |
1036 | 1028 | ||
1037 | return count; | 1029 | return count; |
1038 | cleanup: | ||
1039 | atk_free_sensors(data); | ||
1040 | return ret; | ||
1041 | } | 1030 | } |
1042 | 1031 | ||
1043 | static int atk_ec_present(struct atk_data *data) | 1032 | static int atk_ec_present(struct atk_data *data) |
@@ -1213,17 +1202,6 @@ static int atk_init_attribute_groups(struct atk_data *data) | |||
1213 | return 0; | 1202 | return 0; |
1214 | } | 1203 | } |
1215 | 1204 | ||
1216 | static void atk_free_sensors(struct atk_data *data) | ||
1217 | { | ||
1218 | struct list_head *head = &data->sensor_list; | ||
1219 | struct atk_sensor_data *s, *tmp; | ||
1220 | |||
1221 | list_for_each_entry_safe(s, tmp, head, list) { | ||
1222 | kfree(s->acpi_name); | ||
1223 | kfree(s); | ||
1224 | } | ||
1225 | } | ||
1226 | |||
1227 | static int atk_register_hwmon(struct atk_data *data) | 1205 | static int atk_register_hwmon(struct atk_data *data) |
1228 | { | 1206 | { |
1229 | struct device *dev = &data->acpi_dev->dev; | 1207 | struct device *dev = &data->acpi_dev->dev; |
@@ -1323,7 +1301,7 @@ static int atk_add(struct acpi_device *device) | |||
1323 | 1301 | ||
1324 | dev_dbg(&device->dev, "adding...\n"); | 1302 | dev_dbg(&device->dev, "adding...\n"); |
1325 | 1303 | ||
1326 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 1304 | data = devm_kzalloc(&device->dev, sizeof(*data), GFP_KERNEL); |
1327 | if (!data) | 1305 | if (!data) |
1328 | return -ENOMEM; | 1306 | return -ENOMEM; |
1329 | 1307 | ||
@@ -1375,18 +1353,15 @@ static int atk_add(struct acpi_device *device) | |||
1375 | goto out; | 1353 | goto out; |
1376 | err = atk_register_hwmon(data); | 1354 | err = atk_register_hwmon(data); |
1377 | if (err) | 1355 | if (err) |
1378 | goto cleanup; | 1356 | goto out; |
1379 | 1357 | ||
1380 | atk_debugfs_init(data); | 1358 | atk_debugfs_init(data); |
1381 | 1359 | ||
1382 | device->driver_data = data; | 1360 | device->driver_data = data; |
1383 | return 0; | 1361 | return 0; |
1384 | cleanup: | ||
1385 | atk_free_sensors(data); | ||
1386 | out: | 1362 | out: |
1387 | if (data->disable_ec) | 1363 | if (data->disable_ec) |
1388 | atk_ec_ctl(data, 0); | 1364 | atk_ec_ctl(data, 0); |
1389 | kfree(data); | ||
1390 | return err; | 1365 | return err; |
1391 | } | 1366 | } |
1392 | 1367 | ||
@@ -1399,7 +1374,6 @@ static int atk_remove(struct acpi_device *device) | |||
1399 | 1374 | ||
1400 | atk_debugfs_cleanup(data); | 1375 | atk_debugfs_cleanup(data); |
1401 | 1376 | ||
1402 | atk_free_sensors(data); | ||
1403 | hwmon_device_unregister(data->hwmon_dev); | 1377 | hwmon_device_unregister(data->hwmon_dev); |
1404 | 1378 | ||
1405 | if (data->disable_ec) { | 1379 | if (data->disable_ec) { |
@@ -1407,8 +1381,6 @@ static int atk_remove(struct acpi_device *device) | |||
1407 | dev_err(&device->dev, "Failed to disable EC\n"); | 1381 | dev_err(&device->dev, "Failed to disable EC\n"); |
1408 | } | 1382 | } |
1409 | 1383 | ||
1410 | kfree(data); | ||
1411 | |||
1412 | return 0; | 1384 | return 0; |
1413 | } | 1385 | } |
1414 | 1386 | ||