Do not handle zero length buffer separately. Use kstrtouint() instead of sscanf(). Use kstrtobool() in store_ideapad_cam(). These introduce minor ABI changes, but it is expected that no users rely on the previous behavior. Thus the change is deemed justifed. Additionally, use `!!` to convert to `int` and use the "%d" format specifier in sysfs_emit() for boolean-like attributes. Signed-off-by: Barnabás Pőcze <pobrn@xxxxxxxxxxxxxx> diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 70aa775e80ad..00d9e23a0310 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -388,20 +388,20 @@ static ssize_t show_ideapad_cam(struct device *dev, err = read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result); if (err) return err; - return sysfs_emit(buf, "%lu\n", result); + return sysfs_emit(buf, "%d\n", !!result); } static ssize_t store_ideapad_cam(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int ret, state; struct ideapad_private *priv = dev_get_drvdata(dev); + bool state; + int ret; - if (!count) - return 0; - if (sscanf(buf, "%i", &state) != 1) - return -EINVAL; + ret = kstrtobool(buf, &state); + if (ret) + return ret; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); if (ret) return ret; @@ -428,14 +428,14 @@ static ssize_t store_ideapad_fan(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int ret, state; struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned int state; + int ret; - if (!count) - return 0; - if (sscanf(buf, "%i", &state) != 1) - return -EINVAL; - if (state < 0 || state > 4 || state == 3) + ret = kstrtouint(buf, 0, &state); + if (ret) + return ret; + if (state > 4 || state == 3) return -EINVAL; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state); if (ret) @@ -456,7 +456,7 @@ static ssize_t touchpad_show(struct device *dev, err = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result); if (err) return err; - return sysfs_emit(buf, "%lu\n", result); + return sysfs_emit(buf, "%d\n", !!result); } /* Switch to RO for now: It might be revisited in the future */ @@ -491,7 +491,7 @@ static ssize_t conservation_mode_show(struct device *dev, err = method_gbmd(priv->adev->handle, &result); if (err) return err; - return sysfs_emit(buf, "%u\n", test_bit(BM_CONSERVATION_BIT, &result)); + return sysfs_emit(buf, "%d\n", !!test_bit(BM_CONSERVATION_BIT, &result)); } static ssize_t conservation_mode_store(struct device *dev, @@ -529,7 +529,7 @@ static ssize_t fn_lock_show(struct device *dev, return fail; result = hals; - return sysfs_emit(buf, "%u\n", test_bit(HA_FNLOCK_BIT, &result)); + return sysfs_emit(buf, "%d\n", !!test_bit(HA_FNLOCK_BIT, &result)); } static ssize_t fn_lock_store(struct device *dev, -- 2.30.0