Re: [PATCH v3 15/18] rtla/trace: Fix write loop in trace_event_save_hist()
From: Tomas Glozar
Date: Tue Mar 03 2026 - 09:57:47 EST
čt 15. 1. 2026 v 18:29 odesílatel Wander Lairson Costa
<wander@xxxxxxxxxx> napsal:
>
> The write loop in trace_event_save_hist() does not correctly handle
> errors from the write() system call. If write() returns -1, this value
> is added to the loop index, leading to an incorrect memory access on
> the next iteration and potentially an infinite loop. The loop also
> fails to handle EINTR.
>
> Fix the write loop by introducing proper error handling. The return
> value of write() is now stored in a ssize_t variable and checked for
> errors. The loop retries the call if interrupted by a signal and breaks
> on any other error after logging it with strerror().
>
> Additionally, change the index variable type from int to size_t to
> match the type used for buffer sizes and by strlen(), improving type
> safety.
>
> Signed-off-by: Wander Lairson Costa <wander@xxxxxxxxxx>
Looks good. Only thing is that it should have a Fixes tag so that it
can be detected by automation (e.g. stable backports - as this is
relatively old code), like this:
Fixes: 761916fd02c2 ("rtla/trace: Save event histogram output to a file")
(on one line, Gmail may truncate that)
Tomas