From: David Laight <David.Laight@ACULAB.COM>
To: 'Xu Yilun' <yilun.xu@intel.com>, Michael Walle <michael@walle.cc>
Cc: Tom Rix <trix@redhat.com>, Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>, Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: RE: [PATCH v2 1/5] hwmon: introduce hwmon_sanitize_name()
Date: Wed, 30 Mar 2022 10:11:39 +0000 [thread overview]
Message-ID: <5029cf18c9df4fab96af13c857d2e0ef@AcuMS.aculab.com> (raw)
In-Reply-To: <20220330065047.GA212503@yilunxu-OptiPlex-7050>
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 <michael@walle.cc>
> > ---
> > 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)
next prev parent reply other threads:[~2022-03-30 10:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-29 16:07 [PATCH v2 0/5] hwmon: introduce hwmon_sanitize() Michael Walle
2022-03-29 16:07 ` [PATCH v2 1/5] hwmon: introduce hwmon_sanitize_name() Michael Walle
2022-03-30 2:57 ` David Laight
2022-03-30 3:46 ` Guenter Roeck
2022-03-30 9:20 ` David Laight
2022-03-30 13:58 ` Andrew Lunn
2022-03-30 6:50 ` Xu Yilun
2022-03-30 10:11 ` David Laight [this message]
2022-03-30 14:51 ` Xu Yilun
2022-03-30 15:23 ` Guenter Roeck
2022-03-31 14:45 ` Russell King (Oracle)
2022-03-31 14:51 ` Michael Walle
2022-03-31 14:58 ` Russell King (Oracle)
2022-03-31 15:12 ` Michael Walle
2022-03-31 17:11 ` Guenter Roeck
2022-03-30 14:23 ` Guenter Roeck
2022-03-30 14:50 ` David Laight
2022-03-30 15:13 ` Guenter Roeck
2022-03-29 16:07 ` [PATCH v2 2/5] hwmon: intel-m10-bmc-hwmon: use devm_hwmon_sanitize_name() Michael Walle
2022-03-30 6:52 ` Xu Yilun
2022-03-29 16:07 ` [PATCH v2 3/5] net: sfp: use hwmon_sanitize_name() Michael Walle
2022-03-30 19:40 ` Russell King (Oracle)
2022-03-31 14:46 ` Russell King (Oracle)
2022-03-29 16:07 ` [PATCH v2 4/5] net: phy: nxp-tja11xx: use devm_hwmon_sanitize_name() Michael Walle
2022-03-29 16:07 ` [PATCH RFC v2 5/5] hwmon: move hwmon_is_bad_char() into core Michael Walle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5029cf18c9df4fab96af13c857d2e0ef@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=hkallweit1@gmail.com \
--cc=jdelvare@suse.com \
--cc=kuba@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=linux@roeck-us.net \
--cc=michael@walle.cc \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=trix@redhat.com \
--cc=yilun.xu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox