During development of the support for the temperature sensor on the GPY
PHY, I've noticed that there is ususually a loop over the name to
replace any invalid characters. Instead of open coding it in the drivers
provide a convenience function.
The last patch is marked as RFC, it should probably be reposted/applied
to the kernel release after next (?).
changes since v1:
- split patches
- add hwmon-kernel-api.rst documentation
- move the strdup into the hwmon core
- also provide a resource managed variant
Michael Walle (5):
hwmon: introduce hwmon_sanitize_name()
hwmon: intel-m10-bmc-hwmon: use devm_hwmon_sanitize_name()
net: sfp: use hwmon_sanitize_name()
net: phy: nxp-tja11xx: use devm_hwmon_sanitize_name()
hwmon: move hwmon_is_bad_char() into core
Documentation/hwmon/hwmon-kernel-api.rst | 9 +++-
drivers/hwmon/hwmon.c | 69 ++++++++++++++++++++++++
drivers/hwmon/intel-m10-bmc-hwmon.c | 7 +--
drivers/net/phy/nxp-tja11xx.c | 7 +--
drivers/net/phy/sfp.c | 8 +--
include/linux/hwmon.h | 24 +--------
6 files changed, 83 insertions(+), 41 deletions(-)
--
2.30.2
With the last user of this function converted to hwmon_sanitize_name(),
move the function into the core itself and make it private.
Signed-off-by: Michael Walle <[email protected]>
---
drivers/hwmon/hwmon.c | 20 ++++++++++++++++++++
include/linux/hwmon.h | 23 -----------------------
2 files changed, 20 insertions(+), 23 deletions(-)
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 619ef9f9a16e..f19b69b066ef 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -1057,6 +1057,26 @@ void devm_hwmon_device_unregister(struct device *dev)
}
EXPORT_SYMBOL_GPL(devm_hwmon_device_unregister);
+/**
+ * hwmon_is_bad_char - Is the char invalid in a hwmon name
+ * @ch: the char to be considered
+ *
+ * Returns true if the char is invalid, false otherwise.
+ */
+static bool hwmon_is_bad_char(const char ch)
+{
+ switch (ch) {
+ case '-':
+ case '*':
+ case ' ':
+ case '\t':
+ case '\n':
+ return true;
+ default:
+ return false;
+ }
+}
+
static char *__hwmon_sanitize_name(struct device *dev, const char *old_name)
{
char *name, *p;
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 4efaf06fd2b8..6a60e3a4acc0 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -464,27 +464,4 @@ int hwmon_notify_event(struct device *dev, enum hwmon_sensor_types type,
char *hwmon_sanitize_name(const char *name);
char *devm_hwmon_sanitize_name(struct device *dev, const char *name);
-/**
- * hwmon_is_bad_char - Is the char invalid in a hwmon name
- * @ch: the char to be considered
- *
- * hwmon_is_bad_char() can be used to determine if the given character
- * may not be used in a hwmon name.
- *
- * Returns true if the char is invalid, false otherwise.
- */
-static inline bool hwmon_is_bad_char(const char ch)
-{
- switch (ch) {
- case '-':
- case '*':
- case ' ':
- case '\t':
- case '\n':
- return true;
- default:
- return false;
- }
-}
-
#endif
--
2.30.2