sysfs: refactor findPhandleMatch
- Use same indenting style as the rest of the application.
- Invert branch logic to reduce indent levels.
- Move logic that does not depend on loop variants outside loop.
- Fix a bug where the io-channels phandle is read from the wrong file.
- Remove unnecessary try/catch block around DT IOs (DT is immutable).
- Export findPhandle so other modules can use it.
- Document current method limitations.
Change-Id: I34c1c6731a5e2334075b2d25c6583143c2997207
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/sysfs.hpp b/sysfs.hpp
index b4709eb..9a8211d 100644
--- a/sysfs.hpp
+++ b/sysfs.hpp
@@ -34,6 +34,23 @@
return path + "/"s + type + id + "_"s + entry;
}
+/** @brief Return the path to the phandle file matching value in io-channels.
+ *
+ * This function will take two passed in paths.
+ * One path is used to find the io-channels file.
+ * The other path is used to find the phandle file.
+ * The 4 byte phandle value is read from the phandle file(s).
+ * The 4 byte phandle value and 4 byte index value is read from io-channels.
+ * When a match is found, the path to the matching phandle file is returned.
+ *
+ * @param[in] iochanneldir - Path to file for getting phandle from io-channels
+ * @param[in] phandledir - Path to use for reading from phandle file
+ *
+ * @return Path to phandle file with value matching that in io-channels
+ */
+std::string findPhandleMatch(
+ const std::string& iochanneldir,
+ const std::string& phandledir);
/** @brief Find hwmon instances
*