Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Fixed issue when gpio chip has no label #35

Merged
merged 2 commits into from
Apr 23, 2023
Merged

Conversation

yacinbm
Copy link
Contributor

@yacinbm yacinbm commented Apr 18, 2023

When a GPIO chip has no label, gpiod.chip_iter() leads to a IndexError because the ioctl call leaves the label field empty, not "\0":
image

You can run the following python script when a GPIO chip has no label

import gpiod

chips_dict = {chip.name for chip in gpiod.chip_iter()}
print(chips_dict)

and it will result in:

Traceback (most recent call last):
  File "/home/pi/workspace/test.py", line 3, in <module>
    chips_dict = {chip.name for chip in gpiod.chip_iter()}
  File "/home/pi/.local/lib/python3.9/site-packages/gpiod/libgpiodcxx/__init__.py", line 1285, in __iter__
    self._iter = libgpiod.gpiod_chip_iter().__iter__()
  File "/home/pi/.local/lib/python3.9/site-packages/gpiod/libgpiod/__init__.py", line 1195, in __iter__
    chip = gpiod_chip_open(it)
  File "/home/pi/.local/lib/python3.9/site-packages/gpiod/libgpiod/__init__.py", line 127, in gpiod_chip_open
    if info.label[0] == "\0":
IndexError: index out of range

Whereas the gpiod cli handles the lable correctly:

$ gpiodetect
gpiochip0 [pinctrl-bcm2711] (58 lines)
gpiochip1 [raspberrypi-exp-gpio] (8 lines)
gpiochip2 [unknown] (2 lines)

@hhk7734 hhk7734 enabled auto-merge (squash) April 18, 2023 22:15
@hhk7734 hhk7734 self-requested a review April 23, 2023 09:51
@hhk7734 hhk7734 merged commit a5e5325 into hhk7734:main Apr 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants