Re: [PATCH v10 4/8] iio: osf: add validated stream parser
From: Jonathan Cameron
Date: Sat Sep 19 2026 - 21:31:06 EST
On Sat, 19 Sep 2026 03:24:42 +0900
Jinseob Kim <kimjinseob88@xxxxxxxxx> wrote:
> Add a UART byte-stream parser for Open Sensor Fusion frames.
>
> The parser searches for the OSF0 wire magic, keeps partial frames
> buffered, checks header length and payload bounds, and passes complete
> candidate frames to a registered frame callback.
>
> Candidates rejected before validation drop only the current head
> byte before resynchronizing, so a corrupted unvalidated payload length
> cannot make the parser skip later valid frames. CRC-valid validated
> frames are consumed in full and classified as handled, ignored, or
> rejected.
>
> Use a direct callback member with an opaque context and keep explicit
> statistics for validated outcomes and framing failures.
>
> Assisted-by: LLM
> Signed-off-by: Jinseob Kim <kimjinseob88@xxxxxxxxx>
Just one trivial thing.
Thanks,
Jonathan
> diff --git a/drivers/iio/opensensorfusion/osf_stream.c b/drivers/iio/opensensorfusion/osf_stream.c
> new file mode 100644
> index 000000000000..e262415e69b7
> --- /dev/null
> +++ b/drivers/iio/opensensorfusion/osf_stream.c
> +void osf_stream_init(struct osf_stream *stream,
> + int (*receive_frame)(void *context, const u8 *buf,
> + size_t len),
> + void *frame_context)
> +{
> + if (!stream)
> + return;
> +
> + stream->receive_frame = receive_frame;
> + stream->frame_context = frame_context;
> + stream->len = 0;
> + memset(&stream->stats, 0, sizeof(stream->stats));
> +}
> +
> +void osf_stream_reset(struct osf_stream *stream)
> +{
> + if (!stream)
> + return;
> +
> + stream->len = 0;
> + memset(&stream->stats, 0, sizeof(stream->stats));
> +}
You could reorder these two functions and call stream_reset from
stream_init. Would make it clear what getting to a 'clean' state
means.