From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
To: Maxwell Doose <m32285159@gmail.com>, jic23@kernel.org
Cc: "Tomasz Duszynski" <tomasz.duszynski@octakon.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: chemical: scd30: Cleanup initializations in scd30_float_to_fp()
Date: Sat, 09 May 2026 08:13:42 +0530 [thread overview]
Message-ID: <8F49F478-AAA8-4AE8-B6BC-BF3C3923AAD7@gmail.com> (raw)
In-Reply-To: <20260508225501.86448-1-m32285159@gmail.com>
On 9 May 2026 4:25:00 am IST, Maxwell Doose <m32285159@gmail.com> wrote:
>The current variable declaration and initializations are barely readable
>and use comma separations across multiple lines. Refactor the
>initializations so that mantissa and exp have separate declarations and
>sign gets initialized later.
>
>Signed-off-by: Maxwell Doose <m32285159@gmail.com>
>---
> ps:
> Hi Jonathan, I noticed a potential divide-by-zero bug on line 241 in
> scd30_read_raw(), where the value of tmp is dictated by hardware.
> If the scd30_command_read() call on line 236 assigns 0 to tmp, then
> when we run:
> *val2 = 1000000000 / tmp;
> we'll get a divide-by-zero. Will send a patch for this later.
>
> best regards,
> max
>
> drivers/iio/chemical/scd30_core.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
>index a665fcb78806..be8c055be184 100644
>--- a/drivers/iio/chemical/scd30_core.c
>+++ b/drivers/iio/chemical/scd30_core.c
>@@ -89,10 +89,15 @@ static int scd30_reset(struct scd30_state *state)
> /* simplified float to fixed point conversion with a scaling factor of 0.01 */
> static int scd30_float_to_fp(int float32)
> {
>- int fraction, shift,
>- mantissa = float32 & GENMASK(22, 0),
>- sign = (float32 & BIT(31)) ? -1 : 1,
>- exp = (float32 & ~BIT(31)) >> 23;
>+ int fraction, shift, sign;
>+ int mantissa = float32 & GENMASK(22, 0);
>+ int exp = (float32 & ~BIT(31)) >> 23;
>+
>+ /* Determine sign of received float based on IEEE 754 standard */
>+ if (float32 & BIT(31))
>+ sign = -1;
>+ else
>+ sign = 1;
Hi,
Thank you for the refactor change.
The previous version was more compact and readable. Splitting the variable declarations and expanding the sign assignment into an if/else block does not improve clarity significantly.
You can keep it simpler like:
sign = (float32 & BIT(31)) ? -1 : 1;
The IEEE 754 representation is already implicit from the bit manipulation, so additional comment is probably unnecessary.
Thanks, Sanjay
>
> /* special case 0 */
> if (!exp && !mantissa)
>--
>2.54.0
>
next prev parent reply other threads:[~2026-05-09 2:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 22:55 [PATCH] iio: chemical: scd30: Cleanup initializations in scd30_float_to_fp() Maxwell Doose
2026-05-09 2:43 ` Sanjay Chitroda [this message]
2026-05-09 12:27 ` Maxwell Doose
2026-05-10 9:21 ` Andy Shevchenko
2026-05-10 9:15 ` Andy Shevchenko
2026-05-11 12:00 ` Jonathan Cameron
2026-05-11 13:06 ` Maxwell Doose
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=8F49F478-AAA8-4AE8-B6BC-BF3C3923AAD7@gmail.com \
--to=sanjayembeddedse@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m32285159@gmail.com \
--cc=nuno.sa@analog.com \
--cc=tomasz.duszynski@octakon.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