diff options
author | Barnabás Pőcze <pobrn@protonmail.com> | 2021-02-04 00:55:53 +0300 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2021-02-04 12:21:04 +0300 |
commit | 00641c086d2d929a770afcd8d637655625664eae (patch) | |
tree | e131b3b3964a4ea25dee2abba3164a0af18ed7a0 /drivers/platform | |
parent | c81f241081b8dd6796d9f29fb4f264aa997311cb (diff) | |
download | linux-00641c086d2d929a770afcd8d637655625664eae.tar.xz |
platform/x86: ideapad-laptop: misc. device attribute changes
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@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-16-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'drivers/platform')
-rw-r--r-- | drivers/platform/x86/ideapad-laptop.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index d9e2d0cbe1a3..65cf1be53e4e 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -385,20 +385,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; @@ -425,14 +425,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) @@ -453,7 +453,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 */ @@ -488,7 +488,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, @@ -526,7 +526,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, |