Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2239379pxb; Wed, 30 Mar 2022 20:22:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwuey98A6VBRyXOgJzsq0RptDg6MeIPqED5ot+0aWqEw8V5oYMP84FjDNAnAnEE17qWJKz X-Received: by 2002:a17:90b:3846:b0:1c6:841b:7470 with SMTP id nl6-20020a17090b384600b001c6841b7470mr3559948pjb.193.1648696929273; Wed, 30 Mar 2022 20:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648696929; cv=none; d=google.com; s=arc-20160816; b=UFmmK/M894q/xz6UanwI+6dsZK1b3wxaib+UAgoqvQDQJ53vUflPchquNvMIryIvn7 kUAFGliHuGy3JPL2gdDCA5qRFnAnP6dbDNJhLj9lb1VHhPvANSYy2esxp1TUfEDAJQ/j ONmvfacqr2neHyy8nZOs0fVxDap8AqK+ptWDEqP8vHS6B6bNa/AQKMiTHmPHaNchixvb P3NQNDQt27mtgLiU+rBET1F7vEfH94i6+ZH1DuWBSXtZ8aFIF2GXFpTHZdyYkdeBkKHc wWztoH98pKO8/gM/vub291AokWBSaqUKdTYFZxhzwLR1KDRhs3dbpW8F/HWOxYSOJ1Go hLtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=YKz4aL+JKiW6rgSYEv60MviEPBoE5fep4aGtEfiE9OI=; b=0uovMNaiuINmJOBzm9rJQO2ykKT62cPHFEZ/uiqlUGdTwIXutZcg8s4+09V466kJ9p VJn68YG71LMroxhs/Za0vNGaEiwdKXp9hP9GkvuQwWh/O90664+pUAkDW5OP7Y28H6yF UTSL8+6emgoBWdcdOZc2aeDozditxPJoaP6R4ZcL6aZII4Ue4epvvc+L3KBsefAvnr4V /AyvJfMtdMG9E+q+Eo8xk/tXKZmIsJHWQwosFFsC/rsfTcMF4wl3u/SdPKvpAVtRX2Uq iYb1WkXtNR3cnRuUN0pAdLI74iKAG19DmUbjhhfO6YKHmossGnFkO2eu7Y63zw1svUo4 APCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ltR2Hb3U; 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=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c142-20020a624e94000000b004fa77892f86si21131961pfb.57.2022.03.30.20.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 20:22:09 -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=@intel.com header.s=Intel header.b=ltR2Hb3U; 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=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 17690111DC0; Wed, 30 Mar 2022 19:52:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242336AbiC3PAm (ORCPT + 99 others); Wed, 30 Mar 2022 11:00:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244697AbiC3PAk (ORCPT ); Wed, 30 Mar 2022 11:00:40 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF8976434; Wed, 30 Mar 2022 07:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648652335; x=1680188335; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=LGbzP3xToIyBP1rsfYxryrKuymJX1Ma/5d6WvH8bQgg=; b=ltR2Hb3UzFADOEWfsrf8Wvr//Fuf9Dcidst4Ozfi0iRCjQG4bP64GxKY JmNjJEQrnDNQrLOkJv5AUFAuj6IZdyER0qLZe5m9uZsYLZWzEf/PM60ae wU4BYaU28zMTNJmrWGfg+MXxABGlyVp1chHq+9vN/T+TzEYUBzt3tt6Iw p30HWtRGSaNLviqj+vbG9chzYNuAUpDeM23YRAp8sfS7tK0QbUmx0Ysp4 /9jTHucDfKAU5/+fDI1H03vYM6vA8+0O7JdeUEcb8R2f7zWYQG7v2zrAD XTwRXx3gzIJJaUIpecYMpyGO50W3H4eu2ubqjWZdGRRjrWtSzGxGD8NNi w==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="241717829" X-IronPort-AV: E=Sophos;i="5.90,222,1643702400"; d="scan'208";a="241717829" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2022 07:58:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,222,1643702400"; d="scan'208";a="565574065" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.135]) by orsmga008.jf.intel.com with ESMTP; 30 Mar 2022 07:58:50 -0700 Date: Wed, 30 Mar 2022 22:51:37 +0800 From: Xu Yilun To: David Laight Cc: Michael Walle , Tom Rix , Jean Delvare , Guenter Roeck , 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" Subject: Re: [PATCH v2 1/5] hwmon: introduce hwmon_sanitize_name() Message-ID: <20220330145137.GA214615@yilunxu-OptiPlex-7050> References: <20220329160730.3265481-1-michael@walle.cc> <20220329160730.3265481-2-michael@walle.cc> <20220330065047.GA212503@yilunxu-OptiPlex-7050> <5029cf18c9df4fab96af13c857d2e0ef@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5029cf18c9df4fab96af13c857d2e0ef@AcuMS.aculab.com> 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,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 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. Thanks, Yilun > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales)