Skip to content

Conversation

@raffaeler
Copy link
Contributor

@raffaeler raffaeler commented Jun 4, 2024

Fixes #2313

This PR fixes the Segmentation Fault occuring when a wrong gpioChip is passed to the libgpiod driver.
In a Raspberry PI this is typically 0 whichi is the default but on other boards there may be the need to specify a different number or even more than one (different I/Os are mapped on different chips).

The problem was related to the SafeHandle being non-null but invalid, therefore any following PInvoke to the native libgpiod library resulted in the fault.

After the change, the application calling the driver with a wrong gpioChip receive this exception message which can be handled in a catch statement.

System.IO.IOException: Unable to find a chip, error code: 2

The libgpiod V2 manages the gpioChip differently and it should already ok.

Microsoft Reviewers: Open in CodeFlow

Copy link
Member

@Ellerbach Ellerbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Nice fix :-)

Copy link
Contributor

@pgrawehr pgrawehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have thought of this much earlier...

@pgrawehr pgrawehr merged commit 9ec5ff8 into dotnet:main Jun 4, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 6, 2024
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.

GPIO input gives segmentation fault on BeagleBone Black in v3.1.0

3 participants