* [PATCH] platform/x86: panasonic-laptop: Return errno correctly in show callback
@ 2024-11-18 6:46 Yao Zi
2024-11-18 11:21 ` Hans de Goede
2024-11-18 12:59 ` Ilpo Järvinen
0 siblings, 2 replies; 3+ messages in thread
From: Yao Zi @ 2024-11-18 6:46 UTC (permalink / raw)
To: Kenneth Chan, Hans de Goede, Ilpo Järvinen
Cc: open list:PANASONIC LAPTOP ACPI EXTRAS DRIVER, open list, Yao Zi
When an error occurs in sysfs show callback, we should return the errno
directly instead of formatting it as the result, which produces
meaningless output and doesn't inform the userspace of the error.
Fixes: 468f96bfa3a0 ("platform/x86: panasonic-laptop: Add support for battery charging threshold (eco mode)")
Fixes: d5a81d8e864b ("platform/x86: panasonic-laptop: Add support for optical driver power in Y and W series")
Signed-off-by: Yao Zi <ziyao@disroot.org>
---
drivers/platform/x86/panasonic-laptop.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index 2bf94d0ab324..22ca70eb8227 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -614,8 +614,7 @@ static ssize_t eco_mode_show(struct device *dev, struct device_attribute *attr,
result = 1;
break;
default:
- result = -EIO;
- break;
+ return -EIO;
}
return sysfs_emit(buf, "%u\n", result);
}
@@ -761,7 +760,12 @@ static ssize_t current_brightness_store(struct device *dev, struct device_attrib
static ssize_t cdpower_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
- return sysfs_emit(buf, "%d\n", get_optd_power_state());
+ int state = get_optd_power_state();
+
+ if (state < 0)
+ return state;
+
+ return sysfs_emit(buf, "%d\n", state);
}
static ssize_t cdpower_store(struct device *dev, struct device_attribute *attr,
--
2.47.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] platform/x86: panasonic-laptop: Return errno correctly in show callback
2024-11-18 6:46 [PATCH] platform/x86: panasonic-laptop: Return errno correctly in show callback Yao Zi
@ 2024-11-18 11:21 ` Hans de Goede
2024-11-18 12:59 ` Ilpo Järvinen
1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2024-11-18 11:21 UTC (permalink / raw)
To: Yao Zi, Kenneth Chan, Ilpo Järvinen
Cc: open list:PANASONIC LAPTOP ACPI EXTRAS DRIVER, open list
Hi,
On 18-Nov-24 7:46 AM, Yao Zi wrote:
> When an error occurs in sysfs show callback, we should return the errno
> directly instead of formatting it as the result, which produces
> meaningless output and doesn't inform the userspace of the error.
>
> Fixes: 468f96bfa3a0 ("platform/x86: panasonic-laptop: Add support for battery charging threshold (eco mode)")
> Fixes: d5a81d8e864b ("platform/x86: panasonic-laptop: Add support for optical driver power in Y and W series")
> Signed-off-by: Yao Zi <ziyao@disroot.org>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Regards,
Hans
> ---
> drivers/platform/x86/panasonic-laptop.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
> index 2bf94d0ab324..22ca70eb8227 100644
> --- a/drivers/platform/x86/panasonic-laptop.c
> +++ b/drivers/platform/x86/panasonic-laptop.c
> @@ -614,8 +614,7 @@ static ssize_t eco_mode_show(struct device *dev, struct device_attribute *attr,
> result = 1;
> break;
> default:
> - result = -EIO;
> - break;
> + return -EIO;
> }
> return sysfs_emit(buf, "%u\n", result);
> }
> @@ -761,7 +760,12 @@ static ssize_t current_brightness_store(struct device *dev, struct device_attrib
> static ssize_t cdpower_show(struct device *dev, struct device_attribute *attr,
> char *buf)
> {
> - return sysfs_emit(buf, "%d\n", get_optd_power_state());
> + int state = get_optd_power_state();
> +
> + if (state < 0)
> + return state;
> +
> + return sysfs_emit(buf, "%d\n", state);
> }
>
> static ssize_t cdpower_store(struct device *dev, struct device_attribute *attr,
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] platform/x86: panasonic-laptop: Return errno correctly in show callback
2024-11-18 6:46 [PATCH] platform/x86: panasonic-laptop: Return errno correctly in show callback Yao Zi
2024-11-18 11:21 ` Hans de Goede
@ 2024-11-18 12:59 ` Ilpo Järvinen
1 sibling, 0 replies; 3+ messages in thread
From: Ilpo Järvinen @ 2024-11-18 12:59 UTC (permalink / raw)
To: Kenneth Chan, Hans de Goede, Yao Zi; +Cc: platform-driver-x86, linux-kernel
On Mon, 18 Nov 2024 06:46:39 +0000, Yao Zi wrote:
> When an error occurs in sysfs show callback, we should return the errno
> directly instead of formatting it as the result, which produces
> meaningless output and doesn't inform the userspace of the error.
>
>
Thank you for your contribution, it has been applied to my local
review-ilpo branch. Note it will show up in the public
platform-drivers-x86/review-ilpo branch only once I've pushed my
local branch there, which might take a while.
The list of commits applied:
[1/1] platform/x86: panasonic-laptop: Return errno correctly in show callback
commit: 5c7bebc1a3f0661db558d60e14dde27fc216d9dc
--
i.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-18 12:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-18 6:46 [PATCH] platform/x86: panasonic-laptop: Return errno correctly in show callback Yao Zi
2024-11-18 11:21 ` Hans de Goede
2024-11-18 12:59 ` Ilpo Järvinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®