lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAJZ5v0gqe2SVU3kTkb3V25kax1dyfW5HjcmJba1bcCcS-BxkdQ@mail.gmail.com>
Date: Tue, 20 May 2025 20:28:15 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Hsin-Te Yuan <yuanhsinte@...omium.org>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>, Daniel Lezcano <daniel.lezcano@...aro.org>, 
	Zhang Rui <rui.zhang@...el.com>, Lukasz Luba <lukasz.luba@....com>, linux-pm@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] thermal: sysfs: Return ENODATA instead of EAGAIN for reads

On Mon, May 12, 2025 at 7:53 AM Hsin-Te Yuan <yuanhsinte@...omium.org> wrote:
>
> According to POSIX spec, EAGAIN returned by read with O_NONBLOCK set
> means the read would block. Hence, the common implementation in
> nonblocking model will poll the file when the nonblocking read returns
> EAGAIN. However, when the target file is thermal zone, this mechanism
> will totally malfunction because thermal zone doesn't implement sysfs
> notification and thus the poll will never return.
>
> For example, the read in Golang implemnts such method and sometimes
> hangs at reading some thermal zones via sysfs.
>
> Change to throw ENODATA instead of EAGAIN to userspace.
>
> Signed-off-by: Hsin-Te Yuan <yuanhsinte@...omium.org>
> ---
> Changes in v2:
> - Modify commit message to make it clear
> - Link to v1: https://lore.kernel.org/r/20250409-temp-v1-1-9a391d8c60fd@chromium.org
> ---
>  drivers/thermal/thermal_sysfs.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
> index 24b9055a0b6c515b865e0d7e2db1d0de176ff767..3d1713e053dfb867933d95131f1f2491d2ecd07e 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -40,8 +40,11 @@ temp_show(struct device *dev, struct device_attribute *attr, char *buf)
>
>         ret = thermal_zone_get_temp(tz, &temperature);
>
> -       if (ret)
> +       if (ret) {
> +               if (ret == -EAGAIN)
> +                       return -ENODATA;
>                 return ret;
> +       }

I would prefer to do

if (ret == -EAGAIN)
        return -ENODATA;

if (ret)
        return ret;

here or even

if (!ret)
        return sprintf(buf, "%d\n", temperature);

if (ret == -EAGAIN)
        return -ENODATA;

return ret;

if you want to optimize for the success case.

>
>         return sprintf(buf, "%d\n", temperature);
>  }
>
> ---

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ