From patchwork Tue Jul 17 19:48:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 10530411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8547860247 for ; Tue, 17 Jul 2018 19:49:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75F9229777 for ; Tue, 17 Jul 2018 19:49:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A2B32977A; Tue, 17 Jul 2018 19:49:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B0B829777 for ; Tue, 17 Jul 2018 19:49:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730116AbeGQUXN (ORCPT ); Tue, 17 Jul 2018 16:23:13 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:37367 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729720AbeGQUXN (ORCPT ); Tue, 17 Jul 2018 16:23:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=GEbZI9rr2jZ7JKsBQ//NHwUTA6bzOmi2jqV2IcN7pHk=; b=d10V2hXGKMqKCSNJWPv5wS/Q7HBM8Qo0lcYoNEn90yj9W0FSCqP5DQf9ZqMclddz09jcw8IC+TiVbA3r13J2PE1H6xbphcQ5VoSGHD5+2DrhsWXA1rLOqKEizr1nuRpWLgYqWMUOU+QiAQ+YvTaxdrakNfwgQ34qPf3PBeRuZ2w=; Received: from andrew by vps0.lunn.ch with local (Exim 4.84_2) (envelope-from ) id 1ffVxT-0007Gc-Rs; Tue, 17 Jul 2018 21:48:27 +0200 From: Andrew Lunn To: David Miller , Guenter Roeck Cc: netdev , Florian Fainelli , Russell King , linux-hwmon@vger.kernel.org, Andrew Lunn 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 Message-Id: <1531856893-27884-4-git-send-email-andrew@lunn.ch> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1531856893-27884-1-git-send-email-andrew@lunn.ch> References: <1531856893-27884-1-git-send-email-andrew@lunn.ch> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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