misc: cs40l2x: Add bounds checking to timeout controls

Added a safety check to ensure that the values written to the
gpio1_fall_timeout and standby_timeout controls do not exceed the
maximum value supported by the DSP.

Change-Id: I8b5dca1f5013acb2d06688af577d0214ce956559
Signed-off-by: Jeff LaBundy <jeff.labundy@cirrus.com>
Signed-off-by: Ravi Vembu <raviv@motorola.com>
This commit is contained in:
Jeff LaBundy 2018-06-01 08:43:47 -05:00 • committed by a7301c
commit cd5ebc4a19
2 changed files with 9 additions and 0 deletions

View file

@ -523,6 +523,9 @@ static ssize_t cs40l2x_gpio1_fall_timeout_store(struct device *dev,
if (ret)
return -EINVAL;
if (val > CS40L2X_PR_TIMEOUT_MAX)
return -EINVAL;
mutex_lock(&cs40l2x->lock);
ret = regmap_write(cs40l2x->regmap,
cs40l2x_dsp_reg(cs40l2x, "PRESS_RELEASE_TIMEOUT",
@ -570,6 +573,9 @@ static ssize_t cs40l2x_standby_timeout_store(struct device *dev,
if (ret)
return -EINVAL;
if (val > CS40L2X_EVENT_TIMEOUT_MAX)
return -EINVAL;
mutex_lock(&cs40l2x->lock);
ret = regmap_write(cs40l2x->regmap,
cs40l2x_dsp_reg(cs40l2x, "EVENT_TIMEOUT",

View file

@ -680,6 +680,9 @@
#define CS40L2X_COEFF_LENGTH_SIZE 4
#define CS40L2X_TIMEOUT_MS_MAX 0x02AAAA /* ~174 sec */
#define CS40L2X_PR_TIMEOUT_MAX 0x7FFFFF
#define CS40L2X_EVENT_TIMEOUT_MAX CS40L2X_PR_TIMEOUT_MAX
#define CS40L2X_HALO_STATE_RUNNING 0x2
#define CS40L2X_STATUS_IDLE 0xFFFFFF