Skip to content

Conversation

etienne-lms
Copy link
Contributor

@etienne-lms etienne-lms commented Oct 13, 2025

Change sys_test_bit() to have several sys_*_test_bit() helper functions to return 0 or 1 (respectively when target bit is clear or set) as described in their documentation (include/zephyr/sys/sys_io.h) instead of returning a bit mask result.

Correct the documentation of sys_test_bit() and its derivative helper functions (listed below) since these return a bit mask value instead of an essentially boolean value as previously described.

In tree implementation do conform with that: the result of these functions are always implicitly tested against being 0 or a non-zero value.

Affected helper functions fix by this change are
sys_test_bit(), sys_test_and_set_bit(), sys_test_and_clear_bit(), sys_bitfield_test_bit(), sys_bitfield_test_and_set_bit() and sys_bitfield_test_and_clear_bit().

@dcpleung
Copy link
Member

Not sure this is a good idea to change the inner working of this, as there are probably lots of divers and apps depending on this behavior.

@etienne-lms
Copy link
Contributor Author

Indeed this is something I would fear. At least, there are no such examples in-tree, in zephyr repo as well as HALs (and the other few modules referred in west.yml).

Alternatively, should we correct the documentation of these functions?
https://github.com/zephyrproject-rtos/zephyr/blob/v4.2.0/include/zephyr/sys/sys_io.h#L288
https://github.com/zephyrproject-rtos/zephyr/blob/v4.2.0/include/zephyr/sys/sys_io.h#L301
...

@JarmouniA
Copy link
Contributor

Alternatively, should we correct the documentation of these functions?

Yes, align the doc instead with the code behavior. Otherwise this will be considered a public API breaking change & will have to go through the relevant process
https://docs.zephyrproject.org/latest/develop/api/api_lifecycle.html#introducing-breaking-api-changes

@etienne-lms
Copy link
Contributor Author

The fact these functions return an int for an unsigned masked value is a bit awkward.

Correct the documentation of sys_test_bit() and its derivative helper
functions (listed below) since these return a bit mask value instead of
an essentially boolean value as previosuly described.

In tree implementation do conform with that: the result of these
functions are always implicitly tested against being 0 or a non-zero
value.

Helper functions which documentation is modified are sys_test_bit(),
sys_test_and_set_bit(), sys_test_and_clear_bit(), sys_bitfield_test_bit(),
sys_bitfield_test_and_set_bit() and sys_bitfield_test_and_clear_bit().

Signed-off-by: Etienne Carriere <[email protected]>
@zephyrbot zephyrbot added the area: Base OS Base OS Library (lib/os) label Oct 14, 2025
@etienne-lms etienne-lms changed the title include: zephyr: arch: common: fix sys_test_bit() to return 0 or 1 include: zephyr: arch: common: fix sys_test_bit() and friends documentation Oct 14, 2025
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Architectures area: Base OS Base OS Library (lib/os) size: XS A PR changing only a single line of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants