Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5598281pxb; Mon, 28 Mar 2022 14:46:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKnaphTLdBmIVK+Ti7cNav+JcqH0y1TzVa3tskyrnoFVZufht3FVVF/eDfrHvjtNXG+uw2 X-Received: by 2002:a05:6870:8327:b0:dd:b065:6a80 with SMTP id p39-20020a056870832700b000ddb0656a80mr604192oae.167.1648503976463; Mon, 28 Mar 2022 14:46:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648503976; cv=none; d=google.com; s=arc-20160816; b=t5RpwXq45SBZJxlmyHpgV1l7dDuPYox6ZugVk/sxqUB7MTNcI4ZqHXalQ9wYJnvfKD CjTQM6sOfv1bGUi5ksjHxbnUtXN1TkioGND/hkAQBygz8iJ8mMEAPjx+TTwiwcdFJsEh rqhinvdzPBCLwNO3LWiPD49kYkHAtO/lH6VNTeoRPvFlNn7vgvOOL2wVnteQnibREiX1 wVWvT72P0qKoBBbopnbwJe8hCS0KCVUu6Wp+c0Ns9IO05WSCs8ZdLopMobfvV8vp/WMd NRG/QMbBfgrxTABOiUdI/ckLxafHPzsYkmRv4NR9aDGMTDcNznyHddDUUex509Blie9N 260Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ravsT/aucKnVvzJpwttquM0/aEFh0FetHl00O2h6aXw=; b=xCFyZ/kjzrKAQQk0iZn1GHMXNrfiOZ+rS6nkRrtZfcrug9s27oDDzJd4dzf4HwKJqP EB/JLCvHOf6XxMuz61uYuiUsuqw2Gg5k3DXOP1LQI19CsW3RFOK8LwcrLXW2nRG6I6PB j1DtqAEVUN43Qo4oJgifLsBr2T5xFmAfOzamzOTOX4Gcbvxwa36KZjobbbLOaILgwDm0 jEChpr8simHrdzET8BMa+mPyL6NTRn2o8mX2pjGXLZzNnThR9oUjzyuojtVfRz8ZUpRi Sdxa6gP9cNlOmWpgk+tr7l/D+96Cwa6JDPLBbvEdWfAFkOt3whbPdS0QZunmX4yLbZdn AnFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@roeck-us.net header.s=default header.b=xjQx8mzl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d5-20020a056870e24500b000dd9afdf567si10457039oac.238.2022.03.28.14.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:46:16 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=fail header.i=@roeck-us.net header.s=default header.b=xjQx8mzl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B6A72B7145; Mon, 28 Mar 2022 14:19:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239474AbiC1QdE (ORCPT + 99 others); Mon, 28 Mar 2022 12:33:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231311AbiC1QdD (ORCPT ); Mon, 28 Mar 2022 12:33:03 -0400 Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.143.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98CC06212F for ; Mon, 28 Mar 2022 09:31:21 -0700 (PDT) Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 00F63108012 for ; Mon, 28 Mar 2022 11:31:21 -0500 (CDT) Received: from 162-215-252-75.unifiedlayer.com ([208.91.199.152]) by cmsmtp with SMTP id YsF6nmAuKXvvJYsF6nzWjE; Mon, 28 Mar 2022 11:29:20 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ravsT/aucKnVvzJpwttquM0/aEFh0FetHl00O2h6aXw=; b=xjQx8mzlpwruVmELyTRwD22SWX kE/e3LznR+m0Or0Nb7PZ7nns/mYp12f7xAyY0VLe/P2ZoUhENAbhbNDmr9XrdC7f7jydWJz2XegyI ub9qpi2oAwbgnhxNHfp+ptZHItnYLoDwaU3Fj6t87naGkABB8saz7f9p4UDnWWP0drZxMBg1IWub5 WtYGFj7gO13wOP1p3OwFGHomD9uX+AhwUoRnSF4pBLXMT+tl+fBg4mp7vxuv9u27Jl9cHMZEsDSP4 FqjLL2+JaHF8DKpw9y1o4h3X9d8ozgyHgJq9Io/l1DBwADJ+dwY6fA0mto8wiT6qkO7rABuPtNvwW IsDyTWGw==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:54530) by bh-25.webhostbox.net with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nYsF5-001eOc-VK; Mon, 28 Mar 2022 16:29:20 +0000 Message-ID: Date: Mon, 28 Mar 2022 09:29:18 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v1 1/2] hwmon: introduce hwmon_sanitize_name() Content-Language: en-US To: Michael Walle , Xu Yilun , Tom Rix , Jean Delvare , Andrew Lunn , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org References: <20220328115226.3042322-1-michael@walle.cc> <20220328115226.3042322-2-michael@walle.cc> From: Guenter Roeck In-Reply-To: <20220328115226.3042322-2-michael@walle.cc> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-BWhitelist: no X-Source-IP: 108.223.40.66 X-Source-L: No X-Exim-ID: 1nYsF5-001eOc-VK X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 108-223-40-66.lightspeed.sntcca.sbcglobal.net [108.223.40.66]:54530 X-Source-Auth: linux@roeck-us.net X-Email-Count: 15 X-Source-Cap: cm9lY2s7YWN0aXZzdG07YmgtMjUud2ViaG9zdGJveC5uZXQ= X-Local-Domain: yes X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/28/22 04:52, Michael Walle wrote: > More and more drivers will check for bad characters in the hwmon name > and all are using the same code snippet. Consolidate that code by adding > a new hwmon_sanitize_name() function. > > Signed-off-by: Michael Walle > --- > drivers/hwmon/intel-m10-bmc-hwmon.c | 5 +---- > include/linux/hwmon.h | 16 ++++++++++++++++ Separate patches please, and the new function needs to be documented in Documentation/hwmon/hwmon-kernel-api.rst. Thanks, Guenter > 2 files changed, 17 insertions(+), 4 deletions(-) > > diff --git a/drivers/hwmon/intel-m10-bmc-hwmon.c b/drivers/hwmon/intel-m10-bmc-hwmon.c > index 7a08e4c44a4b..e6e55fc30153 100644 > --- a/drivers/hwmon/intel-m10-bmc-hwmon.c > +++ b/drivers/hwmon/intel-m10-bmc-hwmon.c > @@ -515,7 +515,6 @@ static int m10bmc_hwmon_probe(struct platform_device *pdev) > struct intel_m10bmc *m10bmc = dev_get_drvdata(pdev->dev.parent); > struct device *hwmon_dev, *dev = &pdev->dev; > struct m10bmc_hwmon *hw; > - int i; > > hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL); > if (!hw) > @@ -532,9 +531,7 @@ static int m10bmc_hwmon_probe(struct platform_device *pdev) > if (!hw->hw_name) > return -ENOMEM; > > - for (i = 0; hw->hw_name[i]; i++) > - if (hwmon_is_bad_char(hw->hw_name[i])) > - hw->hw_name[i] = '_'; > + hwmon_sanitize_name(hw->hw_name); > > hwmon_dev = devm_hwmon_device_register_with_info(dev, hw->hw_name, > hw, &hw->chip, NULL); > diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h > index eba380b76d15..210b8c0b2827 100644 > --- a/include/linux/hwmon.h > +++ b/include/linux/hwmon.h > @@ -484,4 +484,20 @@ static inline bool hwmon_is_bad_char(const char ch) > } > } > > +/** > + * hwmon_sanitize_name - Replaces invalid characters in a hwmon name > + * @name: NUL-terminated name > + * > + * Invalid characters in the name will be overwritten in-place by an > + * underscore. > + */ > +static inline void hwmon_sanitize_name(char *name) > +{ > + while (*name) { > + if (hwmon_is_bad_char(*name)) > + *name = '_'; > + name++; > + }; > +} > + > #endif