From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: rodrigo.alencar@analog.com
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Jonathan Cameron <jic23@kernel.org>,
David Lechner <dlechner@baylibre.com>,
Andy Shevchenko <andy@kernel.org>
Subject: Re: [PATCH RFC v2 3/4] iio: core: use kstrtodec64() to parse fixed-point values
Date: Tue, 13 Oct 2026 22:08:11 +0300 [thread overview]
Message-ID: <as6BmyTrFXggzg3S@ashevche-desk.local> (raw)
In-Reply-To: <20261013-e-notation-v2-3-d4adb5e193fc@analog.com>
On Tue, Oct 13, 2026 at 10:36:46AM -0300, Rodrigo Alencar via B4 Relay wrote:
> Replace the open-coded __iio_str_to_fixpoint() parser with kstrtodec64(),
> so sysfs writes of fixed-point values also accept E notation.
>
> The fractional part only keeps the sign when the integer part is zero,
> as before. The dB suffix for scale attributes is now handled by a separate
> iio_str_to_fixpoint_units() helper. It strips an optional trailing newline
> and the "dB" or " dB" suffix before parsing.
>
> When there is no fractional part (fract_mult == 0, or dec_scale == 0 for
> 64-bit values), try base-autodetecting kstrtoll() first so hexadecimal
> and octal input keeps its meaning ("010" is still 8). Fall back to
> kstrtodec64() on -EINVAL to accept E notation.
>
> As a side effect, inputs that used to be rejected for integer-only
> attributes are now accepted. An invalid octal number such as "08" is
> parsed as decimal 8, and a fractional value such as "1.5" is truncated
> to 1, matching how kstrtodec64() drops digits beyond the requested
> scale.
...
> -int iio_str_to_fixpoint(const char *str, int fract_mult,
> - int *integer, int *fract)
> +int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer,
> + int *fract)
Keep the logical split, id est don't touch these lines, there are no changes.
...
> +static int iio_str_to_fixpoint_units(const char *str, const char *units,
> + int fract_mult, int *integer, int *fract)
> +{
> + size_t units_len = strlen(units);
> + size_t num_len = strlen(str);
> + const char *dec_str = str;
> + char buf[64];
> + if (num_len && str[num_len - 1] == '\n')
> + num_len--;
> + if (num_len > units_len &&
> + !strncmp(str + num_len - units_len, units, units_len)) {
Hmm... We have strends()... Do you expect string to have garbage at the end?
In such a case dB and dBm won't be distinguishable.
> + num_len -= units_len;
> + if (str[num_len - 1] == ' ')
> + num_len--;
> + if (num_len >= sizeof(buf))
> + return -EINVAL;
> + memcpy(buf, str, num_len);
> + buf[num_len] = '\0';
> + dec_str = buf;
> + }
> +
> + return iio_str_to_fixpoint(dec_str, fract_mult, integer, fract);
> +}
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-10-13 19:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 13:36 [PATCH RFC v2 0/4] Add E notation support to kstrtodec64() and IIO sysfs writes Rodrigo Alencar via B4 Relay
2026-10-13 13:36 ` [PATCH RFC v2 1/4] lib: kstrtox: support E notation in kstrtoudec64() and kstrtodec64() Rodrigo Alencar via B4 Relay
2026-10-13 18:48 ` Andy Shevchenko
2026-10-13 13:36 ` [PATCH RFC v2 2/4] lib: test-kstrtox: add E notation tests for kstrto[u]dec64() Rodrigo Alencar via B4 Relay
2026-10-13 18:49 ` Andy Shevchenko
2026-10-13 13:36 ` [PATCH RFC v2 3/4] iio: core: use kstrtodec64() to parse fixed-point values Rodrigo Alencar via B4 Relay
2026-10-13 19:08 ` Andy Shevchenko [this message]
2026-10-13 13:36 ` [PATCH RFC v2 4/4] iio: test: add kunit tests for channel info writes Rodrigo Alencar via B4 Relay
2026-10-13 19:10 ` Andy Shevchenko
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=as6BmyTrFXggzg3S@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=akpm@linux-foundation.org \
--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=rodrigo.alencar@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
all inboxes | Powered by JetHome®