From: Andrew Lunn <andrew@lunn.ch>
To: David Miller <davem@davemloft.net>, Guenter Roeck <linux@roeck-us.net>
Cc: netdev <netdev@vger.kernel.org>,
Florian Fainelli <f.fainelli@gmail.com>,
Russell King <rmk+kernel@arm.linux.org.uk>,
linux-hwmon@vger.kernel.org, Andrew Lunn <andrew@lunn.ch>
Subject: [PATCH net-next 3/4] hwmon: Add helper to tell if a char is invalid in a name
Date: Tue, 17 Jul 2018 21:48:12 +0200 [thread overview]
Message-ID: <1531856893-27884-4-git-send-email-andrew@lunn.ch> (raw)
In-Reply-To: <1531856893-27884-1-git-send-email-andrew@lunn.ch>
HWMON device names are not allowed to contain "-* \t\n". Add a helper
which will return true if passed an invalid character. It can be used
to massage a string into a hwmon compatible name by replacing invalid
characters with '_'.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
include/linux/hwmon.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index b217101ca76e..9493d4a388db 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -398,4 +398,27 @@ devm_hwmon_device_register_with_info(struct device *dev,
void hwmon_device_unregister(struct device *dev);
void devm_hwmon_device_unregister(struct device *dev);
+/**
+ * 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.18.0
next prev parent reply other threads:[~2018-07-17 20:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-17 19:48 [PATCH net-next 0/4] HWMON support for SFP modules Andrew Lunn
2018-07-17 19:48 ` [PATCH net-next 1/4] hwmon: Add missing HWMON_T_LCRIT_ALARM define Andrew Lunn
2018-07-17 20:12 ` Guenter Roeck
2018-07-17 19:48 ` [PATCH net-next 2/4] hwmon: Add support for power min, lcrit, min_alarm and lcrit_alarm Andrew Lunn
2018-07-17 20:12 ` Guenter Roeck
2018-07-17 19:48 ` Andrew Lunn [this message]
2018-07-17 20:12 ` [PATCH net-next 3/4] hwmon: Add helper to tell if a char is invalid in a name Guenter Roeck
2018-07-17 19:48 ` [PATCH net-next 4/4] net: phy: sfp: Add HWMON support for module sensors Andrew Lunn
2018-07-17 20:13 ` Guenter Roeck
2018-07-18 1:02 ` [PATCH net-next 0/4] HWMON support for SFP modules David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1531856893-27884-4-git-send-email-andrew@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=netdev@vger.kernel.org \
--cc=rmk+kernel@arm.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).