diff mbox series

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

Message ID 20210324125548.45983-2-aardelean@deviqon.com (mailing list archive)
State New, archived
Headers show
Series platform/x86: toshiba_acpi: move acpi add/remove to device-managed routines | expand

Commit Message

Alexandru Ardelean March 24, 2021, 12:55 p.m. UTC
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@deviqon.com>
---
 drivers/platform/x86/toshiba_acpi.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Jonathan Cameron March 29, 2021, 2:30 p.m. UTC | #1
On Wed, 24 Mar 2021 14:55:39 +0200
Alexandru Ardelean <aardelean@deviqon.com> 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@deviqon.com>

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;
>  	}
>
Alexandru Ardelean March 30, 2021, 6:49 a.m. UTC | #2
On Mon, 29 Mar 2021 at 17:30, Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Wed, 24 Mar 2021 14:55:39 +0200
> Alexandru Ardelean <aardelean@deviqon.com> 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@deviqon.com>
>
> Might just be me, but naming anything dev that isn't a struct device *
> is downright confusing?
>

I found it a bit odd as well, but I decided to not take it in
consideration for now.

>
>
>
> > ---
> >  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;
> >       }
> >
>
diff mbox series

Patch

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;
 	}