linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Alexandru Ardelean <aardelean@deviqon.com>
Cc: platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	coproscefalo@gmail.com, hdegoede@redhat.com,
	mgross@linux.intel.com, linux@deviqon.com
Subject: Re: [PATCH 08/10] platform/x86: toshiba_acpi: use device-managed for wwan_rfkill management
Date: Mon, 29 Mar 2021 15:57:13 +0100	[thread overview]
Message-ID: <20210329155713.3c19c0d1@jic23-huawei> (raw)
In-Reply-To: <20210324125548.45983-9-aardelean@deviqon.com>

On Wed, 24 Mar 2021 14:55:46 +0200
Alexandru Ardelean <aardelean@deviqon.com> wrote:

> This change converts the wwan_rfkill object to be free'd automatically when
> the parent refcount goes to zero.
> There are 2 cleanup operations required: rfkill_unregister() and
> rfkill_destroy(). Since they don't have any devm_ variants, they are hooked
> via devm_add_action_or_reset().
> 
> The main reason to do this is to enforce ordering on cleanup, when the
> Toshiba ACPI device is cleaned up.
> 
> Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Superficially looks fine to me though I don't know much about rfkill.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/platform/x86/toshiba_acpi.c | 40 ++++++++++++++++++++++-------
>  1 file changed, 31 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
> index 12860ef60e4d..a1249f6dde9a 100644
> --- a/drivers/platform/x86/toshiba_acpi.c
> +++ b/drivers/platform/x86/toshiba_acpi.c
> @@ -2591,7 +2591,22 @@ static const struct rfkill_ops wwan_rfk_ops = {
>  	.poll = toshiba_acpi_wwan_poll,
>  };
>  
> -static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev)
> +static void toshiba_acpi_rfkill_destroy(void *data)
> +{
> +	struct rfkill *wwan_rfk = data;
> +
> +	rfkill_destroy(wwan_rfk);
> +}
> +
> +static void toshiba_acpi_rfkill_unreg(void *data)
> +{
> +	struct rfkill *wwan_rfk = data;
> +
> +	rfkill_unregister(wwan_rfk);
> +}
> +
> +static int toshiba_acpi_setup_wwan_rfkill(struct device *parent,
> +					  struct toshiba_acpi_dev *dev)
>  {
>  	int ret = toshiba_wireless_status(dev);
>  
> @@ -2608,15 +2623,27 @@ static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev)
>  		return -ENOMEM;
>  	}
>  
> +	ret = devm_add_action_or_reset(parent, toshiba_acpi_rfkill_destroy,
> +				       dev->wwan_rfk);
> +	if (ret)
> +		return ret;
> +
>  	rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
>  
>  	ret = rfkill_register(dev->wwan_rfk);
>  	if (ret) {
>  		pr_err("Unable to register WWAN rfkill device\n");
> -		rfkill_destroy(dev->wwan_rfk);
> +		return ret;
>  	}
>  
> -	return ret;
> +	ret = devm_add_action_or_reset(parent, toshiba_acpi_rfkill_unreg,
> +				       dev->wwan_rfk);
> +	if (ret) {
> +		dev->wwan_rfk = NULL;
> +		return ret;
> +	}
> +
> +	return 0;
>  }
>  
>  /*
> @@ -2996,11 +3023,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
>  		sysfs_remove_group(&dev->acpi_dev->dev.kobj,
>  				   &toshiba_attr_group);
>  
> -	if (dev->wwan_rfk) {
> -		rfkill_unregister(dev->wwan_rfk);
> -		rfkill_destroy(dev->wwan_rfk);
> -	}
> -
>  	return 0;
>  }
>  
> @@ -3189,7 +3211,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
>  
>  	toshiba_wwan_available(dev);
>  	if (dev->wwan_supported)
> -		toshiba_acpi_setup_wwan_rfkill(dev);
> +		toshiba_acpi_setup_wwan_rfkill(parent, dev);
>  
>  	toshiba_cooling_method_available(dev);
>  


  reply	other threads:[~2021-03-29 14:57 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24 12:55 [PATCH 00/10] platform/x86: toshiba_acpi: move acpi add/remove to device-managed routines Alexandru Ardelean
2021-03-24 12:55 ` [PATCH 01/10] platform/x86: toshiba_acpi: bind life-time of toshiba_acpi_dev to parent Alexandru Ardelean
2021-03-29 14:30   ` Jonathan Cameron
2021-03-30  6:49     ` Alexandru Ardelean
2021-03-24 12:55 ` [PATCH 02/10] platform/x86: toshiba_acpi: use devm_add_action_or_reset() for singleton clear Alexandru Ardelean
2021-03-29 14:27   ` Jonathan Cameron
2021-03-24 12:55 ` [PATCH 03/10] platform/x86: toshiba_acpi: bind registration of miscdev object to parent Alexandru Ardelean
2021-03-29 14:33   ` Jonathan Cameron
2021-03-24 12:55 ` [PATCH 04/10] platform/x86: toshiba_acpi: use device-managed functions for input device Alexandru Ardelean
2021-03-29 14:48   ` Jonathan Cameron
2021-03-24 12:55 ` [PATCH 05/10] platform/x86: toshiba_acpi: register backlight with device-managed variant Alexandru Ardelean
2021-03-29 14:50   ` Jonathan Cameron
2021-03-24 12:55 ` [PATCH 06/10] platform/x86: toshiba_acpi: use devm_led_classdev_register() for LEDs Alexandru Ardelean
2021-03-29 14:52   ` Jonathan Cameron
2021-03-24 12:55 ` [PATCH 07/10] platform/x86: toshiba_acpi: use device-managed functions for accelerometer Alexandru Ardelean
2021-03-29 14:54   ` Jonathan Cameron
2021-03-24 12:55 ` [PATCH 08/10] platform/x86: toshiba_acpi: use device-managed for wwan_rfkill management Alexandru Ardelean
2021-03-29 14:57   ` Jonathan Cameron [this message]
2021-03-24 12:55 ` [PATCH 09/10] platform/x86: toshiba_acpi: use device-managed for sysfs removal Alexandru Ardelean
2021-03-29 15:09   ` Jonathan Cameron
2021-03-24 12:55 ` [PATCH 10/10] platform/x86: toshiba_acpi: bind proc entries creation to parent Alexandru Ardelean
2021-03-29 15:10   ` Jonathan Cameron
2021-03-29 12:38 ` [PATCH 00/10] platform/x86: toshiba_acpi: move acpi add/remove to device-managed routines Jonathan Cameron
2021-03-29 14:01   ` Alexandru Ardelean
2021-03-30  8:20 ` Hans de Goede
2021-03-30  9:22   ` Alexandru Ardelean
2021-03-30  9:27     ` Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210329155713.3c19c0d1@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=aardelean@deviqon.com \
    --cc=coproscefalo@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@deviqon.com \
    --cc=mgross@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).