The 'full_scale' attribute currently reports either 9.2 or 2.3, which is not really correct, and doesn't error check the value written, which must be 9.2 or anything else.
The accelerometers are advertised as "2g or 8g". 2.3 and 9.2 are reported as typical maximum values but are not guaranteed. So encoding them in the interface doesn't really make sense. This patch changes the value reported to either 2 [8] or [2] 8 which is commonly used was of reporting both the list of available values, and also the current value. The value written to the attribute must be a number (possibly with a decimal point). Values from 3 up to 9 set the '8g' mode. Values below 3 set the '2g' mode. This makes usage more obvious and more correct. It should not break old applications unless they depended on reading exactly "9.2" - which would be sad. Signed-off-by: NeilBrown <[email protected]> --- drivers/input/misc/lis302dl.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/input/misc/lis302dl.c b/drivers/input/misc/lis302dl.c index f9dfc24..ab6a62b 100644 --- a/drivers/input/misc/lis302dl.c +++ b/drivers/input/misc/lis302dl.c @@ -535,7 +535,7 @@ static ssize_t show_scale(struct device *dev, struct device_attribute *attr, ctrl1 = __reg_read(lis, LIS302DL_REG_CTRL1); local_irq_restore(flags); - return sprintf(buf, "%s\n", ctrl1 & LIS302DL_CTRL1_FS ? "9.2" : "2.3"); + return sprintf(buf, "%s\n", ctrl1 & LIS302DL_CTRL1_FS ? "2 [8]" : "[2] 8"); } static ssize_t set_scale(struct device *dev, struct device_attribute *attr, @@ -543,10 +543,18 @@ static ssize_t set_scale(struct device *dev, struct device_attribute *attr, { struct lis302dl_info *lis = dev_get_drvdata(dev); unsigned long flags; + char *endp; + int val; + + val = simple_strtoul(buf, &endp, 10); + if (endp == buf || (*endp != '.' && *endp != '\n' && *endp != '\0')) + return -EINVAL; + if (val < 2 || val > 9) + return -EINVAL; local_irq_save(flags); - if (!strcmp(buf, "9.2\n")) { + if (val >= 3) { __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS, LIS302DL_CTRL1_FS); lis->flags |= LIS302DL_F_FS;
