[PATCH 07/10] platform/x86: toshiba_acpi: use device-managed functions for accelerometer
From: Alexandru Ardelean
Date: Wed Mar 24 2021 - 08:57:07 EST
This change converts the IIO registration to use devm_iio_device_alloc()
and devm_iio_device_register().
With this change we can remove the manual deregistrations an freeing of the
IIO data.
This also makes the deregistration symmetrical with the registration.
One side-effect (that is undesired), is that if devm_iio_device_register()
fails, then the IIO object will not be free'd and will stick around until
the parent object is free'd. This is because there is no
devm_iio_device_free() function anymore in IIO.
However, this is a pretty bad corner-case that should not happen under
normal operation.
Signed-off-by: Alexandru Ardelean <aardelean@xxxxxxxxxxx>
---
drivers/platform/x86/toshiba_acpi.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index e787c140eec2..12860ef60e4d 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -2992,11 +2992,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
remove_toshiba_proc_entries(dev);
- if (dev->accelerometer_supported && dev->indio_dev) {
- iio_device_unregister(dev->indio_dev);
- iio_device_free(dev->indio_dev);
- }
-
if (dev->sysfs_created)
sysfs_remove_group(&dev->acpi_dev->dev.kobj,
&toshiba_attr_group);
@@ -3149,7 +3144,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
toshiba_accelerometer_available(dev);
if (dev->accelerometer_supported) {
- dev->indio_dev = iio_device_alloc(&acpi_dev->dev, sizeof(*dev));
+ dev->indio_dev = devm_iio_device_alloc(parent, sizeof(*dev));
if (!dev->indio_dev) {
pr_err("Unable to allocate iio device\n");
goto iio_error;
@@ -3164,10 +3159,10 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
dev->indio_dev->num_channels =
ARRAY_SIZE(toshiba_iio_accel_channels);
- ret = iio_device_register(dev->indio_dev);
+ ret = devm_iio_device_register(parent, dev->indio_dev);
if (ret < 0) {
pr_err("Unable to register iio device\n");
- iio_device_free(dev->indio_dev);
+ dev->indio_dev = NULL;
}
}
iio_error:
--
2.30.2