Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions i2c_smbus/Linux/i2c_smbus_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,28 @@ bool i2c_smbus_linux_detect()
path[sizeof(path) - 1] = '\0';
strncat(path, ent->d_name, sizeof(path) - strlen(path) - 1);
path[sizeof(path) - 1] = '\0';
if(ent->d_type == DT_LNK)
if(ent->d_type == DT_LNK || ent->d_type == DT_UNKNOWN)
{
ptr = realpath(path, NULL);
if(ptr == NULL)
continue;

strncpy(path, ptr, sizeof(path) - 1);
path[sizeof(path) - 1] = '\0';
strncat(path, "/..", sizeof(path) - strlen(path) - 1);
path[sizeof(path) - 1] = '\0';
free(ptr);

/*-------------------------------------------------------------*\
| Truncate at last '/' to get the parent PCI device directory. |
| For AMDGPU i2c buses the realpath resolves to something like: |
| /sys/devices/pci.../0000:03:00.0/i2c-4 |
| The parent (0000:03:00.0) contains vendor/device/subsystem |
| files. Using /..' traversal is unreliable in sysfs; directly |
| truncating the path is correct and portable. |
\*-------------------------------------------------------------*/
char* last_slash = strrchr(path, '/');
if(last_slash == NULL || last_slash == path)
continue;
*last_slash = '\0';
}
else
{
Expand Down