Quoting Michal Wajdeczko (2017-12-06 19:00:22)
> In some cases debugfs or sysfs may return errors that we
> want to check. Return -errno from helper functions to make
> asserts easier.
> 
> Signed-off-by: Michal Wajdeczko <[email protected]>
> Cc: Chris Wilson <[email protected]>
> Cc: Joonas Lahtinen <[email protected]>
> ---
>  lib/igt_sysfs.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
> index e7c67da..9e9fdde 100644
> --- a/lib/igt_sysfs.c
> +++ b/lib/igt_sysfs.c
> @@ -60,8 +60,8 @@ static int readN(int fd, char *buf, int len)
>                 if (ret < 0 && (errno == EINTR || errno == EAGAIN))
>                         continue;
>  
> -               if (ret <= 0)
> -                       return total ?: ret;
> +               if (ret < 0)
> +                       return total ?: -errno;

We do need to keep the break on ret == 0; some fs will just keep on
reporting 0 bytes read for EOF.

How about

if (ret < 0) {
        ret = -errno;
        if (ret == -EINTR || ret == -EAGAIN)
                continue;
}

if (ret <= 0)
        return total ?: ret;

>  
>                 total += ret;
>                 if (total == len)
> @@ -77,8 +77,8 @@ static int writeN(int fd, const char *buf, int len)
>                 if (ret < 0 && (errno == EINTR || errno == EAGAIN))
>                         continue;
>  
> -               if (ret <= 0)
> -                       return total ?: ret;
> +               if (ret < 0)
> +                       return total ?: -errno;

Ditto.

Reviewed-by: Chris Wilson <[email protected]>
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to