iio: add Open Sensor Fusion IIO driver
Subsystems (3)
v6 cover iio: add Open Sensor Fusion IIO driver
Open Sensor Fusion (OSF) devices expose a UART/serdev host interface for a sensor aggregation hub. This RFC adds a Linux IIO driver that parses OSF frames and creates IIO devices at runtime from capability reports provided by the device firmware.
When the corresponding capabilities are reported, the driver exposes accelerometer, gyroscope, magnetometer, and temperature data as IIO devices named osf-accel, osf-gyro, osf-magn, and osf-temp.
This remains RFC while the binding, protocol subset, runtime discovery model, and driver-facing ABI are reviewed.
Changes in v6:
- Reworked the series as a 5-patch standalone RFC.
- Folded the previous transport and IIO registration split into one final driver patch to avoid Kconfig and Makefile churn.
- Addressed binding feedback with generic host interface wording, mandatory capability reporting, runtime discovery wording, no Linux-specific binding language, and no fixed regulator provider in the example.
- Added progressive MAINTAINERS coverage as files are introduced.
- Removed patch-split wording from Kconfig and introduced Kconfig and Makefile entries in final form.
- Applied style cleanups including loop-local variables, unused include cleanup, and a probe-local device pointer.
- Used designated initializers and guard/scoped_guard where useful.
- Kept the stream parser from discarding unauthenticated frame_len on failed decode.
- Synchronized IIO buffer pushes with iio_device_try_claim_buffer_mode() and release.
- Replaced iio_push_to_buffers_with_ts_unaligned() with local zeroed scan storage and iio_push_to_buffers_with_ts().
Validation summary:
- git diff --check: pass.
- checkpatch --strict: pass, 0 errors, 0 warnings, 0 checks.
- dt_binding_check: pass with dtschema 2026.4.
- make KBUILD_MODPOST_WARN=1 W=1 M=drivers/iio/opensensorfusion:
pass, no compiler warnings.
- Local stream parser corruption/resync harness: pass.
- Static IIO scan layout and padding checks: pass.
- Raspberry Pi hardware/runtime smoke testing is pending for this v6 candidate.
Jinseob Kim (5):
dt-bindings: iio: add Open Sensor Fusion device
Documentation: iio: add Open Sensor Fusion driver overview
iio: osf: add protocol decoding
iio: osf: add authenticated stream parser
iio: osf: add UART IIO driver
.../bindings/iio/opensensorfusion,osf.yaml | 54 +++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + Documentation/iio/index.rst | 1 + Documentation/iio/open-sensor-fusion.rst | 72 ++++ MAINTAINERS | 14 + drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/opensensorfusion/Kconfig | 16 + drivers/iio/opensensorfusion/Makefile | 6 + drivers/iio/opensensorfusion/osf_core.c | 291 +++++++++++++++++ drivers/iio/opensensorfusion/osf_core.h | 70 ++++ drivers/iio/opensensorfusion/osf_iio.c | 308 ++++++++++++++++++ drivers/iio/opensensorfusion/osf_iio.h | 22 ++ drivers/iio/opensensorfusion/osf_protocol.c | 258 +++++++++++++++ drivers/iio/opensensorfusion/osf_protocol.h | 97 ++++++ drivers/iio/opensensorfusion/osf_serdev.c | 114 +++++++ drivers/iio/opensensorfusion/osf_stream.c | 189 +++++++++++ drivers/iio/opensensorfusion/osf_stream.h | 31 ++ 18 files changed, 1547 insertions(+)
base-commit: ab5fce87a778cb780a05984a2ca448f2b41aafbf
Signature · 1 line
2.43.0
RFC PATCH v6 1/5 dt-bindings: iio: add Open Sensor Fusion device
Add a binding for the generic Open Sensor Fusion host interface.
Open Sensor Fusion devices report capabilities and samples over an OSF protocol stream. Sensor channels are discovered at runtime from capability reports instead of being described individually in Device Tree.
The protocol version is discovered at runtime from the OSF frame header. OSF GREEN is a product identity, and OSF0 is a wire-format magic value, so neither is used as the Linux compatible string.
--- .../bindings/iio/opensensorfusion,osf.yaml | 54 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 6 +++ 3 files changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml
Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml new file +54 -0
@@ -0,0 +1,54 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/opensensorfusion,osf.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Open Sensor Fusion Sensor Aggregation Hub + +maintainers: + - Jinseob Kim <[email protected]> + +description: | + This binding documents the generic Open Sensor Fusion host interface. Open + Sensor Fusion is a sensor aggregation hub. The hub exposes an OSF protocol + data stream over its host interface and reports capabilities and samples for + multiple sensor classes. The actual sensor channels are discovered at runtime + from OSF capability reports instead of describing them in Device Tree. The + protocol version is discovered at runtime. + + Public project documentation is available at: + + https://github.com/opensensorfusion + + The compatible describes the generic Open Sensor Fusion host interface. It + is not an OSF GREEN board identity, and it does not encode the OSF0 wire + magic. OSF0, protocol_major, and protocol_minor are wire-protocol details + exchanged in OSF frames. + +allOf: + - $ref: /schemas/serial/serial-peripheral-props.yaml# + +properties: + compatible: + const: opensensorfusion,osf + + vcc-supply: + description: + Regulator supplying power to the Open Sensor Fusion device. + +required: + - compatible + - vcc-supply + +unevaluatedProperties: false + +examples: + - | + serial { + sensor { + compatible = "opensensorfusion,osf"; + vcc-supply = <&vcc_sensor>; + }; + }; +...
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1237,6 +1237,8 @@ patternProperties: description: OpenPandora GmbH "^openrisc,.*": description: OpenRISC.io + "^opensensorfusion,.*": + description: Open Sensor Fusion "^openwrt,.*": description: OpenWrt "^option,.*":
MAINTAINERS +6 -0
@@ -20011,6 +20011,12 @@ F: Documentation/devicetree/ F: arch/*/boot/dts/ F: include/dt-bindings/ +OPEN SENSOR FUSION +M: Jinseob Kim <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml +K: opensensorfusion + OPENCOMPUTE PTP CLOCK DRIVER M: Vadim Fedorenko <[email protected]> L: [email protected]
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RFC v6 1/5] dt-bindings: iio: add Open Sensor Fusion device
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Using a generic protocol name as the sole compatible string instead of a specific product…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Using a generic protocol name as the sole compatible string instead of a specific product identity. --
commit 52d695764bb9f94bbb11a6128ea968762ee2ceef
Author: Jinseob Kim <[email protected]>
dt-bindings: iio: add Open Sensor Fusion device
This commit adds a binding for the generic Open Sensor Fusion host interface. Sensor channels and protocol versions are discovered dynamically at runtime, so they are not described individually in the Device Tree.
Quoted 5 lines
Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml new file +0
-0
[ ... ]
Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml line 34
Quoted 3 lines
Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml new file +3
-0+properties: + compatible: + const: opensensorfusion,osf
[Severity: Medium]
Does this generic compatible string prevent the kernel from applying future quirks or workarounds if a specific board revision or hardware variant has silicon bugs or unique power sequencing requirements?
The commit message mentions that product identities are explicitly not used as the compatible string. By defining the generic protocol name as the only valid value, the kernel lacks the ability to distinguish between different hardware implementations that might need specific handling.
Would it be more appropriate to allow or require a hardware-specific compatible string (such as the OSF Green product identity) alongside the generic fallback?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH RFC v6 1/5] dt-bindings: iio: add Open Sensor Fusion device
In reply to Jinseob KimQuoted 51 lines · Jinseob Kim
Add a binding for the generic Open Sensor Fusion host interface.
Open Sensor Fusion devices report capabilities and samples over an OSF protocol stream. Sensor channels are discovered at runtime from capability reports instead of being described individually in Device Tree.
The protocol version is discovered at runtime from the OSF frame header. OSF GREEN is a product identity, and OSF0 is a wire-format magic value, so neither is used as the Linux compatible string.
Signed-off-by Jinseob Kim <[email protected]>--- .../bindings/iio/opensensorfusion,osf.yaml | 54 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 6 +++ 3 files changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/opensensorfusion,osf.yamlDocumentation/devicetree/bindings/iio/opensensorfusion,osf.yaml new file +24
-0@@ -0,0 +1,54 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/opensensorfusion,osf.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Open Sensor Fusion Sensor Aggregation Hub + +maintainers: + - Jinseob Kim <[email protected]> + +description: | + This binding documents the generic Open Sensor Fusion host interface. Open + Sensor Fusion is a sensor aggregation hub. The hub exposes an OSF protocol + data stream over its host interface and reports capabilities and samples for + multiple sensor classes. The actual sensor channels are discovered at runtime + from OSF capability reports instead of describing them in Device Tree. The + protocol version is discovered at runtime. + + Public project documentation is available at: + + https://github.com/opensensorfusion + + The compatible describes the generic Open Sensor Fusion host interface.It
Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml
Quoted 2 lines
Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml new file +2
-0+ is not an OSF GREEN board identity, and it does not encode the OSF0 wire + magic.
I think this is evident from the previous text, and the first part is a bit confusing while the latter half is a bit confusing.
Just remove this sentence I think.
Binding looks fine to me, I'll provide a r-b when you submit a non-RFC version.
pw-bot: not-applicable
Thanks,
Conor.
Quoted 62 lines
OSF0,
protocol_major, andprotocol_minorare wire-protocol detailsDocumentation/devicetree/bindings/iio/opensensorfusion,osf.yaml new file +28
-0+ exchanged in OSF frames. + +allOf: + - $ref: /schemas/serial/serial-peripheral-props.yaml# + +properties: + compatible: + const: opensensorfusion,osf + + vcc-supply: + description: + Regulator supplying power to the Open Sensor Fusion device. + +required: + - compatible + - vcc-supply + +unevaluatedProperties: false + +examples: + - | + serial { + sensor { + compatible = "opensensorfusion,osf"; + vcc-supply = <&vcc_sensor>; + }; + }; +...Documentation/devicetree/bindings/vendor-prefixes.yaml +2
-0@@ -1237,6 +1237,8 @@ patternProperties: description: OpenPandora GmbH "^openrisc,.*": description: OpenRISC.io + "^opensensorfusion,.*": + description: Open Sensor Fusion "^openwrt,.*": description: OpenWrt "^option,.*":MAINTAINERS +6
-0@@ -20011,6 +20011,12 @@ F: Documentation/devicetree/ F: arch/*/boot/dts/ F: include/dt-bindings/ +OPEN SENSOR FUSION +M: Jinseob Kim <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml +K: opensensorfusion + OPENCOMPUTE PTP CLOCK DRIVER M: Vadim Fedorenko <[email protected]> L: [email protected]Signature · 1 line
2.43.0
Re: [PATCH RFC v6 1/5] dt-bindings: iio: add Open Sensor Fusion device
I will remove that sentence in the next revision.
I will also drop the RFC tag for the next version unless there are specific open questions that need to be called out.
Thanks
Jinseob
2026년 6월 30일 (화) 오전 12:39, Conor Dooley <[email protected]>님이 작성:
Quoted 130 lines · Jinseob Kim
Quoted 51 lines
Add a binding for the generic Open Sensor Fusion host interface.
Open Sensor Fusion devices report capabilities and samples over an OSF protocol stream. Sensor channels are discovered at runtime from capability reports instead of being described individually in Device Tree.
The protocol version is discovered at runtime from the OSF frame header. OSF GREEN is a product identity, and OSF0 is a wire-format magic value, so neither is used as the Linux compatible string.
Signed-off-by Jinseob Kim <[email protected]>--- .../bindings/iio/opensensorfusion,osf.yaml | 54 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 6 +++ 3 files changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/opensensorfusion,osf.yamlDocumentation/devicetree/bindings/iio/opensensorfusion,osf.yaml new file +24
-0@@ -0,0 +1,54 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/opensensorfusion,osf.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Open Sensor Fusion Sensor Aggregation Hub + +maintainers: + - Jinseob Kim <[email protected]> + +description: | + This binding documents the generic Open Sensor Fusion host interface. Open + Sensor Fusion is a sensor aggregation hub. The hub exposes an OSF protocol + data stream over its host interface and reports capabilities and samples for + multiple sensor classes. The actual sensor channels are discovered at runtime + from OSF capability reports instead of describing them in Device Tree. The + protocol version is discovered at runtime. + + Public project documentation is available at: + + https://github.com/opensensorfusion + + The compatible describes the generic Open Sensor Fusion host interface.It
Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml
Quoted 2 lines
Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml new file +2
-0+ is not an OSF GREEN board identity, and it does not encode the OSF0 wire + magic.I think this is evident from the previous text, and the first part is a bit confusing while the latter half is a bit confusing.
Just remove this sentence I think.Binding looks fine to me, I'll provide a r-b when you submit a non-RFC version.
pw-bot: not-applicable
Thanks,
Conor.Quoted 62 lines
OSF0,
protocol_major, andprotocol_minorare wire-protocol detailsDocumentation/devicetree/bindings/iio/opensensorfusion,osf.yaml new file +28
-0+ exchanged in OSF frames. + +allOf: + - $ref: /schemas/serial/serial-peripheral-props.yaml# + +properties: + compatible: + const: opensensorfusion,osf + + vcc-supply: + description: + Regulator supplying power to the Open Sensor Fusion device. + +required: + - compatible + - vcc-supply + +unevaluatedProperties: false + +examples: + - | + serial { + sensor { + compatible = "opensensorfusion,osf"; + vcc-supply = <&vcc_sensor>; + }; + }; +...Documentation/devicetree/bindings/vendor-prefixes.yaml +2
-0@@ -1237,6 +1237,8 @@ patternProperties: description: OpenPandora GmbH "^openrisc,.*": description: OpenRISC.io + "^opensensorfusion,.*": + description: Open Sensor Fusion "^openwrt,.*": description: OpenWrt "^option,.*":MAINTAINERS +6
-1@@ -20011,6 +20011,12 @@ F: Documentation/devicetree/ F: arch/*/boot/dts/ F: include/dt-bindings/ +OPEN SENSOR FUSION +M: Jinseob Kim <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml +K: opensensorfusion + OPENCOMPUTE PTP CLOCK DRIVER M: Vadim Fedorenko <[email protected]> L: [email protected] --2.43.0
RFC PATCH v6 2/5 Documentation: iio: add Open Sensor Fusion driver overview
In reply to Jinseob KimDocument the Linux IIO mapping for Open Sensor Fusion devices.
The overview explains that sensor channels are discovered at runtime from mandatory capability reports. It also documents that OSF0 is a wire-format detail and that protocol_major and protocol_minor carry protocol compatibility information.
--- Documentation/iio/index.rst | 1 + Documentation/iio/open-sensor-fusion.rst | 72 ++++++++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 74 insertions(+) create mode 100644 Documentation/iio/open-sensor-fusion.rst
Documentation/iio/index.rst +1 -0
@@ -38,4 +38,5 @@ Industrial I/O Kernel Drivers adxl345 bno055 ep93xx_adc + open-sensor-fusion opt4060
Documentation/iio/open-sensor-fusion.rst new file +72 -0
72 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -20015,6 +20015,7 @@ OPEN SENSOR FUSION M: Jinseob Kim <[email protected]> S: Maintained F: Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml +F: Documentation/iio/open-sensor-fusion.rst K: opensensorfusion OPENCOMPUTE PTP CLOCK DRIVER
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH RFC v6 2/5] Documentation: iio: add Open Sensor Fusion driver overview
Quoted 8 lines · On Mon, 29 Jun 2026 04:13:34 +0900 Jinseob Kim <[email protected]> wrote:
Document the Linux IIO mapping for Open Sensor Fusion devices.
The overview explains that sensor channels are discovered at runtime from mandatory capability reports. It also documents that OSF0 is a wire-format detail and that
protocol_majorandprotocol_minorcarry protocol compatibility information.Signed-off-by Jinseob Kim <[email protected]>
One small thing inline. Otherwise looks good to me!
Jonathan
Documentation/iio/open-sensor-fusion.rst line 64
Quoted 13 lines
Documentation/iio/open-sensor-fusion.rst new file +7
-0+Timestamps +---------- + +OSF frames include a device-side ``timestamp_us`` field. Buffered IIO samples use +an IIO timestamp captured on the host when samples are pushed to IIO buffers. +The initial driver does not correlate the device timestamp with the host IIO +clock.
Really small thing but I would avoid talking about 'initial' driver. It can cause confusion about when something is true and when it is not as we may have multiple non 'initial' drivers before you get to changing this handling. So just remove that word.
Re: [PATCH RFC v6 2/5] Documentation: iio: add Open Sensor Fusion driver overview
I will remove "initial" there in the next revision.
Thanks
Jinseob
2026년 6월 30일 (화) 오전 8:03, Jonathan Cameron <[email protected]>님이 작성:
Quoted 36 lines
Quoted 8 lines · On Mon, 29 Jun 2026 04:13:34 +0900 Jinseob Kim <[email protected]> wrote:
Document the Linux IIO mapping for Open Sensor Fusion devices.
The overview explains that sensor channels are discovered at runtime from mandatory capability reports. It also documents that OSF0 is a wire-format detail and that
protocol_majorandprotocol_minorcarry protocol compatibility information.Signed-off-by Jinseob Kim <[email protected]>One small thing inline. Otherwise looks good to me!
Jonathan
Documentation/iio/open-sensor-fusion.rst line 64
Quoted 13 lines
Documentation/iio/open-sensor-fusion.rst new file +7
-0+Timestamps +---------- + +OSF frames include a device-side ``timestamp_us`` field. Buffered IIO samples use +an IIO timestamp captured on the host when samples are pushed to IIO buffers. +The initial driver does not correlate the device timestamp with the host IIO +clock.Really small thing but I would avoid talking about 'initial' driver. It can cause confusion about when something is true and when it is not as we may have multiple non 'initial' drivers before you get to changing this handling. So just remove that word.
Jonathan Cameron
maintainerRe: [PATCH RFC v6 2/5] Documentation: iio: add Open Sensor Fusion driver overview
Quoted 2 lines · On Tue, 30 Jun 2026 14:04:43 +0900 Kim Jinseob <[email protected]> wrote:
I will remove "initial" there in the next revision.
Hi Jinseob
A small process thing that a lot of people get 'wrong' is to reply when only saying you are making the suggested change. That adds a lot of noise to the mailing list. The correct place for this information is in the change log for the next version.
Thanks,
Jonathan
Quoted 41 lines
Thanks
Jinseob
2026년 6월 30일 (화) 오전 8:03, Jonathan Cameron <[email protected]>님이 작성:
Quoted 36 lines
Quoted 8 lines · On Mon, 29 Jun 2026 04:13:34 +0900 Jinseob Kim <[email protected]> wrote:
Document the Linux IIO mapping for Open Sensor Fusion devices.
The overview explains that sensor channels are discovered at runtime from mandatory capability reports. It also documents that OSF0 is a wire-format detail and that
protocol_majorandprotocol_minorcarry protocol compatibility information.Signed-off-by Jinseob Kim <[email protected]>One small thing inline. Otherwise looks good to me!
Jonathan
Documentation/iio/open-sensor-fusion.rst line 64
Quoted 13 lines
Documentation/iio/open-sensor-fusion.rst new file +7
-0+Timestamps +---------- + +OSF frames include a device-side ``timestamp_us`` field. Buffered IIO samples use +an IIO timestamp captured on the host when samples are pushed to IIO buffers. +The initial driver does not correlate the device timestamp with the host IIO +clock.Really small thing but I would avoid talking about 'initial' driver. It can cause confusion about when something is true and when it is not as we may have multiple non 'initial' drivers before you get to changing this handling. So just remove that word.
RFC PATCH v6 3/5 iio: osf: add protocol decoding
In reply to Jinseob KimAdd 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.
--- MAINTAINERS | 1 + drivers/iio/opensensorfusion/osf_protocol.c | 258 ++++++++++++++++++++ drivers/iio/opensensorfusion/osf_protocol.h | 97 ++++++++ 3 files changed, 356 insertions(+) create mode 100644 drivers/iio/opensensorfusion/osf_protocol.c create mode 100644 drivers/iio/opensensorfusion/osf_protocol.h
MAINTAINERS +1 -0
@@ -20016,6 +20016,7 @@ M: Jinseob Kim <[email protected]> S: Maintained F: Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml F: Documentation/iio/open-sensor-fusion.rst +F: drivers/iio/opensensorfusion/osf_protocol.* K: opensensorfusion OPENCOMPUTE PTP CLOCK DRIVER
drivers/iio/opensensorfusion/osf_protocol.c new file +258 -0
258 lines not on this page · raw message
drivers/iio/opensensorfusion/osf_protocol.h new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH RFC v6 3/5] iio: osf: add protocol decoding
Quoted 9 lines · Jinseob Kim
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.
...
Quoted 6 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +6
-0+#include <linux/bits.h> +#include <linux/crc32.h> +#include <linux/errno.h> +#include <linux/limits.h> +#include <linux/types.h> +#include <linux/unaligned.h>
...
Quoted 1 line
+#define
OSF_FRAME_MAGIC0x3046534f/* "OSF0" little-endian */
#define OSF_FRAME_MAGIC 0x3046534f /* "OSF0", little-endian */
(mind a comma).
...
Quoted 28 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +28
-0+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 ;
drivers/iio/opensensorfusion/osf_protocol.c line 116
Quoted 10 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +9
-0+ +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.
Quoted 15 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +15
-0+ 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 ; +}
...
drivers/iio/opensensorfusion/osf_protocol.c line 201
Quoted 3 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +3
-0+if (capability_count > (SIZE_MAX -OSF_CAP_REPORT_BASE_LEN ) / +OSF_CAP_SENSOR_ENTRY_LEN ) +return -EOVERFLOW ;
Ditto.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH RFC v6 3/5] iio: osf: add protocol decoding
I will fix these in the next revision.
- adjust the OSF_FRAME_MAGIC comment as suggested;
- remove or rewrite the overflow checks that are effectively dead for the current u16 counts;
- build with W=1 using both GCC and clang before posting.
I will also include these items in the review tracking before posting another revision.
Thanks,
Jinseob
2026년 6월 29일 (월) 오후 11:05, Andy Shevchenko <[email protected]>님이 작성:
Quoted 102 lines · Jinseob Kim
Quoted 9 lines
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.
...
Quoted 6 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +6
-0+#include <linux/bits.h> +#include <linux/crc32.h> +#include <linux/errno.h> +#include <linux/limits.h> +#include <linux/types.h> +#include <linux/unaligned.h> ...
Quoted 1 line
+#define
OSF_FRAME_MAGIC0x3046534f/* "OSF0" little-endian */#define
OSF_FRAME_MAGIC0x3046534f/* "OSF0", little-endian */(mind a comma).
...
Quoted 28 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +28
-0+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 ;drivers/iio/opensensorfusion/osf_protocol.c line 116
Quoted 10 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +9
-0+ +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=1using both compilers: clang and GCC.Quoted 15 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +15
-0+ 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 ; +}...
drivers/iio/opensensorfusion/osf_protocol.c line 201
Quoted 3 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +3
-0+if (capability_count > (SIZE_MAX -OSF_CAP_REPORT_BASE_LEN ) / +OSF_CAP_SENSOR_ENTRY_LEN ) +return -EOVERFLOW ;Ditto.
--
With Best Regards,
Andy Shevchenko
RFC PATCH v6 4/5 iio: osf: add authenticated stream parser
In reply to Jinseob KimAdd 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 the core decoder.
Rejected candidate frames drop only the current head byte before resynchronizing, so a corrupted unauthenticated payload length cannot make the parser skip later valid frames.
--- MAINTAINERS | 1 + drivers/iio/opensensorfusion/osf_stream.c | 189 ++++++++++++++++++++++ drivers/iio/opensensorfusion/osf_stream.h | 31 ++++ 3 files changed, 221 insertions(+) create mode 100644 drivers/iio/opensensorfusion/osf_stream.c create mode 100644 drivers/iio/opensensorfusion/osf_stream.h
MAINTAINERS +1 -0
@@ -20017,6 +20017,7 @@ S: Maintained F: Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml F: Documentation/iio/open-sensor-fusion.rst F: drivers/iio/opensensorfusion/osf_protocol.* +F: drivers/iio/opensensorfusion/osf_stream.* K: opensensorfusion OPENCOMPUTE PTP CLOCK DRIVER
drivers/iio/opensensorfusion/osf_stream.c new file +189 -0
189 lines not on this page · raw message
drivers/iio/opensensorfusion/osf_stream.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _OSF_STREAM_H +#define _OSF_STREAM_H + +#include <linux/types.h> + +#define OSF_STREAM_MAX_FRAME_LEN 4096 + +struct osf_device ; + +struct osf_stream_stats { +u64 valid_frames; +u64 bad_magic_resyncs; +u64 bad_crc_frames; +u64 partial_frames; +u64 dropped_bytes; +}; + +struct osf_stream { +struct osf_device *osf; +u8 buf[OSF_STREAM_MAX_FRAME_LEN ]; +size_t len; +struct osf_stream_stats stats; +}; + +void osf_stream_init (struct osf_stream *stream,struct osf_device *osf); +void osf_stream_reset (struct osf_stream *stream); +int osf_stream_receive_bytes (struct osf_stream *stream,const u8 *buf, +size_t len); + +#endif
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RFC v6 4/5] iio: osf: add authenticated stream parser
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Frame Smuggling / Unauthenticated Injection due to dropping only 1 byte on application-level…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Frame Smuggling / Unauthenticated Injection due to dropping only 1 byte on application-level error.
- [Low] The partial_frames statistic is defined but never updated.
--
commit c420661e9f0f330fb78aaadf3e5695f6b7ee7947
Author: Jinseob Kim <[email protected]>
iio: osf: add authenticated stream parser
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 the core decoder.
Quoted 6 lines
drivers/iio/opensensorfusion/osf_stream.c new file +0
-0@@ -0,0 +1,189 @@
[ ... ]
drivers/iio/opensensorfusion/osf_stream.c line 106
Quoted 3 lines
drivers/iio/opensensorfusion/osf_stream.c new file +3
-0+ frame_len =OSF_FRAME_HEADER_LEN + payload_len +OSF_FRAME_CRC_LEN ; +if (stream->len < frame_len) +break ;
[Severity: Low]
Does this code miss updating the partial_frames statistic?
When the stream parser encounters a partial frame here and breaks out of the processing loop, it appears stream->stats.partial_frames is not incremented. This will leave it reporting 0 in debug outputs.
drivers/iio/opensensorfusion/osf_stream.c line 118
Quoted 12 lines
drivers/iio/opensensorfusion/osf_stream.c new file +12
-0+ + ret =osf_core_receive_frame (stream->osf, stream->buf, frame_len); +if (ret) { +if (ret == -EBADMSG ) + stream->stats.bad_crc_frames++; + +/* +* Until the decoder accepts the frame, payload_len is +* untrusted. Drop only the current head and resynchronize. +*/ + stream->stats.dropped_bytes++; +osf_stream_drop_invalid_head (stream);
[Severity: High]
Can this lead to an unauthenticated protocol injection if an application-level handler rejects a valid frame?
If a legitimate frame has a valid CRC but osf_core_receive_frame() returns an error (like -EPROTO or -EOPNOTSUPP) because the payload is rejected by a handler, this path drops only the first byte of the outer frame rather than discarding frame_len bytes.
Could this allow an attacker to embed fake OSF frames within the payload of a legitimate sensor frame, which would then be parsed as a new frame after the single-byte drop resynchronizes?
Quoted 4 lines
drivers/iio/opensensorfusion/osf_stream.c new file +4
-0+if (!first_err) + first_err = ret; +continue ; + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH RFC v6 4/5] iio: osf: add authenticated stream parser
In reply to Jinseob KimQuoted 9 lines · Jinseob Kim
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 the core decoder.
Rejected candidate frames drop only the current head byte before resynchronizing, so a corrupted unauthenticated payload length cannot make the parser skip later valid frames.
...
drivers/iio/opensensorfusion/osf_stream.c line 18
Quoted 7 lines
drivers/iio/opensensorfusion/osf_stream.c new file +7
-0+#define OSF_STREAM_MAGIC_LEN 4 +#define OSF_STREAM_MAX_PAYLOAD_LEN \ + (OSF_STREAM_MAX_FRAME_LEN - OSF_FRAME_HEADER_LEN - OSF_FRAME_CRC_LEN) + +static const u8 osf_stream_magic[OSF_STREAM_MAGIC_LEN ] = { +'O' ,'S' ,'F' ,'0' , +};
You have already this in the header (as FourCC), use that.
...
drivers/iio/opensensorfusion/osf_stream.c line 47
Quoted 8 lines
drivers/iio/opensensorfusion/osf_stream.c new file +7
-0+static size_t osf_stream_discard_to_magic (struct osf_stream *stream) +{ +size_t old_len = stream->len; +size_t match_len; +size_t i; + +for (i =0 ; i < stream->len; i++) {
for (size_t i = 0; i < stream->len; i++) {Quoted 4 lines
drivers/iio/opensensorfusion/osf_stream.c new file +4
-0+ match_len = stream->len - i; +if (match_len >OSF_STREAM_MAGIC_LEN ) + match_len =OSF_STREAM_MAGIC_LEN ; +
drivers/iio/opensensorfusion/osf_stream.c line 61
Quoted 10 lines
drivers/iio/opensensorfusion/osf_stream.c new file +10
-0+if (osf_stream_magic_match (stream->buf + i, match_len)) { +if (i) +osf_stream_discard (stream, i); +return i; + } + } + + stream->len =0 ; +return old_len; +}
...
I stop here, because it's obvious that you neglected and ignored my previous reviews. No explanation given, nothing. This is not how you should interact with the community.
Come again when each of the given comment will be either addressed or argued.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH RFC v6 4/5] iio: osf: add authenticated stream parser
Quoted 53 lines · On Mon, 29 Jun 2026 17:10:31 +0300 Andy Shevchenko…
Quoted 9 lines · Jinseob Kim
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 the core decoder.
Rejected candidate frames drop only the current head byte before resynchronizing, so a corrupted unauthenticated payload length cannot make the parser skip later valid frames.
...
drivers/iio/opensensorfusion/osf_stream.c line 18
Quoted 7 lines
drivers/iio/opensensorfusion/osf_stream.c new file +7
-0+#define OSF_STREAM_MAGIC_LEN 4 +#define OSF_STREAM_MAX_PAYLOAD_LEN \ + (OSF_STREAM_MAX_FRAME_LEN - OSF_FRAME_HEADER_LEN - OSF_FRAME_CRC_LEN) + +static const u8 osf_stream_magic[OSF_STREAM_MAGIC_LEN ] = { +'O' ,'S' ,'F' ,'0' , +};You have already this in the header (as FourCC), use that.
...
drivers/iio/opensensorfusion/osf_stream.c line 47
Quoted 8 lines
drivers/iio/opensensorfusion/osf_stream.c new file +7
-0+static size_t osf_stream_discard_to_magic (struct osf_stream *stream) +{ +size_t old_len = stream->len; +size_t match_len; +size_t i; + +for (i =0 ; i < stream->len; i++) {for (size_t i = 0; i < stream->len; i++) {Quoted 14 lines
drivers/iio/opensensorfusion/osf_stream.c new file +14
-0+ match_len = stream->len - i; +if (match_len >OSF_STREAM_MAGIC_LEN ) + match_len =OSF_STREAM_MAGIC_LEN ; + +if (osf_stream_magic_match (stream->buf + i, match_len)) { +if (i) +osf_stream_discard (stream, i); +return i; + } + } + + stream->len =0 ; +return old_len; +}...
Quoted 6 lines
I stop here, because it's obvious that you neglected and ignored my previous reviews. No explanation given, nothing. This is not how you should interact with the community.
Come again when each of the given comment will be either addressed or argued.
Likewise. Please make sure to address every comment either through changes or through reply to the earlier thread. Perhaps some emails have gone astray (it happens!). It can be a good idea to take a quick look at lore.kernel.org to make sure you aren't missing any feedback on a previous version.
Thanks,
Jonathan
Re: [PATCH RFC v6 4/5] iio: osf: add authenticated stream parser
Understood. I missed applying the earlier style feedback consistently across this file, and I should have explicitly replied where a previous comment was not addressed.
I will these:
- reuse the existing OSF magic definition instead of duplicating a byte array in the stream parser;
- use loop-local variables where the variable is not used outside the loop;
- rework the stream error handling so authenticated and unauthenticated failures are handled deliberately;
- either update partial_frames where appropriate or remove the unused statistic.
I will also check lore for the previous versions and track the earlier review comments before posting another revision, making sure each one is either addressed in code or explicitly answered.
Thanks,
Jinseob
2026년 6월 30일 (화) 오전 8:06, Jonathan Cameron <[email protected]>님이 작성:
Quoted 74 lines
Quoted 53 lines · On Mon, 29 Jun 2026 17:10:31 +0300 Andy Shevchenko…
Quoted 9 lines · Jinseob Kim
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 the core decoder.
Rejected candidate frames drop only the current head byte before resynchronizing, so a corrupted unauthenticated payload length cannot make the parser skip later valid frames.
...
drivers/iio/opensensorfusion/osf_stream.c line 18
Quoted 7 lines
drivers/iio/opensensorfusion/osf_stream.c new file +7
-0+#define OSF_STREAM_MAGIC_LEN 4 +#define OSF_STREAM_MAX_PAYLOAD_LEN \ + (OSF_STREAM_MAX_FRAME_LEN - OSF_FRAME_HEADER_LEN - OSF_FRAME_CRC_LEN) + +static const u8 osf_stream_magic[OSF_STREAM_MAGIC_LEN ] = { +'O' ,'S' ,'F' ,'0' , +};You have already this in the header (as FourCC), use that.
...
drivers/iio/opensensorfusion/osf_stream.c line 47
Quoted 8 lines
drivers/iio/opensensorfusion/osf_stream.c new file +7
-0+static size_t osf_stream_discard_to_magic (struct osf_stream *stream) +{ +size_t old_len = stream->len; +size_t match_len; +size_t i; + +for (i =0 ; i < stream->len; i++) {for (size_t i = 0; i < stream->len; i++) {Quoted 14 lines
drivers/iio/opensensorfusion/osf_stream.c new file +14
-0+ match_len = stream->len - i; +if (match_len >OSF_STREAM_MAGIC_LEN ) + match_len =OSF_STREAM_MAGIC_LEN ; + +if (osf_stream_magic_match (stream->buf + i, match_len)) { +if (i) +osf_stream_discard (stream, i); +return i; + } + } + + stream->len =0 ; +return old_len; +}...
Quoted 6 lines
I stop here, because it's obvious that you neglected and ignored my previous reviews. No explanation given, nothing. This is not how you should interact with the community.
Come again when each of the given comment will be either addressed or argued.
Likewise. Please make sure to address every comment either through changes or through reply to the earlier thread. Perhaps some emails have gone astray (it happens!). It can be a good idea to take a quick look at lore.kernel.org to make sure you aren't missing any feedback on a previous version.
Thanks,
Jonathan
Re: [PATCH RFC v6 4/5] iio: osf: add authenticated stream parser
On Tue, Jun 30, 2026 at 02:12:06PM +0900, Kim Jinseob wrote:
And do not top-post!
Quoted 16 lines
Understood. I missed applying the earlier style feedback consistently across this file, and I should have explicitly replied where a previous comment was not addressed.
I will these:
- reuse the existing OSF magic definition instead of duplicating a byte array in the stream parser;
- use loop-local variables where the variable is not used outside the loop;
- rework the stream error handling so authenticated and unauthenticated failures are handled deliberately;
- either updatepartial_frameswhere appropriate or remove the unused statistic.I will also check lore for the previous versions and track the earlier review comments before posting another revision, making sure each one is either addressed in code or explicitly answered.
...
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Come again when each of the given comment will be either addressed or argued.
Likewise. Please make sure to address every comment either through changes or through reply to the earlier thread. Perhaps some emails have gone astray (it happens!). It can be a good idea to take a quick look at lore.kernel.org to make sure you aren't missing any feedback on a previous version.
Signature · 2 lines
With Best Regards, Andy Shevchenko
RFC PATCH v6 5/5 iio: osf: add UART IIO driver
In reply to Jinseob KimAdd the Open Sensor Fusion serdev transport, driver core, and IIO registration path as one complete driver patch.
The driver enables the required vcc regulator, receives OSF frames over UART, registers IIO devices from capability reports, supports direct raw reads from the latest sample cache, and pushes buffered samples into software kfifo buffers.
Use final Kconfig and Makefile contents from the start, claim IIO buffer mode while pushing samples, and use zeroed scan storage with explicit timestamp alignment so the driver does not depend on IIO core bounce-buffer padding behavior.
--- MAINTAINERS | 5 + drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/opensensorfusion/Kconfig | 16 ++ drivers/iio/opensensorfusion/Makefile | 6 + drivers/iio/opensensorfusion/osf_core.c | 291 ++++++++++++++++++++ drivers/iio/opensensorfusion/osf_core.h | 70 +++++ drivers/iio/opensensorfusion/osf_iio.c | 308 ++++++++++++++++++++++ drivers/iio/opensensorfusion/osf_iio.h | 22 ++ drivers/iio/opensensorfusion/osf_serdev.c | 114 ++++++++ 10 files changed, 834 insertions(+) create mode 100644 drivers/iio/opensensorfusion/Kconfig create mode 100644 drivers/iio/opensensorfusion/Makefile create mode 100644 drivers/iio/opensensorfusion/osf_core.c create mode 100644 drivers/iio/opensensorfusion/osf_core.h create mode 100644 drivers/iio/opensensorfusion/osf_iio.c create mode 100644 drivers/iio/opensensorfusion/osf_iio.h create mode 100644 drivers/iio/opensensorfusion/osf_serdev.c
MAINTAINERS +5 -0
@@ -20016,7 +20016,12 @@ M: Jinseob Kim <[email protected]> S: Maintained F: Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml F: Documentation/iio/open-sensor-fusion.rst +F: drivers/iio/opensensorfusion/Kconfig +F: drivers/iio/opensensorfusion/Makefile +F: drivers/iio/opensensorfusion/osf_core.* +F: drivers/iio/opensensorfusion/osf_iio.* F: drivers/iio/opensensorfusion/osf_protocol.* +F: drivers/iio/opensensorfusion/osf_serdev.c F: drivers/iio/opensensorfusion/osf_stream.* K: opensensorfusion
drivers/iio/Kconfig +1 -0
@@ -101,6 +101,7 @@ source "drivers/iio/light/Kconfig" source "drivers/iio/magnetometer/Kconfig" source "drivers/iio/multiplexer/Kconfig" source "drivers/iio/orientation/Kconfig" +source "drivers/iio/opensensorfusion/Kconfig" source "drivers/iio/test/Kconfig" if IIO_TRIGGER source "drivers/iio/trigger/Kconfig"
drivers/iio/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-y += light/ obj-y += magnetometer/ obj-y += multiplexer/ obj-y += orientation/ +obj-y += opensensorfusion/ obj-y += position/ obj-y += potentiometer/ obj-y += potentiostat/
drivers/iio/opensensorfusion/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config OPEN_SENSOR_FUSION + tristate "Open Sensor Fusion UART IIO driver" + depends on IIO + depends on SERIAL_DEV_BUS + select CRC32 + select IIO_BUFFER + select IIO_KFIFO_BUF + help + Build the Open Sensor Fusion UART IIO driver. + + The driver receives OSF protocol frames over a serdev UART and + registers IIO devices for supported capability entries. It exposes + accelerometer, gyroscope, magnetometer, and temperature samples + through IIO direct reads and software buffers.
drivers/iio/opensensorfusion/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_OPEN_SENSOR_FUSION) += open-sensor-fusion.o + +open-sensor-fusion-y := osf_core.o osf_iio.o osf_protocol.o osf_serdev.o \ + osf_stream.o
drivers/iio/opensensorfusion/osf_core.c new file +291 -0
291 lines not on this page · raw message
drivers/iio/opensensorfusion/osf_core.h new file +70 -0
70 lines not on this page · raw message
drivers/iio/opensensorfusion/osf_iio.c new file +308 -0
308 lines not on this page · raw message
drivers/iio/opensensorfusion/osf_iio.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _OSF_IIO_H +#define _OSF_IIO_H + +#include <linux/types.h> + +#include "osf_protocol.h" + +struct device ; +struct iio_dev ; +struct osf_device ; + +int osf_iio_register_sensor (struct device *dev, +const struct osf_capability_entry *entry, +struct osf_device *osf,struct iio_dev **indio_dev); +void osf_iio_unregister_sensor (struct iio_dev *indio_dev); +int osf_iio_push_sample (struct iio_dev *indio_dev,const s32 *values, +u16 channel_count); +bool osf_iio_sensor_supported (u16 sensor_type,u16 channel_count); +const char *osf_iio_sensor_name (u16 sensor_type); + +#endif
drivers/iio/opensensorfusion/osf_serdev.c new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RFC v6 5/5] iio: osf: add UART IIO driver
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Propagating application-level errors corrupts the UART transport stream state machine. In…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Propagating application-level errors corrupts the UART transport stream state machine. In osf_stream_process(), if osf_core_receive_frame() returns any error, the code assumes the frame length is untrusted, drops only 1 byte, and forces a stream resynchronization. However, osf_core_receive_frame() returns errors for valid, successfully decoded frames under application-level failures, such as -EOPNOTSUPP for unsupported frame types, or errors from IIO buffer pushes (e.g., in osf_iio_push_sample()). Treating these application-layer errors as framing errors causes the driver to drop the first byte of a perfectly valid frame, destroying the UART parser's synchronization and causing it to discard the rest of the frame and potentially subsequent frames. --
commit ecab881e8156b9200eed2042dbafce633317b27f
Author: Jinseob Kim <[email protected]>
iio: osf: add UART IIO driver
Add the Open Sensor Fusion serdev transport, driver core, and IIO registration path as one complete driver patch.
Quoted 5 lines
drivers/iio/opensensorfusion/osf_core.c new file +0
-0
[ ... ]
Quoted 17 lines
drivers/iio/opensensorfusion/osf_core.c new file +17
-0+int osf_core_receive_frame (struct osf_device *osf,const u8 *buf,size_t len) +{ +struct osf_frame frame; +size_t frame_len; +int ret; + + ret =osf_protocol_decode_frame (buf, len, &frame, &frame_len); +if (ret) +return ret; + +if (frame_len != len) +return -EMSGSIZE ; + +switch (frame.message_type) { +case OSF_MSG_SENSOR_SAMPLE : +return osf_core_handle_sensor_sample (osf, &frame); +case OSF_MSG_DEVICE_STATUS :
drivers/iio/opensensorfusion/osf_core.c line 263
Quoted 10 lines
drivers/iio/opensensorfusion/osf_core.c new file +10
-0+return osf_core_handle_device_status (osf, &frame); +case OSF_MSG_CAPABILITY_REPORT : +return osf_core_handle_capability_report (osf, &frame); +default : +if (frame.message_type >=OSF_RESERVED_MSG_FIRST && + frame.message_type <=OSF_RESERVED_MSG_LAST ) +return 0 ; +if (frame.message_type >=OSF_VENDOR_PRIVATE_FIRST ) +return 0 ; +return -EOPNOTSUPP ;
[Severity: High]
Will returning an application-level error like -EOPNOTSUPP here corrupt the UART transport stream state machine?
If osf_core_receive_frame() returns an error for a validly framed but unsupported message type, osf_stream_process() appears to treat it as a framing error:
osf_stream_process() {
...
ret = osf_core_receive_frame(stream->osf, stream->buf, frame_len);
if (ret) {
...
stream->stats.dropped_bytes++;
osf_stream_drop_invalid_head(stream);
continue;
}
}By dropping 1 byte instead of consuming the full frame_len, the transport state loses synchronization. This will likely cause the rest of the valid frame and potentially subsequent frames to be dropped while it attempts to resynchronize.
Should application-layer failures (like unsupported message types or failing IIO buffer pushes) be absorbed and return 0 here to ensure the full frame is consumed?
Quoted 2 lines
drivers/iio/opensensorfusion/osf_core.c new file +2
-0+ } +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH RFC v6 5/5] iio: osf: add UART IIO driver
In reply to Jinseob KimHi Jinseob,
drivers/iio/opensensorfusion/Kconfig line 5
Quoted 7 lines · Jinseob Kim
+++ b/drivers/iio/opensensorfusion/Kconfig
drivers/iio/opensensorfusion/Kconfig new file +5
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config OPEN_SENSOR_FUSION + tristate "Open Sensor Fusion UART IIO driver" + depends on IIO
The 'depends on IIO' here creates a duplicate dependency, since you already placed the import for drivers/iio/opensensorfusion/Kconfig within the 'if IIO..endif block' in 'drivers/iio/Kconfig'.
- Julian Braha
Quoted 11 lines · Jinseob Kim
Open Sensor Fusion (OSF) devices expose a UART/serdev host interface for a sensor aggregation hub. This RFC adds a Linux IIO driver that parses OSF frames and creates IIO devices at runtime from capability reports provided by the device firmware.
When the corresponding capabilities are reported, the driver exposes accelerometer, gyroscope, magnetometer, and temperature data as IIO devices named osf-accel, osf-gyro, osf-magn, and osf-temp.
This remains RFC while the binding, protocol subset, runtime discovery model, and driver-facing ABI are reviewed.
Where are the lore links to the previous versions?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Jinseob Kim
Open Sensor Fusion (OSF) devices expose a UART/serdev host interface for a sensor aggregation hub. This RFC adds a Linux IIO driver that parses OSF frames and creates IIO devices at runtime from capability reports provided by the device firmware.
Quoted 8 lines
Quoted 6 lines
When the corresponding capabilities are reported, the driver exposes accelerometer, gyroscope, magnetometer, and temperature data as IIO devices named osf-accel, osf-gyro, osf-magn, and osf-temp.
This remains RFC while the binding, protocol subset, runtime discovery model, and driver-facing ABI are reviewed.
Where are the lore links to the previous versions?
Besides that you utterly ignorant in replying to the comments of the reviewers. v3 and v5 left unanswered, third time in this version I give the very same comments. What the heck?!
Signature · 2 lines
With Best Regards, Andy Shevchenko
David Lechner
reviewerQuoted 11 lines · Jinseob Kim
Open Sensor Fusion (OSF) devices expose a UART/serdev host interface for a sensor aggregation hub. This RFC adds a Linux IIO driver that parses OSF frames and creates IIO devices at runtime from capability reports provided by the device firmware.
When the corresponding capabilities are reported, the driver exposes accelerometer, gyroscope, magnetometer, and temperature data as IIO devices named osf-accel, osf-gyro, osf-magn, and osf-temp.
This remains RFC while the binding, protocol subset, runtime discovery model, and driver-facing ABI are reviewed.
If you are just looking for review and don't have specific questions, then it is time to drop the RFC.
Andy, you are right. I should have included the previous-version links in the cover letter.
I also did not consistently track and answer all review comments across revisions. I carried several comments into later revisions, but that was not sufficient. I should have made sure every reviewer comment was either addressed in the code or explicitly answered before posting the next revision.
Sorry for that.
For reference, the earlier public versions are:
v1:
https://lore.kernel.org/r/[email protected]
v2:
https://lore.kernel.org/r/[email protected]
v3:
https://lore.kernel.org/r/[email protected]
v4:
https://lore.kernel.org/r/[email protected]
v5:
https://lore.kernel.org/r/[email protected]
v6:
https://lore.kernel.org/r/[email protected]
David, understood. If the next revision is just asking for normal review and I do not have specific open questions, I will drop the RFC tag. If I still mark it RFC, I will state the specific questions clearly in the cover letter.
I will not post another revision until I have gone through the previous review comments and made sure each one is either addressed in the code or explicitly answered. I will also include the previous-version links in the next cover letter.
Thanks
Jinseob
2026년 6월 30일 (화) 오전 12:25, David Lechner <[email protected]>님이 작성:
Quoted 17 lines · Jinseob Kim
Quoted 11 lines
Open Sensor Fusion (OSF) devices expose a UART/serdev host interface for a sensor aggregation hub. This RFC adds a Linux IIO driver that parses OSF frames and creates IIO devices at runtime from capability reports provided by the device firmware.
When the corresponding capabilities are reported, the driver exposes accelerometer, gyroscope, magnetometer, and temperature data as IIO devices named osf-accel, osf-gyro, osf-magn, and osf-temp.
This remains RFC while the binding, protocol subset, runtime discovery model, and driver-facing ABI are reviewed.
If you are just looking for review and don't have specific questions, then it is time to drop the RFC.
Jonathan Cameron
maintainerQuoted 10 lines · On Mon, 29 Jun 2026 10:25:38 -0500 David Lechner <[email protected]> wrote:
Quoted 9 lines · Jinseob Kim
Open Sensor Fusion (OSF) devices expose a UART/serdev host interface for a sensor aggregation hub. This RFC adds a Linux IIO driver that parses OSF frames and creates IIO devices at runtime from capability reports provided by the device firmware.
When the corresponding capabilities are reported, the driver exposes accelerometer, gyroscope, magnetometer, and temperature data as IIO devices named osf-accel, osf-gyro, osf-magn, and osf-temp.
Quoted 6 lines
Quoted 2 lines
This remains RFC while the binding, protocol subset, runtime discovery model, and driver-facing ABI are reviewed.
If you are just looking for review and don't have specific questions, then it is time to drop the RFC.
It isn't uncommon to keep RFC tags when there is a related spec that isn't finalised yet. Basically they act as a 'don't merge this' marker. However I can keep track of this one without it given we don't have that happen a lot in IIO. Please do make sure that you keep that bit of the cover letter, Jinseob!
Jonathan