Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2221393pxb; Wed, 30 Mar 2022 19:47:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbsnqL2zmbeZu1PxT84MLohvvO/Krl4H1PD6LRnt32Nfmm7MNinccVdBIn4x7GVGnOmEIS X-Received: by 2002:a63:185c:0:b0:381:10:2843 with SMTP id 28-20020a63185c000000b0038100102843mr8744272pgy.433.1648694858523; Wed, 30 Mar 2022 19:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648694858; cv=none; d=google.com; s=arc-20160816; b=d9njdqq2ADe2kB9k8q39PUTBWnH1qE4oOnuHCZxlUynAz83cqMWcQI2bBprSPq6E1W r+gngUNKRltIt6ZtMqy/J3gOX4D0toTbE93Tx6PTEjjtj0548p8+jEOaCOk0dWY+4a8p j4kzlg8zJz33AWbxe/gRJCEn8KQSOT8WiwA9OfAKD5dzOR6LfRemp8ogx185V3OAtojp SrFCMc6wvB060eBEDsngy5wl1MZwBHtJlC3hQivdmGZPwb7ryQnG/77JJkhSqMSioOGy BsNLsUlB7bqyZcB+5RKMTlWs4rlL8AXgw8RrMtcekdHAiElAcGha7tnhZrbGfUatfo0M OQpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=+aPZJK3JTwjBtLGTHdURjpzTYJYEesiDAVtt+japMcw=; b=TokkSKr2ocDNlTAZmR6zgQ+wwVJuNcnN3UhwP5QQbwse6mPEgnZ8UG3xoUlJQbTgly xfj4e2jZx/Unn+E7nKYFCPc21gVb36bMqA/jRke94CqtQhDrR/E4Vlt6dnE3Qae5k5jx CpkKveCBqNoJlLCeRAzMJ1f3X5VifexNRamLnJ423FsS0qRf8BaAc7YL1ap9GeT/mWNM 5OdZyhvsfY7VYodyKRJxYcDtcOMW3E+3KdQGD9T7J2/DO2StA7FSiGqCsRFL4gk+WQhW WwYoHslLgE+WQnRxHA/WL9WtV+TCfND95DNok46JD1nBEHi8geaVQLLL51as2ltovi/5 ir2A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t63-20020a635f42000000b0039858110984si13536559pgb.879.2022.03.30.19.47.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 19:47:38 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 01BA3B91BA; Wed, 30 Mar 2022 19:37:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245232AbiC3KNe convert rfc822-to-8bit (ORCPT + 99 others); Wed, 30 Mar 2022 06:13:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245228AbiC3KNa (ORCPT ); Wed, 30 Mar 2022 06:13:30 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5CA5A165B9F for ; Wed, 30 Mar 2022 03:11:44 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-304-oB4kqtPMMA6uQJEujX6CkA-1; Wed, 30 Mar 2022 11:11:41 +0100 X-MC-Unique: oB4kqtPMMA6uQJEujX6CkA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 30 Mar 2022 11:11:39 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.033; Wed, 30 Mar 2022 11:11:39 +0100 From: David Laight To: 'Xu Yilun' , Michael Walle CC: 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() Thread-Topic: [PATCH v2 1/5] hwmon: introduce hwmon_sanitize_name() Thread-Index: AQHYRAJ8rIB0cQMH/kajVzJ0H3I8wazXtB2w Date: Wed, 30 Mar 2022 10:11:39 +0000 Message-ID: <5029cf18c9df4fab96af13c857d2e0ef@AcuMS.aculab.com> References: <20220329160730.3265481-1-michael@walle.cc> <20220329160730.3265481-2-michael@walle.cc> <20220330065047.GA212503@yilunxu-OptiPlex-7050> In-Reply-To: <20220330065047.GA212503@yilunxu-OptiPlex-7050> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 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. (I'm assuming that the 'const char *name' parameter doesn't have to be persistent - that would be another bug just waiting to happen.) Seems really pointless to be do a kmalloc() just to pass a string into a function. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)