From 58e01af0a21b3e210a10c0029d82df73d09a0f3d Mon Sep 17 00:00:00 2001 From: Jeff LaBundy Date: Thu, 7 Jun 2018 06:44:52 -0500 Subject: [PATCH] misc: cs40l2x: Add bounds checking to click comp. enable control Added a safety check such that all non-zero values written to the comp_enable control are translated to '1' when passed to the DSP. Change-Id: I359def9737eeb8e1f77abdd76ce8d7a3ef069ee5 Signed-off-by: Jeff LaBundy Signed-off-by: Ravi Vembu Mot-CRs-Fixed: (CR) Reviewed-on: https://gerrit.mot.com/1202247 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Submit-Approved: Jira Key --- drivers/misc/cs40l2x.c | 5 +++-- drivers/misc/cs40l2x.h | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/misc/cs40l2x.c b/drivers/misc/cs40l2x.c index 96140c0c08fd..21ba40369c0f 100644 --- a/drivers/misc/cs40l2x.c +++ b/drivers/misc/cs40l2x.c @@ -794,7 +794,7 @@ static ssize_t cs40l2x_comp_enable_show(struct device *dev, mutex_lock(&cs40l2x->lock); ret = regmap_read(cs40l2x->regmap, cs40l2x_dsp_reg(cs40l2x, "COMPENSATION_ENABLE", - CS40L2X_XM_UNPACKED_TYPE), &val); + CS40L2X_XM_UNPACKED_TYPE), &val); mutex_unlock(&cs40l2x->lock); if (ret) { @@ -820,7 +820,8 @@ static ssize_t cs40l2x_comp_enable_store(struct device *dev, mutex_lock(&cs40l2x->lock); ret = regmap_write(cs40l2x->regmap, cs40l2x_dsp_reg(cs40l2x, "COMPENSATION_ENABLE", - CS40L2X_XM_UNPACKED_TYPE), val); + CS40L2X_XM_UNPACKED_TYPE), + val ? CS40L2X_COMP_ENABLED : CS40L2X_COMP_DISABLED); mutex_unlock(&cs40l2x->lock); if (ret) { diff --git a/drivers/misc/cs40l2x.h b/drivers/misc/cs40l2x.h index c9373f839c8c..cff3c62af7a1 100644 --- a/drivers/misc/cs40l2x.h +++ b/drivers/misc/cs40l2x.h @@ -754,6 +754,9 @@ #define CS40L2X_GPIO1_ENABLED 1 #define CS40L2X_GPIO1_DISABLED 0 +#define CS40L2X_COMP_ENABLED 1 +#define CS40L2X_COMP_DISABLED 0 + bool cs40l2x_readable_reg(struct device *dev, unsigned int reg); bool cs40l2x_precious_reg(struct device *dev, unsigned int reg);