1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00

1609 Commits

Author SHA1 Message Date
Vincent Fazio
c2e9287333 bindings: python: chip: drop redundant exception in reraise
When re-raising an exception, it is not necessary to respecify the
exception object.

There is no functional change here; just minor cleanup to squelch new
linter warnings.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20261020003728.13669-9-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-10-20 15:08:42 +02:00
Vincent Fazio
1867708351 bindings: python: chip: simplify __bool__ expression
The `True if <> else False` ternary is unnecessary and the return value
can be simplified to the bool result of checking if the chip object
is not `None`.

The underlying `Chip` object does not have an explicit `__bool__`
implementation so the check only proved that the object existed which
is preserved.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20261020003728.13669-8-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-10-20 15:08:42 +02:00
Vincent Fazio
cba46d470a bindings: python: line_request: simplify __bool__ expression
The `True if <> else False` ternary is unnecessary and the return value
can be simplified to the bool result of checking if the request object
is not `None`.

The underlying `Request` object does not have an explicit `__bool__`
implementation so the check only proved that the object existed which
is preserved.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20261020003728.13669-7-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-10-20 15:08:42 +02:00
Vincent Fazio
f007d1fbed bindings: python: line: sort exports
Ensures the exports in __all__ are sorted alphabetically.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20261020003728.13669-6-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-10-20 15:08:42 +02:00
Vincent Fazio
5a2d64e1a4 bindings: python: setup: use a context manager to manage files
Previously, a number of places in setup.py did not use a context manager
to manage the lifetime of the underlying file descriptor for reading and
writing the `libgpiod-version.txt` file.

While the previous method works, it relies on the returned file object
being assigned to a temporary Python object that has its refcount
decremented immediately after statement execution. This then relies on
the file object's finalizer to close the underlying handle which can
emit ResourceWarnings:

  /bindings/python/setup.py:193: ResourceWarning: unclosed file <_io.TextIOWrapper name='libgpiod-version.txt' mode='w' encoding='UTF-8'>
    open("libgpiod-version.txt", "w").write(LIBGPIOD_VERSION)

Now, we specifically use a context manager to close the file descriptor
when done to explicitly manage its lifetime.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20261020003728.13669-5-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-10-20 15:08:42 +02:00
Vincent Fazio
5524758ab4 bindings: python: _internal: collapse isinstance checks
The two isinstance checks can be combined to a single call that uses a
tuple of types to check against.

When 8c9d5b4 was prototyped, it originally used a single call but it
was falsely micro-optimized to use two separate calls due to the single
call being slower.

The performance overhead was likely due to the tuple of types being
created on each iteration of the loop. Using a module variable with the
proper types avoids this overhead.

  $ python3 -m timeit -s "x = 42; T = (int, str)" "isinstance(x, T)"
  20000000 loops, best of 5: 13.9 nsec per loop
  $ python3 -m timeit -s "x = 42" "isinstance(x, int) or isinstance(x, str)"
  20000000 loops, best of 5: 14.6 nsec per loop
  $ python3 -m timeit -s "x = 42" "isinstance(x, (int, str))"
  10000000 loops, best of 5: 30 nsec per loop

Fixes: 8c9d5b4 ("bindings: python: make config iteration consistent")
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20261020003728.13669-4-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-10-20 15:08:42 +02:00
Vincent Fazio
766348cc6d bindings: python: _internal: simplify poll_fd calculation
The `True if <> else False` ternary is unnecessary and the return value
can be simplified to the bool result of checking if the file descriptor
is in the list returned from `select`.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20261020003728.13669-3-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-10-20 15:08:42 +02:00
Vincent Fazio
3e074d711e bindings: python: _internal: sort exports
Ensures the exports in __all__ are sorted alphabetically.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20261020003728.13669-2-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-10-20 15:08:42 +02:00
Bartosz Golaszewski
25c5638733 build: clarify to meson that C++ is only added for target
With C++ enabled, meson currently emits the following warning:

    WARNING: add_languages is missing native:, assuming languages are wanted for both host and build.

We only need C++ for target executables, so make that clear in
meson.build.

Fixes: 4946370d06 ("build: do not require a C++ compiler if it is not needed")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-10-02 15:52:11 +02:00
Bartosz Golaszewski
668a0efe91 dbus: fix the license of gpiodbus.h
The libgpiodbus library - which is entirely automatically generated with
gdbus-codegen - was meant to be available under LGPLv2.1 like all the
other shared libraries in this project. Change the SPDX tag in that
file to LGPL-2.1-or-later.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Link: https://patch.msgid.link/20260925-libgpiodbus-license-v1-1-d7ddafca8872@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-09-28 10:00:31 +02:00
Bartosz Golaszewski
64fde2647d README: move SPDX boiler-plate into REUSE.toml
There's no reason to keep the SPDX license and copyright headers in the
.md documents (README, CHANGELOG, etc.) as it only decreases their
readability if one doesn't use any rendering tool. Move all SPDX headers
for .md documents into REUSE.toml.

Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260916-libgpiod-readme-licensing-v1-1-1221405d6840@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-09-21 11:57:16 +02:00
Edgar Bonet
4946370d06 build: do not require a C++ compiler if it is not needed
Languages specified in the meson project() function are considered hard
dependencies. When trying to build libgpiod in an environment lacking a
C++ compiler, the build fails with an obscure error message ("ERROR:
Unable to get gcc pre-processor defines").

As the C++ compiler is only needed for building the C++ bindings, do not
require it unless the option bindings-cxx is enabled.

Fixes: 97bab4cc87 ("build: replace autotools with meson & ninja")
Signed-off-by: Edgar Bonet <bonet@grenoble.cnrs.fr>
Link: https://patch.msgid.link/0eb5c26d-731c-4ebb-be34-76466cf57720@grenoble.cnrs.fr
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-08-26 12:37:46 +02:00
Bartosz Golaszewski
7d7b077388 build: fix dependencies for generated files
Depending on the timing, we may try to build generated files that don't
exist yet. Generated .c and .h files need to be included in the sources
of the dependencies that need them so that they get generated before we
try to build them. Fix issues observed in dbus and GLib bindings.

Reported-by: Luca Weiss <luca@lucaweiss.eu>
Fixes: 97bab4cc87 ("build: replace autotools with meson & ninja")
Closes: https://github.com/brgl/libgpiod/issues/191
Link: https://patch.msgid.link/20260623-dbus-meson-deps-v1-1-b37604ecce3f@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-24 17:19:14 +02:00
Bartosz Golaszewski
1f38ba3928 build: fix incomplete dependency gate for introspection
The introspection gate in bindings/glib/meson.build only checked gir_dep,
missing g_ir_scanner and g_ir_compiler. Switch it to use the already-computed
introspection_enabled flag which checks all three.

Link: https://patch.msgid.link/20260622-build-catch2-issue-v1-4-be95e28f310b@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-24 17:17:52 +02:00
Bartosz Golaszewski
829eebf6a0 build: fix incomplete dependency gate for glib bindings
glib_enabled only checked glib_dep and glib_mkenums, but gobject_dep, gio_dep,
and gio_unix_dep are all required by the glib binding library and examples. Add
them to the gate so a missing dep disables the feature rather than failing at
link time.

Link: https://patch.msgid.link/20260622-build-catch2-issue-v1-3-be95e28f310b@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-24 17:17:52 +02:00
Bartosz Golaszewski
372a5da1d8 build: include all test dependencies in the tests_enabled gate
threads, glib-2.0 and gio-2.0 are required by libgpiosim, gpiosim-glib,
the test harness, and the gpiod-test binary, so the tests_enabled flag
should reflect their availability just like libkmod and mount.

Link: https://patch.msgid.link/20260622-build-catch2-issue-v1-2-be95e28f310b@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-24 17:17:52 +02:00
Bartosz Golaszewski
7edfd6b774 build: don't make catch2 mandatory when C++ bindings and tests are enabled
If both C++ bindings and the test suite are allowed but catch2 is absent,
meson setup would fail the build with error(). Follow the same *_enabled
graceful handling pattern established for all other optional components:
compute cxx_tests_enabled based on whether catch2 is actually found,
emit a warning() instead of error() when it's missing, and gate the C++
tests subdir on the new flag.

Also: enter the catch2 discovery block based on tests_enabled (instead of
opt_tests.allowed()) so it only runs once the test-suite dependencies
(threads, libgpiosim) are confirmed present.

Add a "C++ tests" line to the Bindings summary section, visible only when
C++ bindings are enabled.

Closes: https://github.com/brgl/libgpiod/discussions/190
Fixes: 97bab4cc87 ("build: replace autotools with meson & ninja")
Link: https://patch.msgid.link/20260622-build-catch2-issue-v1-1-be95e28f310b@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-24 17:17:52 +02:00
Bartosz Golaszewski
40538a7b48 build: gate subdirectories on the *_enabled variables
The top-level meson.build descends into tests/ and dbus/ only when the
computed tests_enabled and dbus_enabled gates are true, so the test
helper libraries and D-Bus executables are only defined in those cases.
The per-component subdirectories instead re-checked opt_*.allowed(),
which is true under the default 'auto' even when the dependencies are
missing, and then referenced those undefined variables - failing the
configuration outright instead of quietly disabling the component.

Gate every subdirectory on the corresponding top-level *_enabled
variable for correct and consistent behavior.

Closes: https://github.com/brgl/libgpiod/discussions/190
Fixes: 97bab4cc87 ("build: replace autotools with meson & ninja")
Link: https://patch.msgid.link/20260617-meson-enabled-checks-v1-1-2ff45c7691fe@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-19 10:23:50 +02:00
Bartosz Golaszewski
3591a62952 bindings: python: add missing release to the changelog
CHANGELOG.md must now be updated on every python bindings release just
like what we do with the top-level NEWS file. As the existing
description applies to v2.5.0, set the version now that this release is
tagged.

Fixes: 3076847a6c ("bindings: python: gpiod v2.5.0")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-17 15:38:23 +02:00
Bartosz Golaszewski
3076847a6c bindings: python: gpiod v2.5.0
Changelog:
- add support for free-threaded (no-GIL) CPython
- generate wheels for CPython 3.14t (free-threaded)
- drop support for Python 3.9
- migrate the C extension and test modules to multi-phase module
  initialization
- release the GIL in chip_get_info()
- fix heap-buffer overflow bugs when setting/getting line values
- check for errors after PyIter_Next() when setting output values
- check for errors after PyIter_Next() when reading request values
- fix reference count imbalances (missing Py_None and line-name
  increments, erroneous decref on PyList_SetItem() failure)
- allow closing a Chip multiple times without raising an error
- allow releasing a LineRequest multiple times without raising an error
- remove a duplicated edge-detection setting
- add a CHANGELOG.md to track changes between releases
- copy the license file into source and binary distributions
- require setuptools v77 or newer
- remove wheel from the build dependencies
- add multi-threaded tests
- add a dedicated lint dependency group and update linter configuration
- apply linter recommendations and add type annotations across examples,
  setup and helper scripts
- modernize the C extension using upgrade_pythoncapi.py suggestions
- minor internal cleanups and performance improvements

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
python-v2.5.0
2026-06-17 09:20:20 +02:00
Bartosz Golaszewski
31e184a41e bindings: python: use the correct libgpiod API version define in setup.py
Since commit a62c732936 ("core: change the behavior of
gpiod_api_version()"), the libgpiod build expects the
GPIOD_API_VERSION_STR external define to contain the API version string.
The setup.py script in python bindings was not updated so it fails to
build the library sources into the generated wheel. Use the correct
define.

Fixes: a62c732936 ("core: change the behavior of gpiod_api_version()")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-17 09:13:19 +02:00
Bartosz Golaszewski
4f2508fb8e libgpiod: start v2.4 development cycle
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-17 09:13:19 +02:00
Bartosz Golaszewski
bbcd0a5d64 libgpiod v2.3
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
v2.3
2026-06-16 13:59:02 +02:00
Bartosz Golaszewski
0ef5d37711 NEWS: updates for v2.3
Add release notes for libgpiod v2.3.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-16 13:55:29 +02:00
Bartosz Golaszewski
2de4e60262 tools: gpioset: store interactive sleep period in a long long
The interactive 'sleep' command stored the result of parse_period() in
an int. parse_period() returns a long long number of microseconds, so a
period above INT_MAX microseconds (~36 minutes, e.g. "sleep 40m")
overflowed: it could wrap to a negative value and be wrongly rejected as
an invalid period, or to an incorrect positive value producing the wrong
sleep duration.

Declare period_us as long long to match parse_period()'s return type.
The error check (period_us < 0) and the sleep_us() call, which takes an
unsigned long long, both remain correct. The non-interactive hold and
toggle period paths already use unsigned long long and were unaffected.

Add a test that issues "sleep 40m" at the interactive prompt and verifies
the tool starts sleeping rather than emitting an "invalid period" error

Fixes: c34a572c53 ("tools: add minutes as a new supported time unit")
Assisted-by: Claude Opus 4.8
Link: https://patch.msgid.link/20260608-more-pre-2-3-fixes-v1-5-577a5ba426a5@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-15 09:38:16 +02:00
Bartosz Golaszewski
c43a6cc5a5 tools: reject trailing garbage in parse_period()
parse_period() consumed an optional unit suffix ('us', 'ms', 's', 'm')
but never verified that the suffix was the end of the string. As a
result inputs with trailing garbage such as "100msx", "100usx" or
"100sx" were silently accepted and parsed as if the garbage were not
there, while inconsistently "100mx" was already rejected.

Require that the whole string be consumed by checking *end == '\0'
after the unit suffix has been processed, mirroring what parse_uint()
already does. All valid forms still leave end pointing at the
terminating NUL at that point, so only malformed input is rejected.

Add a test that passes an invalid suffix and verifies it's rejected.

Fixes: 6702eed1a5 ("tools: fix an integer overflow bug in parse_period()")
Assisted-by: Claude Opus 4.8
Link: https://patch.msgid.link/20260608-more-pre-2-3-fixes-v1-4-577a5ba426a5@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-15 09:38:16 +02:00
Bartosz Golaszewski
696ffc986b tools: gpionotify: don't watch lines on the wrong chip
Commit 0de77e2abf ("tools: gpionotify: don't leak info returned by
gpiod_chip_watch_line_info()") moved the call to
gpiod_chip_watch_line_info() out of the condition that guarded it. The
original code relied on the short-circuit evaluation of the logical AND
to only request a watch when the line actually belonged to the chip
currently being processed:

	if ((resolver->lines[j].chip_num == i) &&
	    !gpiod_chip_watch_line_info(chip, resolver->lines[j].offset))
		die_perror(...);

After the refactor the watch is requested unconditionally for every
resolved line on every chip, using the line's offset as-is. When lines
are spread across multiple chips this installs watches at foreign
offsets on the wrong chip. Such a watch typically succeeds (the offset
usually exists on the other chip too), persists - freeing the returned
gpiod_line_info does not remove it - and makes gpionotify report
spurious info events for lines the user never asked to watch.

Restore the guard so that each line is only ever watched on the chip it
belongs to, while keeping the gpiod_line_info_free() leak fix. As a side
effect a watch failure on the correct chip is now always treated as
fatal instead of only when it coincided with a matching chip_num.

Add a test-case that requests two lines with distinct offsets on two
different chips and then toggles one line's offset on the other chip. No
event must be reported for that, as the offset is not watched there.

Fixes: 0de77e2abf ("tools: gpionotify: don't leak info returned by gpiod_chip_watch_line_info()")
Assisted-by: Claude Opus 4.8
Link: https://patch.msgid.link/20260608-more-pre-2-3-fixes-v1-3-577a5ba426a5@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-15 09:38:16 +02:00
Bartosz Golaszewski
32db8215a8 core: edge-event: return 0 when zero events are requested
gpiod_edge_event_buffer_read_fd() is documented to read at most
max_events events and to return the number of events read. When called
with max_events == 0 it nonetheless issued a read() for 0 bytes, which
returns 0, and the subsequent short-read check
((unsigned int)rd < sizeof(*event_data)) then treated this as an I/O
error, setting errno to EIO and returning -1.

Requesting zero events is not an error - it is a no-op that reads
nothing. Handle it explicitly by clearing num_events and returning 0
before attempting the read.

Add a test case verifying the behavior.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Assisted-by: Claude Opus 4.8
Link: https://patch.msgid.link/20260608-more-pre-2-3-fixes-v1-2-577a5ba426a5@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-15 09:38:16 +02:00
Bartosz Golaszewski
65b5ed66e4 core: line-config: use gpiod_line_settings_free() to release settings
When releasing a no-longer-referenced settings node in
gpiod_line_config_add_line_settings(), the embedded settings object was
freed with a raw free() instead of gpiod_line_settings_free(), unlike
every other release site (e.g. free_refs()).

This is currently harmless because gpiod_line_settings_free() is just a
free(), but bypassing the type's destructor is a latent leak should the
struct ever gain heap-allocated members. Use the proper destructor for
consistency.

Fixes: 2560a857ce ("core: keep memory usage of struct line_config in check")
Assisted-by: Claude Opus 4.8
Link: https://patch.msgid.link/20260608-more-pre-2-3-fixes-v1-1-577a5ba426a5@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-15 09:38:16 +02:00
Bartosz Golaszewski
84700a6d5f dbus: manager: move g_tree_remove() out of g_assert() in gpiodbus_id_free()
g_assert() is compiled out when G_DISABLE_ASSERT is defined, which would
cause the g_tree_remove() call to disappear entirely, leading to ID leaks
and eventual resource exhaustion. Move the side-effecting call outside
the assertion, consistent with the pattern used elsewhere in the daemon.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Assisted-by: Claude Opus 4.6
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-15-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
d7d6ae8dd4 bindings: python: release the GIL in chip_get_info()
Other methods that call into the C library (chip_get_line_info,
chip_watch_line_info, etc.) properly release the GIL with
Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS, but chip_get_info() was
missed. Add the missing GIL release for consistency and to avoid
blocking other Python threads during the ioctl.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Assisted-by: Claude Opus 4.6
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-14-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
e6fb6554e9 bindings: python: check for errors after PyIter_Next() in set_output_values
PyIter_Next() returns NULL both at end-of-iteration and when an exception
is raised. The code breaks out of the loop without checking
PyErr_Occurred(), potentially swallowing Python exceptions and continuing
with a partially filled buffer.

Add the missing error check.

Fixes: 27a69b0bfd ("bindings: python: add the output_values argument to Chip.request_lines()")
Assisted-by: Claude Opus 4.6
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-13-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
3c04ff9949 bindings: python: check for errors after PyIter_Next() in request_get_values
PyIter_Next() returns NULL both at end-of-iteration and when an exception
is raised. The code breaks out of the loop without checking
PyErr_Occurred(), potentially swallowing Python exceptions and continuing
with a partially filled buffer.

Add the missing error check.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Assisted-by: Claude Opus 4.6
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-12-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
62283cc98c bindings: rust: use repr(transparent) on edge Event and simplify casts
The Event struct wraps a single *mut gpiod_edge_event pointer and is cast
from raw pointers in event_buffer.rs. Without #[repr(transparent)], the
layout compatibility is not guaranteed by the language specification.

Add #[repr(transparent)] to make the pointer cast sound, and replace
try_into().unwrap() with a simple 'as' cast for the sequence number
getters since c_ulong and usize are the same width on Linux.

Fixes: 91f9373c65 ("bindings: rust: Add libgpiod crate")
Assisted-by: Claude Opus 4.6
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-11-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
33a92137f1 bindings: rust: implement Eq and Ord for chip::Info
chip::Info already implements PartialEq and PartialOrd (both based on
comparing chip names as UTF-8 strings), but not their total-order
counterparts Eq and Ord. The omission is inconsistent: types with a
total order should implement Ord so callers can use the ergonomic sort()
/ min() / max() APIs.

Add the missing impls. Ord::cmp() delegates to partial_cmp() and falls
back to Ordering::Equal for the unreachable case where a chip name is
not valid UTF-8. Update gpiochip_devices() to use cmp() directly now
that Ord is available.

Assisted-by: Claude Sonnet 4.6
Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-10-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
b94f9591e6 bindings: rust: avoid potential panic in gpiochip_devices()
chip::Info::partial_cmp() returns None when either chip name cannot be
decoded as UTF-8. Passing that None straight to unwrap() in
gpiochip_devices() would panic at runtime. Use unwrap_or(Ordering::Equal)
so that chips with undecodable names are treated as equal rather than
causing a panic.

Fixes: 91f9373c65 ("bindings: rust: Add libgpiod crate")
Assisted-by: Claude Sonnet 4.6
Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-9-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
b5225b6d76 bindings: cxx: use get_mapped_value() for all enum mappings in line_info
The direction() method correctly uses get_mapped_value() which converts
std::out_of_range to the project's bad_mapping exception, but bias(),
drive(), edge_detection(), and event_clock() call .at() directly. This
causes them to throw std::out_of_range instead of the expected
bad_mapping exception on unexpected values.

Use get_mapped_value() consistently for all enum mapping lookups.

Fixes: 78020eae9d ("bindings: cxx: remove duplicate mapping helper")
Assisted-by: Claude Opus 4.6
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-8-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
e773070e6e bindings: cxx: drop redundant class qualifier in line_request::set_value
The definition of set_value() carried a duplicate class name prefix
(line_request::line_request::set_value) which compiles correctly but
is misleading and inconsistent with every other method definition in
the same file.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Assisted-by: Claude Sonnet 4.6
Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-7-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
f4ee1f36f9 bindings: cxx: fix consumer string in line_info stream operator
The consumer field in operator<< for line_info was using info.name()
instead of info.consumer() when building the quoted consumer string.
As a result any non-empty consumer would be printed as the line name,
not the actual consumer string.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Assisted-by: Claude Sonnet 4.6
Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-6-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
bb19198661 tests: gpiosim: remove dead container_of() assignment in gpiosim_dev_enable()
The assignment to bank via container_of() immediately before the
list_for_each_entry() loop is dead code: the loop macro reinitialises
bank on every iteration and the initial value is never read.

Assisted-by: Claude Sonnet 4.6
Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-5-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
ff535296ff tools: gpionotify: use the parse_config() return value to advance argv
Every other tool (gpioinfo, gpiomon, gpioset …) uses the value returned
by parse_config() to advance argc/argv past the parsed options:

    i = parse_config(argc, argv, &cfg);
    argc -= i;
    argv += i;

gpionotify was directly using the global optind variable instead of i,
which is equivalent today because parse_config() returns optind, but is
inconsistent and would silently break if the function were ever changed
to return something else.

Assisted-by: Claude Sonnet 4.6
Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-4-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
8098a02b46 core: add explicit NUL-termination after strncpy() calls
Both gpiod_chip_info_from_uapi() and gpiod_line_info_from_uapi() copy
kernel UAPI name strings with strncpy() into buffers that are one byte
larger than GPIO_MAX_NAME_SIZE. If the source string is exactly
GPIO_MAX_NAME_SIZE bytes long strncpy() will not append a NUL, so the
strings are only guaranteed to be terminated because the structs are
zeroed with memset() beforehand.

Make the termination unconditional and independent of the zeroing by
writing the NUL byte explicitly after each strncpy() call.

Fixes: c040d4e15e ("core: fix 1-byte buffer over-read bugs in gpiod_chip_info_from_uapi()")
Fixes: 5533f277aa ("core: fix line-info strings termination")
Assisted-by: Claude Sonnet 4.6
Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-3-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
e5cc32989e core: replace strcpy() with strncpy() in gpiod_request_config_to_uapi()
Both source and destination buffers are char[GPIO_MAX_NAME_SIZE] and
the source is always null-terminated, so strcpy() is safe here, but
since the copy length is statically known, strncpy() is more explicit.

Assisted-by: Claude Sonnet 4.6
Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-2-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
69d0c58051 core: fix signed/unsigned type mismatch in gpiod_line_request_get_value()
The local variable used to store the return value of
gpiod_line_request_get_values_subset() was declared as unsigned int
while the function returns int (-1 on error). The check for the error
condition worked by accident because assigning -1 to an unsigned type
produces UINT_MAX, which is non-zero, but using the wrong type is
misleading and technically invoking implementation-defined behaviour.
Use int throughout.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Assisted-by: Claude Sonnet 4.6
Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-1-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
f0f56bbba3 treewide: add REUSE.toml
We have some .txt files that contain SPDX headers to make `reuse lint`
happy. Let's move them into REUSE.toml instead for better readability of
their content.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-02 14:51:42 +02:00
Bartosz Golaszewski
7950002228 build: display the summary of build options after meson setup
It's useful to know which options ended up really being selected by
meson (for instance for --auto-features) so use the dedicated meson
function to display the summary.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-02 14:51:32 +02:00
Vincent Fazio
c0650edd44 bindings: python: add a changelog
Add a changelog to summarize changes to the bindings between releases.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260527215922.18678-4-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-05-28 11:01:02 +02:00
Vincent Fazio
c9378d6c63 bindings: python: support free-threaded CPython
PEP 703 [0] discusses making the GIL optional in certain builds of the
CPython interpreter.

This build option was available experiementally in Python 3.13 but has
since been stabilized in Python 3.14 per PEP 779 [1].

According to the porting guide [2], there is no strict requirement that
C extensions must be thread-safe.

Experiments have shown that no logic changes are required if callers
use sychronization mechanisms provided by the Python standard library.

The documentation has been updated to call this out specifically using
terminology from the porting guide [3].

[0]: https://peps.python.org/pep-0703/
[1]: https://peps.python.org/pep-0779/
[2]: https://py-free-threading.github.io/porting/#define-and-document-thread-safety-guarantees
[3]: https://py-free-threading.github.io/documentation-principles/#free-threading-terminology

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260527215922.18678-3-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-05-28 10:59:30 +02:00
Vincent Fazio
9d8940f38f bindings: python: tests: add multi-threaded tests
Add new multi-threaded test cases to ensure the bindings operate as
expected and do not lead to crashes or data corruption.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260527215922.18678-2-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-05-28 10:59:12 +02:00
Bartosz Golaszewski
ec46215f7b core: allow modifying settings for existing offsets in a full line-config
gpiod_line_config_add_line_settings() checks the remaining capacity
using the raw num_offsets from the caller. If the config is already at
the 64-line limit, any call - even one that would only update settings
for already configured offsets - would fail with E2BIG making it
impossible to reconfigure a line once the config is full.

Extend gpiod_line_config_add_line_settings() to only count offsets that
would require a new config slot and use this number to check if the
line-config object still has capacity.

Add a test case allowing to verify the fix.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Link: https://patch.msgid.link/20260522-line-config-full-config-bug-v1-1-b138958bf05d@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-05-26 11:00:13 +02:00