From: Onur Atilla <oati...@gmail.com> Sensor compensation factor input from the platform is being checked now before use.
Signed-off-by: Onur Atilla <oati...@gmail.com> Signed-off-by: Andi Shyti <a...@etezian.org> --- drivers/misc/bh1770glc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/misc/bh1770glc.c b/drivers/misc/bh1770glc.c index cb63c25..383cefe 100644 --- a/drivers/misc/bh1770glc.c +++ b/drivers/misc/bh1770glc.c @@ -123,6 +123,7 @@ #define BH1770_LUX_GA_SCALE 8192 #define BH1770_LUX_CF_SCALE 8192 /* CF ChipFactor */ #define BH1770_NEUTRAL_CF BH1770_LUX_CF_SCALE +#define BH1770_LUX_MAX_CF (10 * BH1770_NEUTRAL_CF) #define BH1770_LUX_CORR_SCALE 4096 #define PROX_ABOVE_THRESHOLD 1 @@ -550,7 +551,11 @@ static int bh1770_detect(struct bh1770_chip *chip) if ((manu == BH1770_MANUFACT_ROHM) && ((part & BH1770_PART_MASK) == BH1770_PART)) { snprintf(chip->chipname, sizeof(chip->chipname), "BH1770GLC"); - chip->lux_cf = chip->pdata->als_scf_BH1770; + + /* apply sensor compensation factor only after verifying it */ + if ((chip->pdata->als_scf_BH1770 > 0) && + (chip->pdata->als_scf_BH1770 < BH1770_LUX_MAX_CF)) + chip->lux_cf = chip->pdata->als_scf_BH1770; /* apply minimum threshold value only after verifying it */ if ((chip->pdata->prox_min_thresh_BH1770 > 0) && @@ -565,7 +570,11 @@ static int bh1770_detect(struct bh1770_chip *chip) if ((manu == BH1770_MANUFACT_OSRAM) && ((part & BH1770_PART_MASK) == BH1770_PART)) { snprintf(chip->chipname, sizeof(chip->chipname), "SFH7770"); - chip->lux_cf = chip->pdata->als_scf_SFH7770; + + /* apply sensor compensation factor only after verifying it */ + if ((chip->pdata->als_scf_SFH7770 > 0) && + (chip->pdata->als_scf_SFH7770 < BH1770_LUX_MAX_CF)) + chip->lux_cf = chip->pdata->als_scf_SFH7770; /* apply minimum threshold value only after verifying it */ if ((chip->pdata->prox_min_thresh_SFH7770 > 0) && -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/