Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5621488pxb; Mon, 28 Mar 2022 15:05:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFaUGFrg6bRCaZa70UxW+3VRoCBg/qBOFqF+nmGlpbZwae/bvUNQW81bXE6wwhY+mjsHi1 X-Received: by 2002:a17:903:18b:b0:154:4d7a:1bac with SMTP id z11-20020a170903018b00b001544d7a1bacmr28003179plg.0.1648505128733; Mon, 28 Mar 2022 15:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648505128; cv=none; d=google.com; s=arc-20160816; b=toHm6E0fsx1eVSGpEJkmD9MTk66SLdxlF/Pqi8FBg1gBSZH+1/IX1Y0HI0nsQNl8Aa rgqVwX0KFpbYjWd56blwB2GMHlEb0HCxJ7GvQ0jhM0aYEoeaezaC466bPGu5yk0gVfVx sne6NRkB5O3bF2z771v1UM0wDtmIwUAuDj7gLsTi/Wq4ZL1nV3pD9/p3lzmN4rfFNRCo yA8Fxu2MqDUWIO9cip9p+yUXmOcb5qK4xfJ5fGn/0imZ3wrmofB5iYDWEzGi76wDLFOW uVB8c81nOnpFVph1g7/CswqEmWoVz7EmYVSATcvuUB21nM9AZK0mPAH3bAzazYyJG+Bb JGkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=GvJCNB2Cnl/nlDULpdtsfyTRfdka37fX/FHgNiQs3CE=; b=CEid6sbC9FZrxlB9rzQzsHL0v6ftygQhtwn6iRhEGAlcCf82lr7vI79rwZPJQ5xkQn mt9sljZLl3N4kqOZR8z38NQH6qnRaBpQMpThWzyyZGciM/sHewpNCM/1hQNpNFox03Ng EwCFcO2eHhqy/3jUj6aTLJPWWDv0pMUiz30wLjv0WsmEikv9WGOr6P869vUY5V5KqI5I ePkFnATwp3sf3fc+t92VVvKtBFN2afyF0gbY+nR+9vSsW15sCzgdmVy9Tl0/1JslwlX2 ori/klOPy8Lah7eoOi92owPzN1OQhi9RGMs3Rz0zH30XRe2K3rzzIfZpvNaUNWU/vx+U dB/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UWVFKoEl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d26-20020a65621a000000b00381f609d718si13452841pgv.691.2022.03.28.15.05.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 15:05:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UWVFKoEl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C8AA714CD1B; Mon, 28 Mar 2022 14:28:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242418AbiC1M1T (ORCPT + 99 others); Mon, 28 Mar 2022 08:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236086AbiC1M1S (ORCPT ); Mon, 28 Mar 2022 08:27:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 878654CD7F for ; Mon, 28 Mar 2022 05:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648470336; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GvJCNB2Cnl/nlDULpdtsfyTRfdka37fX/FHgNiQs3CE=; b=UWVFKoElXqvWCLqfPsIxURQmLn2qvubUV/RVRGM7DORv0FOGigXsUcqqK9AqWHveY5Kjfk eXV1iu8We8fr2MwjDA7KoDoNzdBFcUctxNB7+WpIbP/oeTnew9secspMqkSFMUI26D6rVi pNxm83e5nbDqyavahy2BqpO5SAWogIc= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-497-M0rGSScjMdS8UyDrAMOTEw-1; Mon, 28 Mar 2022 08:25:35 -0400 X-MC-Unique: M0rGSScjMdS8UyDrAMOTEw-1 Received: by mail-qk1-f200.google.com with SMTP id v16-20020a376110000000b0067b2749e0fbso8315817qkb.0 for ; Mon, 28 Mar 2022 05:25:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=GvJCNB2Cnl/nlDULpdtsfyTRfdka37fX/FHgNiQs3CE=; b=md7rW4QaL6tWEdWRROi50SuOvdgKHAaCxkJyoUVbPY916XwVIB/NPzqY2aEj6gLkpG u9WxuUULNgZNuPdds1w48azdF8KZYaJlY5UdyCGj0anDYEVREl8/NWuW/bNB51CJ+Fb7 Q0OCJ188mGNJQdw9OOOVRdKoL0bmTvl9Fpcs9P+bhcFy/kXx5LeC93omSnLoYDfy8Da9 C9JL3ajqjHX7mCqvA3hQc9iLWuS/jLzL19o6Z+Bj0GObhOxXKa1cx6C551CTReIE0AUU ulEUA6Y9EioW4tk2GtYQtP/km0R/lFwo5vehGRd7/otlbG0MpenVFb9FESlLmaVnNYx3 HpCg== X-Gm-Message-State: AOAM530DKvtZ0AxyTlVtwDNaUSmyFEi8hA94bbcn7Lm8WYC8CBfG9azB M88SmnYAzlBQLkVC/kfWhM6SihbRjFKj2v1fhWk5uMIU55BVQKuPk8ZeKjSzCnRR3CW8SB/f2zG VjtzUn85A3BlpKEAg8Vym0pvj X-Received: by 2002:a05:622a:107:b0:2e1:d655:cc4c with SMTP id u7-20020a05622a010700b002e1d655cc4cmr21566403qtw.669.1648470334645; Mon, 28 Mar 2022 05:25:34 -0700 (PDT) X-Received: by 2002:a05:622a:107:b0:2e1:d655:cc4c with SMTP id u7-20020a05622a010700b002e1d655cc4cmr21566381qtw.669.1648470334415; Mon, 28 Mar 2022 05:25:34 -0700 (PDT) Received: from localhost.localdomain (024-205-208-113.res.spectrum.com. [24.205.208.113]) by smtp.gmail.com with ESMTPSA id y17-20020a05622a121100b002e0702457b2sm12282866qtx.20.2022.03.28.05.25.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Mar 2022 05:25:34 -0700 (PDT) Subject: Re: [PATCH v1 1/2] hwmon: introduce hwmon_sanitize_name() To: Michael Walle , Xu Yilun , Jean Delvare , Guenter Roeck , 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: Tom Rix Message-ID: Date: Mon, 28 Mar 2022 05:25:30 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20220328115226.3042322-2-michael@walle.cc> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 4:52 AM, 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 ++++++++++++++++ > 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_is_bad_char is now only used by hwmon_sanitize_name. as patch 3, consolidate into only hwmon_sanitize_name. Tom > > +/** > + * 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