From c81f241081b8dd6796d9f29fb4f264aa997311cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 3 Feb 2021 21:55:48 +0000 Subject: platform/x86: ideapad-laptop: always propagate error codes from device attributes' show() callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consumers can differentiate an error from a successful read much more easily if the read() call fails with an appropriate errno instead of returning a magic string like "-1". This introduces an ABI change, but not many users are expected to be relying on the previous behavior, and this change makes this module conforming to the standard behavior that sysfs attribute show/store callbacks return an appropriate errno in case of failure. Thus the ABI breakage is deemed justified. Signed-off-by: Barnabás Pőcze Link: https://lore.kernel.org/r/20210203215403.290792-15-pobrn@protonmail.com Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede --- drivers/platform/x86/ideapad-laptop.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index c7c939f18e38..d9e2d0cbe1a3 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -380,9 +380,11 @@ static ssize_t show_ideapad_cam(struct device *dev, { unsigned long result; struct ideapad_private *priv = dev_get_drvdata(dev); + int err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result)) - return sysfs_emit(buf, "-1\n"); + err = read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result); + if (err) + return err; return sysfs_emit(buf, "%lu\n", result); } @@ -411,9 +413,11 @@ static ssize_t show_ideapad_fan(struct device *dev, { unsigned long result; struct ideapad_private *priv = dev_get_drvdata(dev); + int err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result)) - return sysfs_emit(buf, "-1\n"); + err = read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result); + if (err) + return err; return sysfs_emit(buf, "%lu\n", result); } @@ -444,9 +448,11 @@ static ssize_t touchpad_show(struct device *dev, { struct ideapad_private *priv = dev_get_drvdata(dev); unsigned long result; + int err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result)) - return sysfs_emit(buf, "-1\n"); + err = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result); + if (err) + return err; return sysfs_emit(buf, "%lu\n", result); } @@ -477,9 +483,11 @@ static ssize_t conservation_mode_show(struct device *dev, { struct ideapad_private *priv = dev_get_drvdata(dev); unsigned long result; + int err; - if (method_gbmd(priv->adev->handle, &result)) - return sysfs_emit(buf, "-1\n"); + err = method_gbmd(priv->adev->handle, &result); + if (err) + return err; return sysfs_emit(buf, "%u\n", test_bit(BM_CONSERVATION_BIT, &result)); } @@ -515,7 +523,7 @@ static ssize_t fn_lock_show(struct device *dev, int fail = read_method_int(priv->adev->handle, "HALS", &hals); if (fail) - return sysfs_emit(buf, "-1\n"); + return fail; result = hals; return sysfs_emit(buf, "%u\n", test_bit(HA_FNLOCK_BIT, &result)); -- cgit v1.2.3