Re: [PATCH 03/10] platform/x86: toshiba_acpi: bind registration of miscdev object to parent

2021-03-29 Thread Jonathan Cameron
On Wed, 24 Mar 2021 14:55:41 +0200
Alexandru Ardelean  wrote:

> This change moves the registration of the Toshiba ACPI miscdev to be
> handled by the devm_add_action_or_reset() hook. This way, the miscdev will
> be unregistered when the reference count of the parent device object goes
> to zero.
> 
> This also changes the order of cleanup in toshiba_acpi_remove(), where the
> miscdev was deregistered first. Now it will be deregistered right before
> the toshiba_acpi_dev object is free'd.
> 
> Signed-off-by: Alexandru Ardelean 
Reorder looks right to me, but maybe I'm missing something subtle.

Acked-by: Jonathan Cameron 

One unrelated comment inline.

Jonathan

> ---
>  drivers/platform/x86/toshiba_acpi.c | 14 --
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/x86/toshiba_acpi.c 
> b/drivers/platform/x86/toshiba_acpi.c
> index c5284601bc2a..53ef565378ef 100644
> --- a/drivers/platform/x86/toshiba_acpi.c
> +++ b/drivers/platform/x86/toshiba_acpi.c
> @@ -2963,8 +2963,6 @@ static int toshiba_acpi_remove(struct acpi_device 
> *acpi_dev)
>  {
>   struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
>  
> - misc_deregister(>miscdev);
> -
>   remove_toshiba_proc_entries(dev);
>  
>   if (dev->accelerometer_supported && dev->indio_dev) {
> @@ -3014,6 +3012,13 @@ static void toshiba_acpi_singleton_clear(void *data)
>   toshiba_acpi = NULL;
>  }
>  
> +static void toshiba_acpi_misc_deregister(void *data)
> +{
> + struct miscdevice *miscdev = data;
> +
> + misc_deregister(miscdev);
> +}
> +
>  static int toshiba_acpi_add(struct acpi_device *acpi_dev)
>  {
>   struct device *parent = _dev->dev;
> @@ -3056,6 +3061,11 @@ static int toshiba_acpi_add(struct acpi_device 
> *acpi_dev)
>   return ret;
>   }
>  
> + ret = devm_add_action_or_reset(parent, toshiba_acpi_misc_deregister,
> +>miscdev);
> + if (ret)
> + return ret;
> +
>   acpi_dev->driver_data = dev;
>   dev_set_drvdata(_dev->dev, dev);

Why are we carrying two copies of the same thing? (obviously unrelated
to your patch :)

>  



[PATCH 03/10] platform/x86: toshiba_acpi: bind registration of miscdev object to parent

2021-03-24 Thread Alexandru Ardelean
This change moves the registration of the Toshiba ACPI miscdev to be
handled by the devm_add_action_or_reset() hook. This way, the miscdev will
be unregistered when the reference count of the parent device object goes
to zero.

This also changes the order of cleanup in toshiba_acpi_remove(), where the
miscdev was deregistered first. Now it will be deregistered right before
the toshiba_acpi_dev object is free'd.

Signed-off-by: Alexandru Ardelean 
---
 drivers/platform/x86/toshiba_acpi.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index c5284601bc2a..53ef565378ef 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -2963,8 +2963,6 @@ static int toshiba_acpi_remove(struct acpi_device 
*acpi_dev)
 {
struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
 
-   misc_deregister(>miscdev);
-
remove_toshiba_proc_entries(dev);
 
if (dev->accelerometer_supported && dev->indio_dev) {
@@ -3014,6 +3012,13 @@ static void toshiba_acpi_singleton_clear(void *data)
toshiba_acpi = NULL;
 }
 
+static void toshiba_acpi_misc_deregister(void *data)
+{
+   struct miscdevice *miscdev = data;
+
+   misc_deregister(miscdev);
+}
+
 static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 {
struct device *parent = _dev->dev;
@@ -3056,6 +3061,11 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
return ret;
}
 
+   ret = devm_add_action_or_reset(parent, toshiba_acpi_misc_deregister,
+  >miscdev);
+   if (ret)
+   return ret;
+
acpi_dev->driver_data = dev;
dev_set_drvdata(_dev->dev, dev);
 
-- 
2.30.2