Re: [PATCH 01/10] platform/x86: toshiba_acpi: bind life-time of toshiba_acpi_dev to parent

From: Jonathan Cameron
Date: Mon Mar 29 2021 - 10:31:41 EST


On Wed, 24 Mar 2021 14:55:39 +0200
Alexandru Ardelean <aardelean@xxxxxxxxxxx> wrote:

> The 'toshiba_acpi_dev' object is allocated first and free'd last. We can
> bind it's life-time to the parent ACPI device object. This is a first step
> in using more device-managed allocated functions for this.
>
> The main intent is to try to convert the IIO framework to export only
> device-managed functions (i.e. devm_iio_device_alloc() and
> devm_iio_device_register()). It's still not 100% sure that this is
> possible, but for now, this is the process of taking it slowly in that
> direction.
>
> Signed-off-by: Alexandru Ardelean <aardelean@xxxxxxxxxxx>

Might just be me, but naming anything dev that isn't a struct device *
is downright confusing?




> ---
> drivers/platform/x86/toshiba_acpi.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
> index fa7232ad8c39..6d298810b7bf 100644
> --- a/drivers/platform/x86/toshiba_acpi.c
> +++ b/drivers/platform/x86/toshiba_acpi.c
> @@ -2998,8 +2998,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
> if (toshiba_acpi)
> toshiba_acpi = NULL;
>
> - kfree(dev);
> -
> return 0;
> }
>
> @@ -3016,6 +3014,7 @@ static const char *find_hci_method(acpi_handle handle)
>
> static int toshiba_acpi_add(struct acpi_device *acpi_dev)
> {
> + struct device *parent = &acpi_dev->dev;
> struct toshiba_acpi_dev *dev;
> const char *hci_method;
> u32 dummy;
> @@ -3033,7 +3032,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
> return -ENODEV;
> }
>
> - dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> + dev = devm_kzalloc(parent, sizeof(*dev), GFP_KERNEL);
> if (!dev)
> return -ENOMEM;
> dev->acpi_dev = acpi_dev;
> @@ -3045,7 +3044,6 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
> ret = misc_register(&dev->miscdev);
> if (ret) {
> pr_err("Failed to register miscdevice\n");
> - kfree(dev);
> return ret;
> }
>