From: David Lechner <dlechner@baylibre.com>
To: "Paller, Kim Seer" <KimSeer.Paller@analog.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Dimitri Fedrau" <dima.fedrau@gmail.com>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Hennerich, Michael" <Michael.Hennerich@analog.com>,
"Nuno Sá" <noname.nuno@gmail.com>,
"kernel test robot" <lkp@intel.com>
Subject: Re: [PATCH v3 5/5] iio: dac: ltc2664: Add driver for LTC2664 and LTC2672
Date: Tue, 18 Jun 2024 08:42:31 -0500 [thread overview]
Message-ID: <edc38640-42ee-4bde-bc95-500498b5a461@baylibre.com> (raw)
In-Reply-To: <PH0PR03MB714164FC9335DFBC003E4F57F9CE2@PH0PR03MB7141.namprd03.prod.outlook.com>
On 6/18/24 5:32 AM, Paller, Kim Seer wrote:
>
>
>>> +}
>>> +
>>> +static int ltc2672_scale_get(const struct ltc2664_state *st, int c)
>>> +{
>>> + const struct ltc2664_chan *chan = &st->channels[c];
>>> + int span, fs;
>>> +
>>> + span = chan->span;
>>> + if (span < 0)
>>> + return span;
>>> +
>>> + fs = 1000 * st->vref / st->rfsadj;
>>> +
>>> + if (span == LTC2672_MAX_SPAN)
>>> + return 4800 * fs;
>>> +
>>> + return LTC2672_SCALE_MULTIPLIER(span) * fs;
>>
>> Are we losing accuracy by multiplying after dividing here as well?
>
> Hi,
>
> In the case of max span for ltc2672, I found that performing multiplication
> before division causes an integer overflow during testing. I was wondering
> how the upstream handles this case. Could you provide some advice?
>
> Thanks,
> Kim
>
>
In cases like this, we usually do 64-bit multiplication to avoid the
overflow. There are helper functions for this sort of thing in
linux/math64.h.
For example, if LTC2672_SCALE_MULTIPLIER(span) is unsigned, you
could probably do something like this:
mul_u64_u32_div(LTC2672_SCALE_MULTIPLIER(span), 1000 * st->vref, st->rfsadj);
next prev parent reply other threads:[~2024-06-18 13:42 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-03 1:21 [PATCH v3 0/5] Add driver for LTC2664 and LTC2672 Kim Seer Paller
2024-06-03 1:21 ` [PATCH v3 1/5] iio: ABI: Generalize ABI documentation for DAC Kim Seer Paller
2024-06-08 14:40 ` Jonathan Cameron
2024-06-12 10:57 ` Paller, Kim Seer
2024-06-13 17:00 ` Jonathan Cameron
2024-06-03 1:21 ` [PATCH v3 2/5] iio: ABI: add DAC 42kohm_to_gnd powerdown mode Kim Seer Paller
2024-06-03 1:21 ` [PATCH v3 3/5] dt-bindings: iio: dac: Add adi,ltc2664.yaml Kim Seer Paller
2024-06-03 7:02 ` Krzysztof Kozlowski
2024-06-03 1:21 ` [PATCH v3 4/5] dt-bindings: iio: dac: Add adi,ltc2672.yaml Kim Seer Paller
2024-06-03 7:05 ` Krzysztof Kozlowski
2024-06-03 19:59 ` David Lechner
2024-06-03 20:17 ` David Lechner
2024-06-04 6:47 ` Krzysztof Kozlowski
2024-06-04 13:53 ` David Lechner
2024-06-08 14:32 ` Jonathan Cameron
2024-06-03 1:22 ` [PATCH v3 5/5] iio: dac: ltc2664: Add driver for LTC2664 and LTC2672 Kim Seer Paller
2024-06-03 13:12 ` Nuno Sá
2024-06-03 20:43 ` David Lechner
2024-06-06 15:49 ` Paller, Kim Seer
2024-06-07 19:13 ` David Lechner
2024-06-18 10:32 ` Paller, Kim Seer
2024-06-18 13:42 ` David Lechner [this message]
2024-06-08 14:57 ` Jonathan Cameron
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=edc38640-42ee-4bde-bc95-500498b5a461@baylibre.com \
--to=dlechner@baylibre.com \
--cc=KimSeer.Paller@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dima.fedrau@gmail.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=noname.nuno@gmail.com \
--cc=robh@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