Input: convert drivers to use strict_strtoul()
strict_strtoul() allows newline character at the end of the the input string and therefore is more user-friendly. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
82a196f481
commit
160f1fef7e
@ -1207,15 +1207,13 @@ static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t coun
|
|||||||
{
|
{
|
||||||
struct input_dev *old_dev, *new_dev;
|
struct input_dev *old_dev, *new_dev;
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
int err;
|
int err;
|
||||||
unsigned char old_extra, old_set;
|
unsigned char old_extra, old_set;
|
||||||
|
|
||||||
if (!atkbd->write)
|
if (!atkbd->write)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value) || value > 1)
|
||||||
if (*rest || value > 1)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (atkbd->extra != value) {
|
if (atkbd->extra != value) {
|
||||||
@ -1264,12 +1262,10 @@ static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t cou
|
|||||||
{
|
{
|
||||||
struct input_dev *old_dev, *new_dev;
|
struct input_dev *old_dev, *new_dev;
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
int err;
|
int err;
|
||||||
unsigned char old_scroll;
|
unsigned char old_scroll;
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value) || value > 1)
|
||||||
if (*rest || value > 1)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (atkbd->scroll != value) {
|
if (atkbd->scroll != value) {
|
||||||
@ -1310,15 +1306,13 @@ static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
|
|||||||
{
|
{
|
||||||
struct input_dev *old_dev, *new_dev;
|
struct input_dev *old_dev, *new_dev;
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
int err;
|
int err;
|
||||||
unsigned char old_set, old_extra;
|
unsigned char old_set, old_extra;
|
||||||
|
|
||||||
if (!atkbd->write)
|
if (!atkbd->write)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value) || (value != 2 && value != 3))
|
||||||
if (*rest || (value != 2 && value != 3))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (atkbd->set != value) {
|
if (atkbd->set != value) {
|
||||||
@ -1361,15 +1355,13 @@ static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t
|
|||||||
{
|
{
|
||||||
struct input_dev *old_dev, *new_dev;
|
struct input_dev *old_dev, *new_dev;
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
int err;
|
int err;
|
||||||
unsigned char old_softrepeat, old_softraw;
|
unsigned char old_softrepeat, old_softraw;
|
||||||
|
|
||||||
if (!atkbd->write)
|
if (!atkbd->write)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value) || value > 1)
|
||||||
if (*rest || value > 1)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (atkbd->softrepeat != value) {
|
if (atkbd->softrepeat != value) {
|
||||||
@ -1413,12 +1405,10 @@ static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t co
|
|||||||
{
|
{
|
||||||
struct input_dev *old_dev, *new_dev;
|
struct input_dev *old_dev, *new_dev;
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
int err;
|
int err;
|
||||||
unsigned char old_softraw;
|
unsigned char old_softraw;
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value) || value > 1)
|
||||||
if (*rest || value > 1)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (atkbd->softraw != value) {
|
if (atkbd->softraw != value) {
|
||||||
|
@ -157,10 +157,8 @@ static ssize_t ps2pp_attr_show_smartscroll(struct psmouse *psmouse, void *data,
|
|||||||
static ssize_t ps2pp_attr_set_smartscroll(struct psmouse *psmouse, void *data, const char *buf, size_t count)
|
static ssize_t ps2pp_attr_set_smartscroll(struct psmouse *psmouse, void *data, const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value) || value > 1)
|
||||||
if (*rest || value > 1)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ps2pp_set_smartscroll(psmouse, value);
|
ps2pp_set_smartscroll(psmouse, value);
|
||||||
|
@ -1433,10 +1433,8 @@ static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const
|
|||||||
{
|
{
|
||||||
unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
|
unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value))
|
||||||
if (*rest)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if ((unsigned int)value != value)
|
if ((unsigned int)value != value)
|
||||||
@ -1549,10 +1547,8 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
|
|||||||
static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
|
static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value))
|
||||||
if (*rest)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
psmouse->set_rate(psmouse, value);
|
psmouse->set_rate(psmouse, value);
|
||||||
@ -1562,10 +1558,8 @@ static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const
|
|||||||
static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
|
static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value))
|
||||||
if (*rest)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
psmouse->set_resolution(psmouse, value);
|
psmouse->set_resolution(psmouse, value);
|
||||||
|
@ -89,10 +89,8 @@ static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data,
|
|||||||
struct trackpoint_attr_data *attr = data;
|
struct trackpoint_attr_data *attr = data;
|
||||||
unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
|
unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value) || value > 255)
|
||||||
if (*rest || value > 255)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
*field = value;
|
*field = value;
|
||||||
@ -117,10 +115,8 @@ static ssize_t trackpoint_set_bit_attr(struct psmouse *psmouse, void *data,
|
|||||||
struct trackpoint_attr_data *attr = data;
|
struct trackpoint_attr_data *attr = data;
|
||||||
unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
|
unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *rest;
|
|
||||||
|
|
||||||
value = simple_strtoul(buf, &rest, 10);
|
if (strict_strtoul(buf, 10, &value) || value > 1)
|
||||||
if (*rest || value > 1)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (attr->inverted)
|
if (attr->inverted)
|
||||||
|
@ -1202,16 +1202,22 @@ static ssize_t
|
|||||||
store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct aiptek *aiptek = dev_get_drvdata(dev);
|
struct aiptek *aiptek = dev_get_drvdata(dev);
|
||||||
int x;
|
long x;
|
||||||
|
|
||||||
|
if (strict_strtol(buf, 10, &x)) {
|
||||||
|
size_t len = buf[count - 1] == '\n' ? count - 1 : count;
|
||||||
|
|
||||||
|
if (strncmp(buf, "disable", len))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
if (strcmp(buf, "disable") == 0) {
|
|
||||||
aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
|
aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
|
||||||
} else {
|
} else {
|
||||||
x = (int)simple_strtol(buf, NULL, 10);
|
if (x < AIPTEK_TILT_MIN || x > AIPTEK_TILT_MAX)
|
||||||
if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) {
|
return -EINVAL;
|
||||||
|
|
||||||
aiptek->newSetting.xTilt = x;
|
aiptek->newSetting.xTilt = x;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1238,16 +1244,22 @@ static ssize_t
|
|||||||
store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct aiptek *aiptek = dev_get_drvdata(dev);
|
struct aiptek *aiptek = dev_get_drvdata(dev);
|
||||||
int y;
|
long y;
|
||||||
|
|
||||||
|
if (strict_strtol(buf, 10, &y)) {
|
||||||
|
size_t len = buf[count - 1] == '\n' ? count - 1 : count;
|
||||||
|
|
||||||
|
if (strncmp(buf, "disable", len))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
if (strcmp(buf, "disable") == 0) {
|
|
||||||
aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
|
aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
|
||||||
} else {
|
} else {
|
||||||
y = (int)simple_strtol(buf, NULL, 10);
|
if (y < AIPTEK_TILT_MIN || y > AIPTEK_TILT_MAX)
|
||||||
if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) {
|
return -EINVAL;
|
||||||
|
|
||||||
aiptek->newSetting.yTilt = y;
|
aiptek->newSetting.yTilt = y;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1269,8 +1281,12 @@ static ssize_t
|
|||||||
store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct aiptek *aiptek = dev_get_drvdata(dev);
|
struct aiptek *aiptek = dev_get_drvdata(dev);
|
||||||
|
long j;
|
||||||
|
|
||||||
aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, NULL, 10);
|
if (strict_strtol(buf, 10, &j))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
aiptek->newSetting.jitterDelay = (int)j;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1294,8 +1310,12 @@ static ssize_t
|
|||||||
store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct aiptek *aiptek = dev_get_drvdata(dev);
|
struct aiptek *aiptek = dev_get_drvdata(dev);
|
||||||
|
long d;
|
||||||
|
|
||||||
aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, NULL, 10);
|
if (strict_strtol(buf, 10, &d))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
aiptek->newSetting.programmableDelay = (int)d;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1541,8 +1561,11 @@ static ssize_t
|
|||||||
store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct aiptek *aiptek = dev_get_drvdata(dev);
|
struct aiptek *aiptek = dev_get_drvdata(dev);
|
||||||
|
long w;
|
||||||
|
|
||||||
aiptek->newSetting.wheel = (int)simple_strtol(buf, NULL, 10);
|
if (strict_strtol(buf, 10, &w)) return -EINVAL;
|
||||||
|
|
||||||
|
aiptek->newSetting.wheel = (int)w;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,10 +461,11 @@ static ssize_t ads7846_disable_store(struct device *dev,
|
|||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct ads7846 *ts = dev_get_drvdata(dev);
|
struct ads7846 *ts = dev_get_drvdata(dev);
|
||||||
char *endp;
|
long i;
|
||||||
int i;
|
|
||||||
|
if (strict_strtoul(buf, 10, &i))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
i = simple_strtoul(buf, &endp, 10);
|
|
||||||
spin_lock_irq(&ts->lock);
|
spin_lock_irq(&ts->lock);
|
||||||
|
|
||||||
if (i)
|
if (i)
|
||||||
|
Loading…
Reference in New Issue
Block a user