Re: [PATCH v7 4/5] iio: osf: add authenticated stream parser
From: Kim Jinseob
Date: Fri Jul 10 2026 - 11:31:32 EST
> Why so complicated? le32_to_cpup() + just integer comparison should work, no?
> Alternatively get_unaligned_le32() if the buffer is unaligned.
I have reworked this in my local next revision. Complete four-byte
candidates are now compared using get_unaligned_le32() and
OSF_FRAME_MAGIC.
A small separate check remains only for preserving a trailing one-,
two-, or three-byte "OSF0" prefix when the magic is split across
receive callbacks. I added a comment explaining that case.
> Seems like reinvention of min() from minmax.h.
Agreed. The open-coded minimum calculations are now replaced with min().
> I believe I have commented on this already. Please, go and double check all comments.
> My comment was to use the same pattern as in _init() above.
osf_stream_reset() now uses the same early-return pattern as
osf_stream_init(). I also re-audited the earlier comments, including the
common magic definition, loop-local variables, redundant casts, GENMASK(),
Kconfig wording, and partial-frame statistics.
> Why all this dances? first_err is 0, we all know this.
The zero-length path now directly returns osf_stream_process(stream).
> This error checking and handling is unusual. It requires a good comment
> explaining what's going on.
The parser continues processing the current received chunk after a
recoverable framing error so that later valid frames in the same chunk are
not delayed until another callback. Only the first error is retained for
diagnostic logging, while the serdev callback still reports the complete
byte count as consumed.
I added a source comment documenting this behavior and verified that
CRC-valid frames ignored by the core are consumed in full without
resynchronizing into their payload.
thanks,
jinseob