From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Jinseob Kim <kimjinseob88@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC v6 3/5] iio: osf: add protocol decoding
Date: Mon, 29 Jun 2026 17:05:27 +0300 [thread overview]
Message-ID: <akJ7p17eay2mnW-Y@ashevche-desk.local> (raw)
In-Reply-To: <20260628191337.937-4-kimjinseob88@gmail.com>
On Mon, Jun 29, 2026 at 04:13:35AM +0900, Jinseob Kim wrote:
> Add helpers for decoding Open Sensor Fusion frame headers and supported
> message payloads.
>
> The decoder validates the OSF0 wire magic, protocol major version,
> header length, payload bounds, reserved fields and CRC before exposing
> decoded frame contents to the rest of the driver.
>
> Use explicit little-endian wire storage sizes and designated
> initializers for decoded output structures.
...
> +#include <linux/bits.h>
> +#include <linux/crc32.h>
> +#include <linux/errno.h>
> +#include <linux/limits.h>
> +#include <linux/types.h>
> +#include <linux/unaligned.h>
...
> +#define OSF_FRAME_MAGIC 0x3046534f /* "OSF0" little-endian */
#define OSF_FRAME_MAGIC 0x3046534f /* "OSF0", little-endian */
(mind a comma).
...
> +int osf_protocol_decode_sensor_sample(const struct osf_frame *frame,
> + struct osf_sensor_sample *sample)
> +{
> + u16 channel_count;
> + u16 sample_format;
> + u16 sensor_type;
> + size_t expected_len;
> + const u8 *payload;
> +
> + if (!frame || !sample || !frame->payload)
> + return -EINVAL;
> +
> + if (frame->message_type != OSF_MSG_SENSOR_SAMPLE)
> + return -EPROTO;
> +
> + if (frame->payload_len < OSF_SENSOR_SAMPLE_BASE_LEN)
> + return -EMSGSIZE;
> +
> + payload = frame->payload;
> + sensor_type = get_unaligned_le16(payload);
> + channel_count = get_unaligned_le16(payload + 4);
> + sample_format = get_unaligned_le16(payload + 6);
> +
> + if (!osf_sensor_type_valid(sensor_type))
> + return -EPROTO;
> +
> + if (!channel_count)
> + return -EPROTO;
> +
> + if (sample_format != OSF_SAMPLE_FORMAT_S32)
> + return -EPROTO;
> +
> + if (get_unaligned_le32(payload + 12))
> + return -EPROTO;
> + if (channel_count > (SIZE_MAX - OSF_SENSOR_SAMPLE_BASE_LEN) /
> + sizeof(__le32))
> + return -EOVERFLOW;
Dead code because it's always 'false'? Hasn't compiler given a warning?
Always compile your code with `make W=1` using both compilers: clang and GCC.
> + expected_len = OSF_SENSOR_SAMPLE_BASE_LEN + channel_count * sizeof(__le32);
> + if (frame->payload_len != expected_len)
> + return -EMSGSIZE;
> +
> + *sample = (struct osf_sensor_sample) {
> + .sensor_type = sensor_type,
> + .sensor_index = get_unaligned_le16(payload + 2),
> + .channel_count = channel_count,
> + .sample_format = sample_format,
> + .scale_nano = get_unaligned_le32(payload + 8),
> + .samples = payload + OSF_SENSOR_SAMPLE_BASE_LEN,
> + };
> +
> + return 0;
> +}
...
> + if (capability_count > (SIZE_MAX - OSF_CAP_REPORT_BASE_LEN) /
> + OSF_CAP_SENSOR_ENTRY_LEN)
> + return -EOVERFLOW;
Ditto.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-06-29 14:05 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-28 19:13 [PATCH RFC v6 0/5] iio: add Open Sensor Fusion IIO driver Jinseob Kim
2026-06-28 19:13 ` [PATCH RFC v6 1/5] dt-bindings: iio: add Open Sensor Fusion device Jinseob Kim
2026-06-28 19:19 ` sashiko-bot
2026-06-29 15:39 ` Conor Dooley
2026-06-28 19:13 ` [PATCH RFC v6 2/5] Documentation: iio: add Open Sensor Fusion driver overview Jinseob Kim
2026-06-28 19:13 ` [PATCH RFC v6 3/5] iio: osf: add protocol decoding Jinseob Kim
2026-06-29 14:05 ` Andy Shevchenko [this message]
2026-06-28 19:13 ` [PATCH RFC v6 4/5] iio: osf: add authenticated stream parser Jinseob Kim
2026-06-28 19:26 ` sashiko-bot
2026-06-29 14:10 ` Andy Shevchenko
2026-06-28 19:13 ` [PATCH RFC v6 5/5] iio: osf: add UART IIO driver Jinseob Kim
2026-06-28 19:26 ` sashiko-bot
2026-06-29 14:09 ` [PATCH RFC v6 0/5] iio: add Open Sensor Fusion " Andy Shevchenko
2026-06-29 14:12 ` Andy Shevchenko
2026-06-29 15:25 ` David Lechner
2026-06-29 16:47 ` Kim Jinseob
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=akJ7p17eay2mnW-Y@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=kimjinseob88@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox