kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] iio: adc128s052: Simplify 'adc128_probe()'
@ 2021-08-26 18:36 Christophe JAILLET
  2021-08-29 17:16 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2021-08-26 18:36 UTC (permalink / raw)
  To: jic23, lars, ardeleanalex, andy.shevchenko
  Cc: linux-iio, linux-kernel, kernel-janitors, Christophe JAILLET

Turn 'adc128_probe()' into a full resource managed function to simplify the
code.

This way, the .remove function can be removed.
Doing so, the only 'spi_get_drvdata()' call is removed and the
corresponding 'spi_set_drvdata()' can be removed as well.

Suggested-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
---
Compile tested only.

When reviewing, pay special attention to the 'spi_set_drvdata()' call
removal. I recently introduced a regression with a too aggressive cleanup
like that.

This patch should be applied after
https://lore.kernel.org/linux-iio/f33069f0-601b-4bbb-3766-026f7a161912-39ZsbGIQGT5GWvitb5QawA@public.gmane.org/T/#meb792dcd6540f87d9ae041660ca4738a776e924a

v1 --> v2: just garbage --> ignore
v1 --> v3: Simplify 'adc128_disable_regulator()'
---
 drivers/iio/adc/ti-adc128s052.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
index 3143f35a6509..ce0cfe40b219 100644
--- a/drivers/iio/adc/ti-adc128s052.c
+++ b/drivers/iio/adc/ti-adc128s052.c
@@ -132,6 +132,11 @@ static const struct iio_info adc128_info = {
 	.read_raw = adc128_read_raw,
 };
 
+static void adc128_disable_regulator(void *reg)
+{
+	regulator_disable(reg);
+}
+
 static int adc128_probe(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev;
@@ -151,8 +156,6 @@ static int adc128_probe(struct spi_device *spi)
 	adc = iio_priv(indio_dev);
 	adc->spi = spi;
 
-	spi_set_drvdata(spi, indio_dev);
-
 	indio_dev->name = spi_get_device_id(spi)->name;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &adc128_info;
@@ -167,23 +170,13 @@ static int adc128_probe(struct spi_device *spi)
 	ret = regulator_enable(adc->reg);
 	if (ret < 0)
 		return ret;
+	ret = devm_add_action_or_reset(&spi->dev, adc128_disable_regulator, adc->reg);
+	if (ret)
+		return ret;
 
 	mutex_init(&adc->lock);
 
-	ret = iio_device_register(indio_dev);
-
-	return ret;
-}
-
-static int adc128_remove(struct spi_device *spi)
-{
-	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct adc128 *adc = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
-	regulator_disable(adc->reg);
-
-	return 0;
+	return devm_iio_device_register(&spi->dev, indio_dev);
 }
 
 static const struct of_device_id adc128_of_match[] = {
@@ -225,7 +218,6 @@ static struct spi_driver adc128_driver = {
 		.acpi_match_table = ACPI_PTR(adc128_acpi_match),
 	},
 	.probe = adc128_probe,
-	.remove = adc128_remove,
 	.id_table = adc128_id,
 };
 module_spi_driver(adc128_driver);
-- 
2.30.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] iio: adc128s052: Simplify 'adc128_probe()'
  2021-08-26 18:36 [PATCH v3] iio: adc128s052: Simplify 'adc128_probe()' Christophe JAILLET
@ 2021-08-29 17:16 ` Jonathan Cameron
  2021-10-13 20:07   ` Christophe JAILLET
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2021-08-29 17:16 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: lars, ardeleanalex, andy.shevchenko, linux-iio, linux-kernel,
	kernel-janitors

On Thu, 26 Aug 2021 20:36:22 +0200
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> Turn 'adc128_probe()' into a full resource managed function to simplify the
> code.
> 
> This way, the .remove function can be removed.
> Doing so, the only 'spi_get_drvdata()' call is removed and the
> corresponding 'spi_set_drvdata()' can be removed as well.
> 
> Suggested-by: Alexandru Ardelean <ardeleanalex@gmail.com>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Looks good to me, but as mentioned this will need to wait for the
fix to go upstream.

Give me a poke if I seem to have lost it once that's true.

Thanks,

Jonathan

> ---
> Compile tested only.
> 
> When reviewing, pay special attention to the 'spi_set_drvdata()' call
> removal. I recently introduced a regression with a too aggressive cleanup
> like that.
> 
> This patch should be applied after
> https://lore.kernel.org/linux-iio/f33069f0-601b-4bbb-3766-026f7a161912-39ZsbGIQGT5GWvitb5QawA@public.gmane.org/T/#meb792dcd6540f87d9ae041660ca4738a776e924a
> 
> v1 --> v2: just garbage --> ignore
> v1 --> v3: Simplify 'adc128_disable_regulator()'
> ---
>  drivers/iio/adc/ti-adc128s052.c | 26 +++++++++-----------------
>  1 file changed, 9 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
> index 3143f35a6509..ce0cfe40b219 100644
> --- a/drivers/iio/adc/ti-adc128s052.c
> +++ b/drivers/iio/adc/ti-adc128s052.c
> @@ -132,6 +132,11 @@ static const struct iio_info adc128_info = {
>  	.read_raw = adc128_read_raw,
>  };
>  
> +static void adc128_disable_regulator(void *reg)
> +{
> +	regulator_disable(reg);
> +}
> +
>  static int adc128_probe(struct spi_device *spi)
>  {
>  	struct iio_dev *indio_dev;
> @@ -151,8 +156,6 @@ static int adc128_probe(struct spi_device *spi)
>  	adc = iio_priv(indio_dev);
>  	adc->spi = spi;
>  
> -	spi_set_drvdata(spi, indio_dev);
> -
>  	indio_dev->name = spi_get_device_id(spi)->name;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  	indio_dev->info = &adc128_info;
> @@ -167,23 +170,13 @@ static int adc128_probe(struct spi_device *spi)
>  	ret = regulator_enable(adc->reg);
>  	if (ret < 0)
>  		return ret;
> +	ret = devm_add_action_or_reset(&spi->dev, adc128_disable_regulator, adc->reg);
> +	if (ret)
> +		return ret;
>  
>  	mutex_init(&adc->lock);
>  
> -	ret = iio_device_register(indio_dev);
> -
> -	return ret;
> -}
> -
> -static int adc128_remove(struct spi_device *spi)
> -{
> -	struct iio_dev *indio_dev = spi_get_drvdata(spi);
> -	struct adc128 *adc = iio_priv(indio_dev);
> -
> -	iio_device_unregister(indio_dev);
> -	regulator_disable(adc->reg);
> -
> -	return 0;
> +	return devm_iio_device_register(&spi->dev, indio_dev);
>  }
>  
>  static const struct of_device_id adc128_of_match[] = {
> @@ -225,7 +218,6 @@ static struct spi_driver adc128_driver = {
>  		.acpi_match_table = ACPI_PTR(adc128_acpi_match),
>  	},
>  	.probe = adc128_probe,
> -	.remove = adc128_remove,
>  	.id_table = adc128_id,
>  };
>  module_spi_driver(adc128_driver);


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] iio: adc128s052: Simplify 'adc128_probe()'
  2021-08-29 17:16 ` Jonathan Cameron
@ 2021-10-13 20:07   ` Christophe JAILLET
  2021-10-20 16:42     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2021-10-13 20:07 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: lars, ardeleanalex, andy.shevchenko, linux-iio, linux-kernel,
	kernel-janitors

Le 29/08/2021 à 19:16, Jonathan Cameron a écrit :
> On Thu, 26 Aug 2021 20:36:22 +0200
> Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
> 
>> Turn 'adc128_probe()' into a full resource managed function to simplify the
>> code.
>>
>> This way, the .remove function can be removed.
>> Doing so, the only 'spi_get_drvdata()' call is removed and the
>> corresponding 'spi_set_drvdata()' can be removed as well.
>>
>> Suggested-by: Alexandru Ardelean <ardeleanalex@gmail.com>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
> Looks good to me, but as mentioned this will need to wait for the
> fix to go upstream.
> 
> Give me a poke if I seem to have lost it once that's true.

Hi,

looks like it's fine now. So this is a gentle reminder :)
The fix is in -next (see [1])

CJ

[1]: 
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/drivers/iio/adc/ti-adc128s052.c

> 
> Thanks,
> 
> Jonathan
> 
>> ---
>> Compile tested only.
>>
>> When reviewing, pay special attention to the 'spi_set_drvdata()' call
>> removal. I recently introduced a regression with a too aggressive cleanup
>> like that.
>>
>> This patch should be applied after
>> https://lore.kernel.org/linux-iio/f33069f0-601b-4bbb-3766-026f7a161912-39ZsbGIQGT5GWvitb5QawA@public.gmane.org/T/#meb792dcd6540f87d9ae041660ca4738a776e924a
>>
>> v1 --> v2: just garbage --> ignore
>> v1 --> v3: Simplify 'adc128_disable_regulator()'
>> ---
>>   drivers/iio/adc/ti-adc128s052.c | 26 +++++++++-----------------
>>   1 file changed, 9 insertions(+), 17 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
>> index 3143f35a6509..ce0cfe40b219 100644
>> --- a/drivers/iio/adc/ti-adc128s052.c
>> +++ b/drivers/iio/adc/ti-adc128s052.c
>> @@ -132,6 +132,11 @@ static const struct iio_info adc128_info = {
>>   	.read_raw = adc128_read_raw,
>>   };
>>   
>> +static void adc128_disable_regulator(void *reg)
>> +{
>> +	regulator_disable(reg);
>> +}
>> +
>>   static int adc128_probe(struct spi_device *spi)
>>   {
>>   	struct iio_dev *indio_dev;
>> @@ -151,8 +156,6 @@ static int adc128_probe(struct spi_device *spi)
>>   	adc = iio_priv(indio_dev);
>>   	adc->spi = spi;
>>   
>> -	spi_set_drvdata(spi, indio_dev);
>> -
>>   	indio_dev->name = spi_get_device_id(spi)->name;
>>   	indio_dev->modes = INDIO_DIRECT_MODE;
>>   	indio_dev->info = &adc128_info;
>> @@ -167,23 +170,13 @@ static int adc128_probe(struct spi_device *spi)
>>   	ret = regulator_enable(adc->reg);
>>   	if (ret < 0)
>>   		return ret;
>> +	ret = devm_add_action_or_reset(&spi->dev, adc128_disable_regulator, adc->reg);
>> +	if (ret)
>> +		return ret;
>>   
>>   	mutex_init(&adc->lock);
>>   
>> -	ret = iio_device_register(indio_dev);
>> -
>> -	return ret;
>> -}
>> -
>> -static int adc128_remove(struct spi_device *spi)
>> -{
>> -	struct iio_dev *indio_dev = spi_get_drvdata(spi);
>> -	struct adc128 *adc = iio_priv(indio_dev);
>> -
>> -	iio_device_unregister(indio_dev);
>> -	regulator_disable(adc->reg);
>> -
>> -	return 0;
>> +	return devm_iio_device_register(&spi->dev, indio_dev);
>>   }
>>   
>>   static const struct of_device_id adc128_of_match[] = {
>> @@ -225,7 +218,6 @@ static struct spi_driver adc128_driver = {
>>   		.acpi_match_table = ACPI_PTR(adc128_acpi_match),
>>   	},
>>   	.probe = adc128_probe,
>> -	.remove = adc128_remove,
>>   	.id_table = adc128_id,
>>   };
>>   module_spi_driver(adc128_driver);
> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] iio: adc128s052: Simplify 'adc128_probe()'
  2021-10-13 20:07   ` Christophe JAILLET
@ 2021-10-20 16:42     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2021-10-20 16:42 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: lars, ardeleanalex, andy.shevchenko, linux-iio, linux-kernel,
	kernel-janitors

On Wed, 13 Oct 2021 22:07:25 +0200
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> Le 29/08/2021 à 19:16, Jonathan Cameron a écrit :
> > On Thu, 26 Aug 2021 20:36:22 +0200
> > Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
> >   
> >> Turn 'adc128_probe()' into a full resource managed function to simplify the
> >> code.
> >>
> >> This way, the .remove function can be removed.
> >> Doing so, the only 'spi_get_drvdata()' call is removed and the
> >> corresponding 'spi_set_drvdata()' can be removed as well.
> >>
> >> Suggested-by: Alexandru Ardelean <ardeleanalex@gmail.com>
> >> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> >> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>  
> > Looks good to me, but as mentioned this will need to wait for the
> > fix to go upstream.
> > 
> > Give me a poke if I seem to have lost it once that's true.  
> 
> Hi,
> 
> looks like it's fine now. So this is a gentle reminder :)
> The fix is in -next (see [1])
> 
> CJ
> 
> [1]: 
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/drivers/iio/adc/ti-adc128s052.c

Applied to the togreg branch of iio.git and pushed out as testing for
0-day to see if we missed anything.

Thanks,

Jonathan

> 
> > 
> > Thanks,
> > 
> > Jonathan
> >   
> >> ---
> >> Compile tested only.
> >>
> >> When reviewing, pay special attention to the 'spi_set_drvdata()' call
> >> removal. I recently introduced a regression with a too aggressive cleanup
> >> like that.
> >>
> >> This patch should be applied after
> >> https://lore.kernel.org/linux-iio/f33069f0-601b-4bbb-3766-026f7a161912-39ZsbGIQGT5GWvitb5QawA@public.gmane.org/T/#meb792dcd6540f87d9ae041660ca4738a776e924a
> >>
> >> v1 --> v2: just garbage --> ignore
> >> v1 --> v3: Simplify 'adc128_disable_regulator()'
> >> ---
> >>   drivers/iio/adc/ti-adc128s052.c | 26 +++++++++-----------------
> >>   1 file changed, 9 insertions(+), 17 deletions(-)
> >>
> >> diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
> >> index 3143f35a6509..ce0cfe40b219 100644
> >> --- a/drivers/iio/adc/ti-adc128s052.c
> >> +++ b/drivers/iio/adc/ti-adc128s052.c
> >> @@ -132,6 +132,11 @@ static const struct iio_info adc128_info = {
> >>   	.read_raw = adc128_read_raw,
> >>   };
> >>   
> >> +static void adc128_disable_regulator(void *reg)
> >> +{
> >> +	regulator_disable(reg);
> >> +}
> >> +
> >>   static int adc128_probe(struct spi_device *spi)
> >>   {
> >>   	struct iio_dev *indio_dev;
> >> @@ -151,8 +156,6 @@ static int adc128_probe(struct spi_device *spi)
> >>   	adc = iio_priv(indio_dev);
> >>   	adc->spi = spi;
> >>   
> >> -	spi_set_drvdata(spi, indio_dev);
> >> -
> >>   	indio_dev->name = spi_get_device_id(spi)->name;
> >>   	indio_dev->modes = INDIO_DIRECT_MODE;
> >>   	indio_dev->info = &adc128_info;
> >> @@ -167,23 +170,13 @@ static int adc128_probe(struct spi_device *spi)
> >>   	ret = regulator_enable(adc->reg);
> >>   	if (ret < 0)
> >>   		return ret;
> >> +	ret = devm_add_action_or_reset(&spi->dev, adc128_disable_regulator, adc->reg);
> >> +	if (ret)
> >> +		return ret;
> >>   
> >>   	mutex_init(&adc->lock);
> >>   
> >> -	ret = iio_device_register(indio_dev);
> >> -
> >> -	return ret;
> >> -}
> >> -
> >> -static int adc128_remove(struct spi_device *spi)
> >> -{
> >> -	struct iio_dev *indio_dev = spi_get_drvdata(spi);
> >> -	struct adc128 *adc = iio_priv(indio_dev);
> >> -
> >> -	iio_device_unregister(indio_dev);
> >> -	regulator_disable(adc->reg);
> >> -
> >> -	return 0;
> >> +	return devm_iio_device_register(&spi->dev, indio_dev);
> >>   }
> >>   
> >>   static const struct of_device_id adc128_of_match[] = {
> >> @@ -225,7 +218,6 @@ static struct spi_driver adc128_driver = {
> >>   		.acpi_match_table = ACPI_PTR(adc128_acpi_match),
> >>   	},
> >>   	.probe = adc128_probe,
> >> -	.remove = adc128_remove,
> >>   	.id_table = adc128_id,
> >>   };
> >>   module_spi_driver(adc128_driver);  
> > 
> >   
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-20 16:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26 18:36 [PATCH v3] iio: adc128s052: Simplify 'adc128_probe()' Christophe JAILLET
2021-08-29 17:16 ` Jonathan Cameron
2021-10-13 20:07   ` Christophe JAILLET
2021-10-20 16:42     ` Jonathan Cameron

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).