From mboxrd@z Thu Jan 1 00:00:00 1970 From: Guenter Roeck Subject: Re: [PATCH net-next 3/4] hwmon: Add helper to tell if a char is invalid in a name Date: Tue, 17 Jul 2018 13:12:48 -0700 Message-ID: <20180717201248.GC15476@roeck-us.net> References: <1531856893-27884-1-git-send-email-andrew@lunn.ch> <1531856893-27884-4-git-send-email-andrew@lunn.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: David Miller , netdev , Florian Fainelli , Russell King , linux-hwmon@vger.kernel.org To: Andrew Lunn Return-path: Received: from mail-oi0-f65.google.com ([209.85.218.65]:36328 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729840AbeGQUrF (ORCPT ); Tue, 17 Jul 2018 16:47:05 -0400 Content-Disposition: inline In-Reply-To: <1531856893-27884-4-git-send-email-andrew@lunn.ch> Sender: netdev-owner@vger.kernel.org List-ID: On Tue, Jul 17, 2018 at 09:48:12PM +0200, Andrew Lunn wrote: > 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 Acked-by: Guenter Roeck > --- > 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 >