Re: [PATCH 02/10] platform/x86: toshiba_acpi: use devm_add_action_or_reset() for singleton clear

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

> The only reason to do this is to enforce the ordering of deinitialization,
> when the conversion of the device-managed functions is done.
> 
> The singleton object should be cleared right before it is free'd.
> 
> Signed-off-by: Alexandru Ardelean <aardelean@xxxxxxxxxxx>

Whilst this might help get towards your goal, I'm curious to why
this singleton actually needs to exist in the first place.

It doesn't feel like it would be very hard to remove.
1) embed the kbd_bl_work in struct toshiba_acpi_dev with appropriate changes to it's init.
   use container_of() magic to get to that. 
2) For the toshiba_iio_accel_read_raw() stash a copy of the pointer in iio_priv(indio_dev)
   Note that I'm very suspicious of existing sizeing of the private region. 
3) For miscdevice handling you should be able to use container_of() to get to the
   toshiba_acpi_dev structure from file->private_data

There are a few places where the struct toshiba_acpi_dev will need passing into functions
that currently get it from the global, plus one place where I'm fairly sure an element
of that structure gets set twice in a row via different copies of the pointer.

Also nice to not use dev as the name for struct toshiba_acpi_dev * as that is
makes for some confusing code when we have a bunch of struct device * in use
as well.

So this is fine, but kind of feels like the code shouldn't be there in the first place!

Jonathan

> ---
>  drivers/platform/x86/toshiba_acpi.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
> index 6d298810b7bf..c5284601bc2a 100644
> --- a/drivers/platform/x86/toshiba_acpi.c
> +++ b/drivers/platform/x86/toshiba_acpi.c
> @@ -2995,9 +2995,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
>  		rfkill_destroy(dev->wwan_rfk);
>  	}
>  
> -	if (toshiba_acpi)
> -		toshiba_acpi = NULL;
> -
>  	return 0;
>  }
>  
> @@ -3012,6 +3009,11 @@ static const char *find_hci_method(acpi_handle handle)
>  	return NULL;
>  }
>  
> +static void toshiba_acpi_singleton_clear(void *data)
> +{
> +	toshiba_acpi = NULL;
> +}
> +
>  static int toshiba_acpi_add(struct acpi_device *acpi_dev)
>  {
>  	struct device *parent = &acpi_dev->dev;
> @@ -3035,6 +3037,13 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
>  	dev = devm_kzalloc(parent, sizeof(*dev), GFP_KERNEL);
>  	if (!dev)
>  		return -ENOMEM;
> +
> +	ret = devm_add_action_or_reset(parent,
> +				       toshiba_acpi_singleton_clear,
> +				       NULL);
> +	if (ret)
> +		return ret;
> +
>  	dev->acpi_dev = acpi_dev;
>  	dev->method_hci = hci_method;
>  	dev->miscdev.minor = MISC_DYNAMIC_MINOR;




[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux