Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp27319pxb; Wed, 30 Mar 2022 21:57:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlJC7IWiaJp6Pmz5zGb3QQhqMoeAFzDUZtaetC3j3rfx+iawJTFMW57Ak4/mUexdaQVWnz X-Received: by 2002:a63:ea45:0:b0:380:c32f:2a0d with SMTP id l5-20020a63ea45000000b00380c32f2a0dmr9027642pgk.315.1648702663290; Wed, 30 Mar 2022 21:57:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648702663; cv=none; d=google.com; s=arc-20160816; b=F5+uzIPUFKtJnGrhHI5nOK4bWCAL0QUIDFmQqTvh3vxbNHdmuSOyo4AO9VrGj0+6dT VXnQj1fA53O7rTjh5Mu6L5xQAT3SjfvqlK2WL2bdUsIyCOqBPYy+6QnvMM2qWKdhaKxX rNLkfPJdiJML2er5FlXY1dyfEnynxzjZPt/N7oQ+JuG//YncZR59VAb875we9B5fb5Gk wCg3fk8qaNQZmtt4qCMMkGaF+QIN5+ILuIRg4YpcB7weGq+Au2DGeVa85XPZN65NLSBS dXgg0AQefCJDr6V/lQzJrBMgvW8/YcuHL+g6MjxLx+NZJg4BkI7AHsOKKqOW4Y+X1Co/ 6UFg== 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=tKdIWG8Ko+/VYotBZ/EE6HR2yUBVPr5g8z4sbrWCXFo=; b=oZbjYqaqao/VdEhZlxGMs0XJFg4yozBTORZW2y8NPlkARxNobSHG2i+0OX4pRsKBlp KedgFZj8YNoh8zrrjLFxpVFzxFv7SWY2N+mDQ0qPQD46QVl+u9s/6X7wwclX+SCMm07q W2x5Mwuod8rOPBnE8Lx4mfY5NR10xgCYU33CebkBJ8FlzQ7nrDz5j8c+Y+CmL49WVCPT HEw6djC9c1PWH6UQLFmOHVJ72Iwyx7xjAyHXYsfQUAyvsUNmNCBCMXTRKUehOHEJhm6/ ogFI6K5L8a2ldzfX2rRPJISHtH9f4jEqIQQhOOdEg+G7qGUHmUFk9I4xZJlN5QUywVuB NyZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@roeck-us.net header.s=default header.b=jF7pjhL8; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id kk17-20020a17090b4a1100b001bd14e030d8si2403062pjb.176.2022.03.30.21.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 21:57:43 -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=fail header.i=@roeck-us.net header.s=default header.b=jF7pjhL8; 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2275C23C0FC; Wed, 30 Mar 2022 20:36:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238645AbiC3PPG (ORCPT + 99 others); Wed, 30 Mar 2022 11:15:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348028AbiC3PPD (ORCPT ); Wed, 30 Mar 2022 11:15:03 -0400 Received: from gateway24.websitewelcome.com (gateway24.websitewelcome.com [192.185.50.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C519108BC7 for ; Wed, 30 Mar 2022 08:13:17 -0700 (PDT) Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 3C7254248B for ; Wed, 30 Mar 2022 10:13:17 -0500 (CDT) Received: from 162-215-252-75.unifiedlayer.com ([208.91.199.152]) by cmsmtp with SMTP id Za0bnlW7dRnrrZa0bnvR77; Wed, 30 Mar 2022 10:13:17 -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=tKdIWG8Ko+/VYotBZ/EE6HR2yUBVPr5g8z4sbrWCXFo=; b=jF7pjhL8GAP5daoECdGSEUYCUB Wa4O4ybzLTj9AHumGQbxQgDCqCemhreXrmi80zX16rayqFWxRffhifw1l0RC9OqDjiBPvEDCGZMM3 1Jz8MnIXq+EY5ubTrCE738JUEsS2LY9Kc2hF+iVL46iFqisGj4RJ1nW+Cn50wPAVslUZRr12OizEs E/E5SAvTqIfv0f50WGuqjNVMxitaZlDdZkywsSFAqNKE80E1m5s9eiFprbtPut27XX8kVVZb76f/s Ll8S/XPFJ44OjBnjFPeoTmUzbSV5DNQTEP4p4knDLw/L4jMRySkfVqjtUoxPPqxjJDIGOn7RzNuF2 UD+ZBxKQ==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:54568) 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 1nZa0a-002qf7-E6; Wed, 30 Mar 2022 15:13:16 +0000 Message-ID: <795b9b2d-1d6b-359c-ef12-f25c6b3472be@roeck-us.net> Date: Wed, 30 Mar 2022 08:13:14 -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: David Laight , 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: <20220329160730.3265481-1-michael@walle.cc> <20220329160730.3265481-2-michael@walle.cc> <75093b82-4625-d806-a4ea-372b74e60c3b@roeck-us.net> <02545bf1c21b45f78eba5e8b37951748@AcuMS.aculab.com> From: Guenter Roeck Subject: Re: [PATCH v2 1/5] hwmon: introduce hwmon_sanitize_name() In-Reply-To: <02545bf1c21b45f78eba5e8b37951748@AcuMS.aculab.com> 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: 1nZa0a-002qf7-E6 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 108-223-40-66.lightspeed.sntcca.sbcglobal.net [108.223.40.66]:54568 X-Source-Auth: linux@roeck-us.net X-Email-Count: 2 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:50, David Laight wrote: > From: Guenter Roeck >> Sent: 30 March 2022 15:23 >> On 3/29/22 09:07, 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 >>> +underscore. >> >> That needs more details and deserves its own paragraph. Calling one of >> the functions is only necessary if the original name does or can include >> unsupported characters; an unconditional "should" is therefore a bit >> strong. Also, it is important to mention that the function duplicates >> the name, and that it is the responsibility of the caller to release >> the name if hwmon_sanitize_name() was called and the device is removed. > > More worrying, and not documented, is that the buffer 'name' points > to must persist. > You mean the name argument passed to the hwmon registration functions ? That has been the case forever, and I don't recall a single problem with it. If it disturbs you, please feel free to submit a patch adding more details to the documentation. I would not want to change the code and always copy the name because in almost all cases it _is_ a fixed string, and duplicating it would have no value. > ISTM that the kmalloc() in __hwmon_device_register() should include > space for a copy of the name. > It can then do what it will with whatever is passed in. > Whatever is passed in is what the user wants. Registration functions don't change the name. Providing a valid name is the responsibility of the caller. > Oh yes, it has my 'favourite construct': if (!strlen(name)) ... > (well str[strlen(str)] = 0 also happens!) > Sorry, I don't understand what the problem is here. Thanks, Guenter