Re: [PATCH v10 4/8] iio: osf: add validated stream parser

From: Kim Jinseob

Date: Sun Sep 20 2026 - 00:13:17 EST


> You could reorder these two functions and call stream_reset from
> stream_init. Would make it clear what getting to a 'clean' state
> means.

Agreed. I'll move osf_stream_reset() before osf_stream_init() and use
it from the init path in the next revision.

Thanks,

Jinseob

2026년 9월 20일 (일) 오전 10:31, Jonathan Cameron <jic23@xxxxxxxxxx>님이 작성:
>
> 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.
>
>
>