platform/x86: asus-laptop: get rid of parse_arg()
parse_arg() duplicates the funcionality of kstrtoint() so use the latter function instead. There is no funcionality change except that in the case of input being too big -ERANGE will be returned instead of -EINVAL which is not bad because -ERANGE makes more sense here. The check for !count is already done by the sysfs core so no need to duplicate it again. Also, add some minor corrections to error handling to accommodate the change in return values (parse_arg returned count if everything succeeded whereas kstrtoint returns 0 in the same situation) As a result of this patch asus-laptop.ko size is reduced by almost 1%: add/remove: 0/1 grow/shrink: 1/6 up/down: 1/-149 (-148) function old new delta __UNIQUE_ID_vermagic0 69 70 +1 ls_switch_store 133 117 -16 ledd_store 175 159 -16 display_store 157 141 -16 ls_level_store 193 176 -17 gps_store 200 178 -22 sysfs_acpi_set.isra 148 125 -23 parse_arg.part 39 - -39 Total: Before=19160, After=19012, chg -0.77% Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@gmail.com> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
This commit is contained in:
parent
999d4376c6
commit
6f7e357bf1
@ -932,30 +932,19 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
|
|||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(infos);
|
static DEVICE_ATTR_RO(infos);
|
||||||
|
|
||||||
static int parse_arg(const char *buf, unsigned long count, int *val)
|
|
||||||
{
|
|
||||||
if (!count)
|
|
||||||
return 0;
|
|
||||||
if (count > 31)
|
|
||||||
return -EINVAL;
|
|
||||||
if (sscanf(buf, "%i", val) != 1)
|
|
||||||
return -EINVAL;
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
|
static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
|
||||||
const char *buf, size_t count,
|
const char *buf, size_t count,
|
||||||
const char *method)
|
const char *method)
|
||||||
{
|
{
|
||||||
int rv, value;
|
int rv, value;
|
||||||
|
|
||||||
rv = parse_arg(buf, count, &value);
|
rv = kstrtoint(buf, 0, &value);
|
||||||
if (rv <= 0)
|
if (rv < 0)
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
if (write_acpi_int(asus->handle, method, value))
|
if (write_acpi_int(asus->handle, method, value))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
return rv;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -975,15 +964,17 @@ static ssize_t ledd_store(struct device *dev, struct device_attribute *attr,
|
|||||||
struct asus_laptop *asus = dev_get_drvdata(dev);
|
struct asus_laptop *asus = dev_get_drvdata(dev);
|
||||||
int rv, value;
|
int rv, value;
|
||||||
|
|
||||||
rv = parse_arg(buf, count, &value);
|
rv = kstrtoint(buf, 0, &value);
|
||||||
if (rv > 0) {
|
if (rv < 0)
|
||||||
if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
|
return rv;
|
||||||
pr_warn("LED display write failed\n");
|
|
||||||
return -ENODEV;
|
if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
|
||||||
}
|
pr_warn("LED display write failed\n");
|
||||||
asus->ledd_status = (u32) value;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
return rv;
|
|
||||||
|
asus->ledd_status = (u32) value;
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RW(ledd);
|
static DEVICE_ATTR_RW(ledd);
|
||||||
|
|
||||||
@ -1148,10 +1139,12 @@ static ssize_t display_store(struct device *dev, struct device_attribute *attr,
|
|||||||
struct asus_laptop *asus = dev_get_drvdata(dev);
|
struct asus_laptop *asus = dev_get_drvdata(dev);
|
||||||
int rv, value;
|
int rv, value;
|
||||||
|
|
||||||
rv = parse_arg(buf, count, &value);
|
rv = kstrtoint(buf, 0, &value);
|
||||||
if (rv > 0)
|
if (rv < 0)
|
||||||
asus_set_display(asus, value);
|
return rv;
|
||||||
return rv;
|
|
||||||
|
asus_set_display(asus, value);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_WO(display);
|
static DEVICE_ATTR_WO(display);
|
||||||
|
|
||||||
@ -1190,11 +1183,12 @@ static ssize_t ls_switch_store(struct device *dev,
|
|||||||
struct asus_laptop *asus = dev_get_drvdata(dev);
|
struct asus_laptop *asus = dev_get_drvdata(dev);
|
||||||
int rv, value;
|
int rv, value;
|
||||||
|
|
||||||
rv = parse_arg(buf, count, &value);
|
rv = kstrtoint(buf, 0, &value);
|
||||||
if (rv > 0)
|
if (rv < 0)
|
||||||
asus_als_switch(asus, value ? 1 : 0);
|
return rv;
|
||||||
|
|
||||||
return rv;
|
asus_als_switch(asus, value ? 1 : 0);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RW(ls_switch);
|
static DEVICE_ATTR_RW(ls_switch);
|
||||||
|
|
||||||
@ -1219,14 +1213,15 @@ static ssize_t ls_level_store(struct device *dev, struct device_attribute *attr,
|
|||||||
struct asus_laptop *asus = dev_get_drvdata(dev);
|
struct asus_laptop *asus = dev_get_drvdata(dev);
|
||||||
int rv, value;
|
int rv, value;
|
||||||
|
|
||||||
rv = parse_arg(buf, count, &value);
|
rv = kstrtoint(buf, 0, &value);
|
||||||
if (rv > 0) {
|
if (rv < 0)
|
||||||
value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
|
return rv;
|
||||||
/* 0 <= value <= 15 */
|
|
||||||
asus_als_level(asus, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
|
||||||
|
/* 0 <= value <= 15 */
|
||||||
|
asus_als_level(asus, value);
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RW(ls_level);
|
static DEVICE_ATTR_RW(ls_level);
|
||||||
|
|
||||||
@ -1301,14 +1296,14 @@ static ssize_t gps_store(struct device *dev, struct device_attribute *attr,
|
|||||||
int rv, value;
|
int rv, value;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
rv = parse_arg(buf, count, &value);
|
rv = kstrtoint(buf, 0, &value);
|
||||||
if (rv <= 0)
|
if (rv < 0)
|
||||||
return -EINVAL;
|
return rv;
|
||||||
ret = asus_gps_switch(asus, !!value);
|
ret = asus_gps_switch(asus, !!value);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
rfkill_set_sw_state(asus->gps.rfkill, !value);
|
rfkill_set_sw_state(asus->gps.rfkill, !value);
|
||||||
return rv;
|
return count;
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RW(gps);
|
static DEVICE_ATTR_RW(gps);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user