From: Gwendal Grignou <gwendal@chromium.org>
To: jic23@kernel.org, lars@metafoo.de, swboyd@chromium.org,
campello@chromium.org, andy.shevchenko@gmail.com
Cc: linux-iio@vger.kernel.org, Gwendal Grignou <gwendal@chromium.org>,
stable@vger.kernel.org
Subject: [PATCH] iio: sx9310: Fix write_.._debounce()
Date: Wed, 31 Mar 2021 11:22:22 -0700 [thread overview]
Message-ID: <20210331182222.219533-1-gwendal@chromium.org> (raw)
Check input to be sure it matches Semtech sx9310 specification and
can fit into debounce register.
Compare argument writen to thresh_.._period with read from same
sysfs attribute:
Before: Afer:
write | read write | read
-1 | 8 -1 fails: -EINVAL
0 | 8 0 | 0
1 | 0 1 | 0
2..15 | 2^log2(N) 2..15 | 2^log2(N)
16 | 0 >= 16 fails: -EINVAL
Fixes: 1b6872015f0b ("iio: sx9310: Support setting debounce values")
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Cc: stable@vger.kernel.org
---
drivers/iio/proximity/sx9310.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index 578d8841c5398..e5a756f4afa2b 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -764,7 +764,11 @@ static int sx9310_write_far_debounce(struct sx9310_data *data, int val)
int ret;
unsigned int regval;
- val = ilog2(val);
+ if (val > 0)
+ val = ilog2(val);
+ if (!FIELD_FIT(SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_MASK, val))
+ return -EINVAL;
+
regval = FIELD_PREP(SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_MASK, val);
mutex_lock(&data->mutex);
@@ -781,7 +785,11 @@ static int sx9310_write_close_debounce(struct sx9310_data *data, int val)
int ret;
unsigned int regval;
- val = ilog2(val);
+ if (val > 0)
+ val = ilog2(val);
+ if (!FIELD_FIT(SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_MASK, val))
+ return -EINVAL;
+
regval = FIELD_PREP(SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_MASK, val);
mutex_lock(&data->mutex);
--
2.31.0.291.g576ba9dcdaf-goog
next reply other threads:[~2021-03-31 18:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-31 18:22 Gwendal Grignou [this message]
2021-03-31 19:49 ` [PATCH] iio: sx9310: Fix write_.._debounce() Stephen Boyd
2021-04-01 13:21 ` 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=20210331182222.219533-1-gwendal@chromium.org \
--to=gwendal@chromium.org \
--cc=andy.shevchenko@gmail.com \
--cc=campello@chromium.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=swboyd@chromium.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