Re: [PATCH v2] tracing: silence GCC 9 array bounds warning

From: Steven Rostedt
Date: Wed May 22 2019 - 07:55:10 EST


On Wed, 22 May 2019 11:58:10 +0200
Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx> wrote:

> +/* reset all but tr, trace, and overruns */
> +static __always_inline void trace_iterator_reset(struct trace_iterator *iter)
> +{
> + /*
> + * We do not simplify the start address to &iter->seq in order to let
> + * GCC 9 know that we really want to overwrite more members than
> + * just iter->seq (-Warray-bounds).

This comment is fine for the change log, but here it is too specific.
Why does one care about GCC 9 when we are at version GCC 21? I care
more about why we are clearing the data and less about the way we are
doing it.

A comment like:

/*
* Reset the state of the trace_iterator so that it can read
* consumed data. Normally, the trace_iterator is used for
* reading the data when it is not consumed, and must retain
* state.
*/

That is more useful than why we have the offset hack.


> + */
> + const size_t offset = offsetof(struct trace_iterator, seq);

Need a empty line between these two.

-- Steve

> + memset((char *)(iter) + offset, 0, sizeof(struct trace_iterator) - offset);
> +
> + iter->pos = -1;
> +}
> +
> #endif /* _LINUX_KERNEL_TRACE_H */