Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2237323pxb; Wed, 30 Mar 2022 20:17:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyF6OrmJToCqZXb1txQzZ+g+4ZAMR4xfuBkUs3+gcrecFvO1usmmAzV+3SN6UKu4js/+HNm X-Received: by 2002:a17:902:f690:b0:154:2ceb:f18a with SMTP id l16-20020a170902f69000b001542cebf18amr3213697plg.4.1648696663126; Wed, 30 Mar 2022 20:17:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648696663; cv=none; d=google.com; s=arc-20160816; b=nY228gOB+3InVWSdBSmvlkFYiD3ULhnHs1iSbv9SektXHYgG1NoLB15djWWEshVtyF VGwaKQzNRy9X2IwO1VJUFOTFf+n0W3B6xGjZef68ajzYVpRG++4RCEAk3DjGDjUkSd/a orMyxbtSgbeTfouImBhUPY4ySPHqvMYmc8MQ6Trh9Nqz7EUH1XB8eLXO5sL57chUcEX5 kCMxNQ3EZ5kVggUMApOASBoarF4XzDGcEbdKs3plJsnSIu6BrkP2LjUOeTZNUaRh4XiV e+diT1ue8yxCOBBGSL+jVwxbDmeD95sfwX4mlO5Lg75wAEXDXXsOvND/jgZOE+KzIZTE eXIw== 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:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=MdHWXaxnfXMbT4dGtxOke852Tfh2I+Qj/Hn4tovXMKI=; b=Wuv7ifxwi8Z4Un8h0FEoFrijezof6sAoma2fOF97+1Art7kf+WEO8oqwfECmMrps1b 3S8DVHEq1YukFWoIy/Fj9724ykRnyvfeeFSjmd69ty1ZcVGS9+0Xp4AM7/i+79/W8WNr ZMXaGp3serfoBA0us/27ueGxF1WEfxNJLqXbM89TSjf2scnjq6OFLBP3q6sfbNVl059F QQ+RGgCFbx84C++9FTexxwxma6Btou5KBQB16NZ6JxUYdCIYJbiDNNGASc481jmIJrF2 1S6Qd2eThd4J8fuJmg9/y1ru5iS01rdf0c+Uqwfjj7ks25P9OwzHG5ykmtu4CN1XZftU sLnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@roeck-us.net header.s=default header.b=OpHb4H8P; 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 j11-20020a170902758b00b00153b2d165e8si8486550pll.496.2022.03.30.20.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 20:17:43 -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=OpHb4H8P; 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 F24661017CB; Wed, 30 Mar 2022 19:50:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345392AbiC3PZa (ORCPT + 99 others); Wed, 30 Mar 2022 11:25:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbiC3PZ1 (ORCPT ); Wed, 30 Mar 2022 11:25:27 -0400 Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.151.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3093200 for ; Wed, 30 Mar 2022 08:23:39 -0700 (PDT) Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway30.websitewelcome.com (Postfix) with ESMTP id A0CB9278AC for ; Wed, 30 Mar 2022 10:23:38 -0500 (CDT) Received: from 162-215-252-75.unifiedlayer.com ([208.91.199.152]) by cmsmtp with SMTP id ZaAcnavOTdx86ZaAcnA14f; Wed, 30 Mar 2022 10:23:38 -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:Subject:From:References:Cc:To: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=MdHWXaxnfXMbT4dGtxOke852Tfh2I+Qj/Hn4tovXMKI=; b=OpHb4H8PkxkvcVUoESQWRYuGEG SO/ven6U6l04uXCHxDi572vzwdWjSViNGsrrJktRFu8dHCfRaFpCdHXQ//Mrl0yUQ77GUOESG1QxM dpOLQ5XAioqMyvYFgEpwnWLT4qWrYXiOYEtBMLr7QBFWLczZEAATnzfits91r2bUiDFGm0OFzUUQE Kd+B1Xmq15wIjp0pAmOUnD1wo0YDcCxDNEUE8NudAwOqVS0tocYysIDKuZpS1p/UJDeEYQf+0Ko0G eWXQ5now840rT5FhcIbyM1mfpVA65voncsCiCmNdp1szsrZon7hUM/dmW76HVjTeibF32AkSKkGfd 9sRL102A==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:54570) 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 1nZaAb-0031qE-PN; Wed, 30 Mar 2022 15:23:37 +0000 Message-ID: <4973276f-ed1e-c4ed-18f9-e8078c13f81a@roeck-us.net> Date: Wed, 30 Mar 2022 08:23:35 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: Xu Yilun , David Laight Cc: Michael Walle , Tom Rix , Jean Delvare , Andrew Lunn , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Paolo Abeni , "linux-hwmon@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" References: <20220329160730.3265481-1-michael@walle.cc> <20220329160730.3265481-2-michael@walle.cc> <20220330065047.GA212503@yilunxu-OptiPlex-7050> <5029cf18c9df4fab96af13c857d2e0ef@AcuMS.aculab.com> <20220330145137.GA214615@yilunxu-OptiPlex-7050> From: Guenter Roeck Subject: Re: [PATCH v2 1/5] hwmon: introduce hwmon_sanitize_name() In-Reply-To: <20220330145137.GA214615@yilunxu-OptiPlex-7050> 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: 1nZaAb-0031qE-PN X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 108-223-40-66.lightspeed.sntcca.sbcglobal.net [108.223.40.66]:54570 X-Source-Auth: linux@roeck-us.net X-Email-Count: 16 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/30/22 07:51, Xu Yilun wrote: > On Wed, Mar 30, 2022 at 10:11:39AM +0000, David Laight wrote: >> From: Xu Yilun >>> Sent: 30 March 2022 07:51 >>> >>> On Tue, Mar 29, 2022 at 06:07:26PM +0200, 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 >>>> --- >>>> Documentation/hwmon/hwmon-kernel-api.rst | 9 ++++- >>>> drivers/hwmon/hwmon.c | 49 ++++++++++++++++++++++++ >>>> include/linux/hwmon.h | 3 ++ >>>> 3 files changed, 60 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/Documentation/hwmon/hwmon-kernel-api.rst b/Documentation/hwmon/hwmon-kernel-api.rst >>>> index c41eb6108103..12f4a9bcef04 100644 >>>> --- a/Documentation/hwmon/hwmon-kernel-api.rst >>>> +++ b/Documentation/hwmon/hwmon-kernel-api.rst >>>> @@ -50,6 +50,10 @@ register/unregister functions:: >>>> >>>> void devm_hwmon_device_unregister(struct device *dev); >>>> >>>> + char *hwmon_sanitize_name(const char *name); >>>> + >>>> + char *devm_hwmon_sanitize_name(struct device *dev, const char *name); >>>> + >>>> hwmon_device_register_with_groups registers a hardware monitoring device. >>>> The first parameter of this function is a pointer to the parent device. >>>> The name parameter is a pointer to the hwmon device name. The registration >>>> @@ -93,7 +97,10 @@ removal would be too late. >>>> >>>> All supported hwmon device registration functions only accept valid device >>>> names. Device names including invalid characters (whitespace, '*', or '-') >>>> -will be rejected. The 'name' parameter is mandatory. >>>> +will be rejected. The 'name' parameter is mandatory. Before calling a >>>> +register function you should either use hwmon_sanitize_name or >>>> +devm_hwmon_sanitize_name to replace any invalid characters with an >>> >>> I suggest to duplicate the name and replace ... >> >> You are now going to get code that passed in NULL when the kmalloc() fails. >> If 'sanitizing' the name is the correct thing to do then sanitize it >> when the copy is made into the allocated structure. > > Then the driver is unaware of the name change, which makes more > confusing. > >> (I'm assuming that the 'const char *name' parameter doesn't have to >> be persistent - that would be another bug just waiting to happen.) > > The hwmon core does require a persistent "name" parameter now. No name > copy is made when hwmon dev register. > >> >> Seems really pointless to be do a kmalloc() just to pass a string >> into a function. > > Maybe we should not force a kmalloc() when the sanitizing is needed, let > the driver decide whether to duplicate the string or not. > Drivers can do that today, and in all existing cases they do so (which is why I had suggested to handle the duplication in the convenience function in the first place). Drivers don't _have_ to use the provided convenience functions. At the same time, convenience functions should cover the most common use cases. Michael, let's just drop the changes outside drivers/hwmon from the series, and let's keep hwmon_is_bad_char() in the include file. Let's just document it, explaining its use case. Code outside drivers/hwmon can then be independently modified or not at a later time, based on driver author and/or maintainer preference. Thanks, Guenter