2022-08-19 19:31:02

by Matti Vaittinen

[permalink] [raw]
Subject: [PATCH v3 11/14] iio: ad7606: simplify using devm_regulator_get_enable()

Drop open-coded pattern: 'devm_regulator_get(), regulator_enable(),
add_action_or_reset(regulator_disable)' and use the
devm_regulator_get_enable() and drop the pointer to the regulator.
This simplifies code and makes it less tempting to add manual control
for the regulator which is also controlled by devm.

Signed-off-by: Matti Vaittinen <[email protected]>

---
v2 => v3:
New patch
---
drivers/iio/adc/ad7606.c | 22 +++-------------------
drivers/iio/adc/ad7606.h | 1 -
2 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index ba24f99523e0..dd6b603f65ea 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -557,13 +557,6 @@ static const struct iio_trigger_ops ad7606_trigger_ops = {
.validate_device = iio_trigger_validate_own_device,
};

-static void ad7606_regulator_disable(void *data)
-{
- struct ad7606_state *st = data;
-
- regulator_disable(st->reg);
-}
-
int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
const char *name, unsigned int id,
const struct ad7606_bus_ops *bops)
@@ -589,19 +582,10 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
st->scale_avail = ad7606_scale_avail;
st->num_scales = ARRAY_SIZE(ad7606_scale_avail);

- st->reg = devm_regulator_get(dev, "avcc");
- if (IS_ERR(st->reg))
- return PTR_ERR(st->reg);
-
- ret = regulator_enable(st->reg);
- if (ret) {
- dev_err(dev, "Failed to enable specified AVcc supply\n");
- return ret;
- }
-
- ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
+ ret = devm_regulator_get_enable(dev, "avcc");
if (ret)
- return ret;
+ return dev_err_probe(dev, ret,
+ "Failed to enable specified AVcc supply\n");

st->chip_info = &ad7606_chip_info_tbl[id];

diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index 2dc4f599f9df..924a2d1a6d94 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -92,7 +92,6 @@ struct ad7606_chip_info {
struct ad7606_state {
struct device *dev;
const struct ad7606_chip_info *chip_info;
- struct regulator *reg;
const struct ad7606_bus_ops *bops;
unsigned int range[16];
unsigned int oversampling;
--
2.37.1


--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =]


Attachments:
(No filename) (2.60 kB)
signature.asc (499.00 B)
Download all attachments

2022-08-30 12:29:46

by Nuno Sa

[permalink] [raw]
Subject: RE: [PATCH v3 11/14] iio: ad7606: simplify using devm_regulator_get_enable()

> From: Matti Vaittinen <[email protected]>
> Sent: Friday, August 19, 2022 9:20 PM
> To: Matti Vaittinen <[email protected]>; Matti Vaittinen
> <[email protected]>
> Cc: Lars-Peter Clausen <[email protected]>; Hennerich, Michael
> <[email protected]>; Jonathan Cameron
> <[email protected]>; [email protected]; linux-
> [email protected]
> Subject: [PATCH v3 11/14] iio: ad7606: simplify using
> devm_regulator_get_enable()
>
> [External]
>
> Drop open-coded pattern: 'devm_regulator_get(), regulator_enable(),
> add_action_or_reset(regulator_disable)' and use the
> devm_regulator_get_enable() and drop the pointer to the regulator.
> This simplifies code and makes it less tempting to add manual control
> for the regulator which is also controlled by devm.
>
> Signed-off-by: Matti Vaittinen <[email protected]>
>
> ---

The commit message could state that while doing the change, dev_err_probe()
was also introduced. Bah, anyways:

Acked-by: Nuno S? <[email protected]>

2022-08-30 13:40:05

by Matti Vaittinen

[permalink] [raw]
Subject: Re: [PATCH v3 11/14] iio: ad7606: simplify using devm_regulator_get_enable()

Thanks for the review(s) Nuno!

On 8/30/22 14:46, Sa, Nuno wrote:
>> From: Matti Vaittinen <[email protected]>
>> Sent: Friday, August 19, 2022 9:20 PM
>> To: Matti Vaittinen <[email protected]>; Matti Vaittinen
>> <[email protected]>
>> Cc: Lars-Peter Clausen <[email protected]>; Hennerich, Michael
>> <[email protected]>; Jonathan Cameron
>> <[email protected]>; [email protected]; linux-
>> [email protected]
>> Subject: [PATCH v3 11/14] iio: ad7606: simplify using
>> devm_regulator_get_enable()
>>
>> [External]
>>
>> Drop open-coded pattern: 'devm_regulator_get(), regulator_enable(),
>> add_action_or_reset(regulator_disable)' and use the
>> devm_regulator_get_enable() and drop the pointer to the regulator.
>> This simplifies code and makes it less tempting to add manual control
>> for the regulator which is also controlled by devm.
>>
>> Signed-off-by: Matti Vaittinen <[email protected]>
>>
>> ---
>
> The commit message could state that while doing the change, dev_err_probe()
> was also introduced. Bah, anyways:
>
> Acked-by: Nuno Sá <[email protected]>

Good point. I have few other changes to the series pending - and I
probably need to rebase/respin when -rc1 is out (and dependency patches
are merged from Mark's tree) => I may as well alter the commit message.

Yours,
-- Matti

--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~

2022-10-16 16:34:29

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 11/14] iio: ad7606: simplify using devm_regulator_get_enable()

On Tue, 30 Aug 2022 15:54:07 +0300
Matti Vaittinen <[email protected]> wrote:

> Thanks for the review(s) Nuno!
>
> On 8/30/22 14:46, Sa, Nuno wrote:
> >> From: Matti Vaittinen <[email protected]>
> >> Sent: Friday, August 19, 2022 9:20 PM
> >> To: Matti Vaittinen <[email protected]>; Matti Vaittinen
> >> <[email protected]>
> >> Cc: Lars-Peter Clausen <[email protected]>; Hennerich, Michael
> >> <[email protected]>; Jonathan Cameron
> >> <[email protected]>; [email protected]; linux-
> >> [email protected]
> >> Subject: [PATCH v3 11/14] iio: ad7606: simplify using
> >> devm_regulator_get_enable()
> >>
> >> [External]
> >>
> >> Drop open-coded pattern: 'devm_regulator_get(), regulator_enable(),
> >> add_action_or_reset(regulator_disable)' and use the
> >> devm_regulator_get_enable() and drop the pointer to the regulator.
> >> This simplifies code and makes it less tempting to add manual control
> >> for the regulator which is also controlled by devm.
> >>
> >> Signed-off-by: Matti Vaittinen <[email protected]>
> >>
> >> ---
> >
> > The commit message could state that while doing the change, dev_err_probe()
> > was also introduced. Bah, anyways:
> >
> > Acked-by: Nuno Sá <[email protected]>
>
> Good point. I have few other changes to the series pending - and I
> probably need to rebase/respin when -rc1 is out (and dependency patches
> are merged from Mark's tree) => I may as well alter the commit message.
>
I tweaked it and applied.

Not I'm grabbing these early because I forgot you'd sent them and
found myself writing the same patches. Memory of a goldfish :)

Jonathan

> Yours,
> -- Matti
>

2022-10-16 16:36:46

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 11/14] iio: ad7606: simplify using devm_regulator_get_enable()

On Sun, 16 Oct 2022 17:15:29 +0100
Jonathan Cameron <[email protected]> wrote:

> On Tue, 30 Aug 2022 15:54:07 +0300
> Matti Vaittinen <[email protected]> wrote:
>
> > Thanks for the review(s) Nuno!
> >
> > On 8/30/22 14:46, Sa, Nuno wrote:
> > >> From: Matti Vaittinen <[email protected]>
> > >> Sent: Friday, August 19, 2022 9:20 PM
> > >> To: Matti Vaittinen <[email protected]>; Matti Vaittinen
> > >> <[email protected]>
> > >> Cc: Lars-Peter Clausen <[email protected]>; Hennerich, Michael
> > >> <[email protected]>; Jonathan Cameron
> > >> <[email protected]>; [email protected]; linux-
> > >> [email protected]
> > >> Subject: [PATCH v3 11/14] iio: ad7606: simplify using
> > >> devm_regulator_get_enable()
> > >>
> > >> [External]
> > >>
> > >> Drop open-coded pattern: 'devm_regulator_get(), regulator_enable(),
> > >> add_action_or_reset(regulator_disable)' and use the
> > >> devm_regulator_get_enable() and drop the pointer to the regulator.
> > >> This simplifies code and makes it less tempting to add manual control
> > >> for the regulator which is also controlled by devm.
> > >>
> > >> Signed-off-by: Matti Vaittinen <[email protected]>
> > >>
> > >> ---
> > >
> > > The commit message could state that while doing the change, dev_err_probe()
> > > was also introduced. Bah, anyways:
> > >
> > > Acked-by: Nuno Sá <[email protected]>
> >
> > Good point. I have few other changes to the series pending - and I
> > probably need to rebase/respin when -rc1 is out (and dependency patches
> > are merged from Mark's tree) => I may as well alter the commit message.
> >
> I tweaked it and applied.
>
> Not I'm grabbing these early because I forgot you'd sent them and
> found myself writing the same patches. Memory of a goldfish :)

Tweaked a little more - you missed that the struct in the header had
kernel-doc for the struct regulator *. Dropped that.

>
> Jonathan
>
> > Yours,
> > -- Matti
> >
>

2022-10-17 04:38:19

by Matti Vaittinen

[permalink] [raw]
Subject: Re: [PATCH v3 11/14] iio: ad7606: simplify using devm_regulator_get_enable()

On 10/16/22 19:24, Jonathan Cameron wrote:
> On Sun, 16 Oct 2022 17:15:29 +0100
> Jonathan Cameron <[email protected]> wrote:
>
>> On Tue, 30 Aug 2022 15:54:07 +0300
>> Matti Vaittinen <[email protected]> wrote:
>>
>>> Thanks for the review(s) Nuno!
>>>
>>> On 8/30/22 14:46, Sa, Nuno wrote:
>>>>> From: Matti Vaittinen <[email protected]>
>>>>> Sent: Friday, August 19, 2022 9:20 PM
>>>>> To: Matti Vaittinen <[email protected]>; Matti Vaittinen
>>>>> <[email protected]>
>>>>> Cc: Lars-Peter Clausen <[email protected]>; Hennerich, Michael
>>>>> <[email protected]>; Jonathan Cameron
>>>>> <[email protected]>; [email protected]; linux-
>>>>> [email protected]
>>>>> Subject: [PATCH v3 11/14] iio: ad7606: simplify using
>>>>> devm_regulator_get_enable()
>>>>>
>>>>> [External]
>>>>>
>>>>> Drop open-coded pattern: 'devm_regulator_get(), regulator_enable(),
>>>>> add_action_or_reset(regulator_disable)' and use the
>>>>> devm_regulator_get_enable() and drop the pointer to the regulator.
>>>>> This simplifies code and makes it less tempting to add manual control
>>>>> for the regulator which is also controlled by devm.
>>>>>
>>>>> Signed-off-by: Matti Vaittinen <[email protected]>
>>>>>
>>>>> ---
>>>>
>>>> The commit message could state that while doing the change, dev_err_probe()
>>>> was also introduced. Bah, anyways:
>>>>
>>>> Acked-by: Nuno Sá <[email protected]>
>>>
>>> Good point. I have few other changes to the series pending - and I
>>> probably need to rebase/respin when -rc1 is out (and dependency patches
>>> are merged from Mark's tree) => I may as well alter the commit message.
>>>
>> I tweaked it and applied.
>>
>> Not I'm grabbing these early because I forgot you'd sent them and
>> found myself writing the same patches. Memory of a goldfish :)
>
> Tweaked a little more - you missed that the struct in the header had
> kernel-doc for the struct regulator *. Dropped that.

Thanks a bunch!

Yours,
Matti

--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~