From 009506ef515e49963224c0b6f2ea52fcf42af6fe Mon Sep 17 00:00:00 2001 From: "Sanford Rockowitz (/shared/home/rock/dot_gitconfig)" Date: Sat, 23 Nov 2024 13:29:25 -0500 Subject: [PATCH] replace sysfs_find_adapter() should fix the display detection problem part of issue #465 --- src/i2c/i2c_sysfs_base.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/i2c/i2c_sysfs_base.c b/src/i2c/i2c_sysfs_base.c index 41df2b228..dc314a92e 100644 --- a/src/i2c/i2c_sysfs_base.c +++ b/src/i2c/i2c_sysfs_base.c @@ -1079,7 +1079,8 @@ get_i2c_device_sysfs_name(int busno) * * Caller is responsible for freeing the returned value */ -char * sysfs_find_adapter(char * path) { +#ifdef OLD +char * sysfs_find_adapter_old(char * path) { bool debug = false; DBGTRC_STARTING(debug, TRACE_GROUP, "path=%s", path); assert(path); @@ -1120,6 +1121,37 @@ char * sysfs_find_adapter(char * path) { DBGTRC_DONE(debug,TRACE_GROUP, "Returning: %s", devpath); return devpath; } +#endif + + +char * sysfs_find_adapter(char * path) { + bool debug = false; + DBGTRC_STARTING(debug, TRACE_GROUP, "path=%s", path); + assert(path); + int depth = (IS_DBGTRC(debug, DDCA_TRC_NONE)) ? 2 : -1; + + char * devpath = NULL; + char * rp1 = strdup(path); + char * rp2 = NULL; + + // strlen(rp1) > 1 shuld be unnecessary, but just in case: + while(!devpath && strlen(rp1) > 0 && !streq(rp1, "/")) { + if ( RPT_ATTR_TEXT(depth, NULL, rp1, "class")) { + devpath = rp1; + } + else { + RPT_ATTR_REALPATH(depth, &rp2, rp1, ".."); + free(rp1); + rp1 = rp2; + rp2 = NULL; + } + } + if (!devpath) + free(rp1); + + DBGTRC_DONE(debug,TRACE_GROUP, "Returning: %s", devpath); + return devpath; +} /** Gets the driver name of an I2C device,