Re: [PATCH v2 4/4] PM / devfreq: Optimize error return value of governor_show()

From: Jie Zhan

Date: Wed Apr 01 2026 - 23:46:08 EST




On 4/1/2026 11:31 AM, Yaxiong Tian wrote:
> When df->governor is NULL, governor_show() returns -EINVAL, which
> confuses users.
>
> To fix this issue, return -ENOENT to indicate that no governor is
> currently set for the device.
>
> Signed-off-by: Yaxiong Tian <tianyaxiong@xxxxxxxxxx>
> ---
> drivers/devfreq/devfreq.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 975f82d7a9d1..c40568d2a4dc 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -1377,7 +1377,7 @@ static ssize_t governor_show(struct device *dev,
> struct devfreq *df = to_devfreq(dev);
>
> if (!df->governor)
> - return -EINVAL;
> + return -ENOENT;
Hi Yaxiong,

Usually we don't change sysfs error code because that might break userspace
if it depends on this to do some specific handling (although it shouldn't
do so!)

Besides that, from a user-friendliness point of view, I'd still prefer
ENODEV.

A user terminal is supposed to get "No such file" on -ENOENT and "No such
device" on -ENODEV.

I guess the latter is more meaningful since 'device' can mean 'object'?
"No such file" is a bit confusing because the sysfs file or entry is
clearly there.

Thanks,
Jie
>
> return sprintf(buf, "%s\n", df->governor->name);
> }