From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Vineet Thakran <vineet789thakran@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
linux-iio@vger.kernel.org, "Kevin Tsai" <ktsai@capellamicro.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH 3/3] iio: light: cm3232: reject invalid calibscale values
Date: Fri, 4 Dec 2026 18:44:53 +0200 [thread overview]
Message-ID: <axLuBS0P8HsCfm82@ashevche-desk.local> (raw)
In-Reply-To: <20261203165254.135545-4-vineet789thakran@gmail.com>
On Thu, Dec 03, 2026 at 04:52:54PM +0000, Vineet Thakran wrote:
> cm3232_write_raw() stores any value written to in_illuminance_calibscale
> and ignores the fractional part. A value of zero makes every lux reading
> zero. A negative value is converted to a large u64 when cm3232_get_lux()
> multiplies by it, so every non-zero reading is clamped to 0xffff. A
> fractional value such as 1.5 is silently truncated.
>
> Accept only positive integers and return -EINVAL for anything else. No
> upper bound is needed: the largest product in cm3232_get_lux(), with the
> shortest integration time, a full-scale ALS count and INT_MAX as
> calibscale, still fits in a u64.
...
> switch (mask) {
> case IIO_CHAN_INFO_CALIBSCALE:
> + if (val <= 0 || val2)
It's better to use clear comparisons
if (val < 0 || val == 0 || val2 > 0)
(I'm in doubts of splitting <= 0, but let compiler to optimize that anyway).
> + return -EINVAL;
> chip->calibscale = val;
> return 0;
> case IIO_CHAN_INFO_INT_TIME:
> --
> 2.43.0
>
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-12-04 16:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 16:52 [PATCH 0/3] iio: light: cm3232: fix remove ordering, locking and calibscale validation Vineet Thakran
2026-12-03 16:52 ` [PATCH 1/3] iio: light: cm3232: unregister the device before powering it down Vineet Thakran
2026-12-04 6:59 ` Joshua Crofts
2026-12-03 16:52 ` [PATCH 2/3] iio: light: cm3232: serialize access to the cached command register Vineet Thakran
2026-12-03 16:52 ` [PATCH 3/3] iio: light: cm3232: reject invalid calibscale values Vineet Thakran
2026-12-04 6:58 ` Joshua Crofts
2026-12-04 16:44 ` Andy Shevchenko [this message]
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=axLuBS0P8HsCfm82@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=ktsai@capellamicro.com \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=stable@vger.kernel.org \
--cc=vineet789thakran@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.