public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Alisa-Dariana Roman <alisadariana@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"Marcelo Schmitt" <marcelo.schmitt1@gmail.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/5] iio: adc: ad7192: use devm_regulator_get_enable_read_voltage
Date: Mon, 17 Jun 2024 15:00:34 -0500	[thread overview]
Message-ID: <4ff58005-4a71-491f-9400-cdecf2c25d66@baylibre.com> (raw)
In-Reply-To: <bbc2f159-d673-4652-a6b9-a528f905b67c@gmail.com>

On 6/17/24 11:01 AM, Alisa-Dariana Roman wrote:
> On 17.06.2024 18:28, David Lechner wrote:
>> On Mon, Jun 17, 2024 at 9:10 AM Alisa-Dariana Roman
>> <alisadariana@gmail.com> wrote:
>>>
>>> On 17.06.2024 16:48, David Lechner wrote:
>>>> On 6/17/24 8:38 AM, Alisa-Dariana Roman wrote:
>>>>> On 17.06.2024 16:22, David Lechner wrote:
>>>>>> On Mon, Jun 17, 2024 at 4:35 AM Alisa-Dariana Roman
>>>>>> <alisadariana@gmail.com> wrote:
>>>>>>>
>>>>>>> On 15.06.2024 15:08, Jonathan Cameron wrote:
>>>>>>>> On Wed, 12 Jun 2024 16:03:05 -0500
>>>>>>>> David Lechner <dlechner@baylibre.com> wrote:
>>>>>>>>
>>>>>>>>> This makes use of the new devm_regulator_get_enable_read_voltage()
>>>>>>>>> function to reduce boilerplate code.
>>>>>>>>>
>>>>>>>>> Error messages have changed slightly since there are now fewer places
>>>>>>>>> where we print an error. The rest of the logic of selecting which
>>>>>>>>> supply to use as the reference voltage remains the same.
>>>>>>>>>
>>>>>>>>> Also 1000 is replaced by MILLI in a few places for consistency.
>>>>>>>>>
>>>>>>>>> Signed-off-by: David Lechner <dlechner@baylibre.com>
>>>>>>>>
>>>>>>>> Complicated bit of code, but seems correct.
>>>>>>>> However, it crossed with Alisa-Dariana switching adding a
>>>>>>>> struct device *dev = &spi->dev to probe() that I picked up earlier
>>>>>>>> today.
>>>>>>>>
>>>>>>>> I could unwind that but given Alisa-Dariana has a number of
>>>>>>>> other patches on this driver in flight, I'd like the two of you
>>>>>>>> to work out the best resolution between you.  Maybe easiest option
>>>>>>>> is that Alisa-Dariana sends this a first patch of the next
>>>>>>>> series I should pick up.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> Jonathan
>>>>>>> I will add this patch to my series and send it shortly.
>>>>>>>
>>>>>>> Kind regards,
>>>>>>> Alisa-Dariana Roman.
>>>>>>
>>>>>> Great, thanks!
>>>>>
>>>>> Just one quick question:
>>>>>
>>>>> I am getting two such warnings when running the checkpatch script:
>>>>>
>>>>> WARNING: else is not generally useful after a break or return
>>>>> #1335: FILE: ./drivers/iio/adc/ad7192.c:1335:
>>>>> +        return dev_err_probe(dev, ret, "Failed to get AVDD voltage\n");
>>>>> +    } else {
>>>>>
>>>>> Should I switch the last two branches to get rid of the warnings or just ignore them?
>>>>>
>>>>
>>>> In the other patches, I was able to reorder things to avoid this
>>>> warning, but since this one was more complicated, I just ignored
>>>> this warning.
>>>>
>>>> We can't just remove the else in this case because the return
>>>> is inside of an `else if`.
>>>
>>>          /* AVDD can optionally be used as reference voltage */
>>>          ret = devm_regulator_get_enable_read_voltage(dev, "avdd");
>>>          if (ret == -ENODEV || ret == -EINVAL) {
>>>                  /*
>>>                   * We get -EINVAL if avdd is a supply with unknown voltage. We
>>>                   * still need to enable it since it is also a power supply.
>>>                   */
>>>                  ret = devm_regulator_get_enable(dev, "avdd");
>>>                  if (ret)
>>>                          return dev_err_probe(dev, ret,
>>>                                               "Failed to enable AVDD supply\n");
>>>
>>>                  avdd_mv = 0;
>>>          } else if (ret >= 0) {
>>>                  avdd_mv = ret / MILLI;
>>>          } else {
>>>                  return dev_err_probe(dev, ret, "Failed to get AVDD voltage\n");
>>>          }
>>>
>>> Would switching the last two branches, in order to get rid of the
>>> warnings, make the code harder to understand?
>>>
>>
>> I did it in the other order because usually we like to handle the
>> error case first.
>>
>> To make it more like the other patches, we could do something like
>> this. The only thing i don't like about it is that `ret` on the very
>> last line could come from two different places. But it is logically
>> sound in the current form.
>>
>>      /* AVDD can optionally be used as reference voltage */
>>      ret = devm_regulator_get_enable_read_voltage(dev, "avdd");
>>      if (ret == -ENODEV || ret == -EINVAL) {
>>          /*
>>           * We get -EINVAL if avdd is a supply with unknown voltage. We
>>           * still need to enable it since it is also a power supply.
>>           */
>>          ret = devm_regulator_get_enable(dev, "avdd");
>>          if (ret)
>>              return dev_err_probe(dev, ret,
>>                           "Failed to enable AVDD supply\n");
>>      } else if (ret < 0) {
>>          return dev_err_probe(dev, ret, "Failed to get AVDD voltage\n");
>>      }
>>
>>      avdd_mv = ret <= 0 ? 0 : ret / MILLI;
> 
> Maybe this would make it a bit clearer, but yes, the ret == 0 could still come from two different places :(.
> 
> avdd_mv = ret == 0 ? 0 : ret / MILLI;
> 

We could make a ret2 local variable inside of the if block to avoid writing over ret.


  reply	other threads:[~2024-06-17 20:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-12 21:03 [PATCH v2 0/5] iio: adc: use devm_regulator_get_enable_read_voltage round 1 David Lechner
2024-06-12 21:03 ` [PATCH v2 1/5] iio: adc: ad7192: use devm_regulator_get_enable_read_voltage David Lechner
2024-06-15 12:08   ` Jonathan Cameron
2024-06-17  9:35     ` Alisa-Dariana Roman
2024-06-17 13:22       ` David Lechner
2024-06-17 13:38         ` Alisa-Dariana Roman
2024-06-17 13:48           ` David Lechner
2024-06-17 14:10             ` Alisa-Dariana Roman
2024-06-17 15:28               ` David Lechner
2024-06-17 16:01                 ` Alisa-Dariana Roman
2024-06-17 20:00                   ` David Lechner [this message]
2024-06-18  9:45                     ` Alisa-Dariana Roman
2024-06-18 13:30                       ` David Lechner
2024-06-12 21:03 ` [PATCH v2 2/5] iio: adc: ad7266: " David Lechner
2024-06-15 12:12   ` Jonathan Cameron
2024-06-12 21:03 ` [PATCH v2 3/5] iio: adc: ad7292: " David Lechner
2024-06-14 15:11   ` Nuno Sá
2024-06-14 15:16     ` David Lechner
2024-06-15 12:14       ` Jonathan Cameron
2024-06-12 21:03 ` [PATCH v2 4/5] iio: adc: ad7793: " David Lechner
2024-06-15 12:15   ` Jonathan Cameron
2024-06-12 21:03 ` [PATCH v2 5/5] iio: adc: ad7944: " David Lechner
2024-06-14 15:16   ` Nuno Sá
2024-06-14 15:19     ` David Lechner
2024-06-15 12:18       ` Jonathan Cameron
2024-06-14 15:18 ` [PATCH v2 0/5] iio: adc: use devm_regulator_get_enable_read_voltage round 1 Nuno Sá

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=4ff58005-4a71-491f-9400-cdecf2c25d66@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=alisadariana@gmail.com \
    --cc=broonie@kernel.org \
    --cc=jic23@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=nuno.sa@analog.com \
    /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