adafruit/adafruit-beaglebone-io-python — pull request #45 by zthorson (2013-11-14 17:25:05+00:00)
Title: ADC Fix: Conflicting Device Tree would Set Fault

This is a fix for a segfault that occurs when the user loads a device tree object that contains a helper structure in the code fragment.

Cause:
User loads a device tree that uses helper in one of the fragments
A conflicting cape will generate a system path similar to the one used by this library. For Example:

Conflicting path:
/sys/devices/ocp.2/custom_helper.10
Library path:
/sys/devices/ocp.2/helper.15

when the library called build_path, it would mistakenly select custom_helper.10 instead of helper.15. Since custom_helper.10 did not have any AIN files, the read function would try to read a non-existant file and cause a segfault.

Since a lot of sample code out there uses a fragment with the word helper in it, this issue may come up with other users, however it is likely not very common.

Fix:
Force the build_path routine to make sure helper. is at the beginning of the string, not in the middle.
Added additional error checking to produce error messages rather than Seg Faults

Possible improvements:

It may make sense to modify the devicetree overlay file to not use the word helper, since it seems to be in common use. Possibly change name to adafruit-bbio-ios?

Patch Notes:
Updated the build_path to be more selective over what paths it chooses (This should prevent chosing the wrong helper leading to seg faults)
Improved error messages when ADC fails to setup
Check for null file handle when opening AIN to prevent seg fault