From: David Laight <David.Laight@ACULAB.COM>
To: 'Guenter Roeck' <linux@roeck-us.net>,
Michael Walle <michael@walle.cc>, "Xu Yilun" <yilun.xu@intel.com>,
Tom Rix <trix@redhat.com>, Jean Delvare <jdelvare@suse.com>,
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>
Cc: "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 14:50:02 +0000 [thread overview]
Message-ID: <02545bf1c21b45f78eba5e8b37951748@AcuMS.aculab.com> (raw)
In-Reply-To: <75093b82-4625-d806-a4ea-372b74e60c3b@roeck-us.net>
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 <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
> > +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.
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.
Oh yes, it has my 'favourite construct': if (!strlen(name)) ...
(well str[strlen(str)] = 0 also happens!)
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 14:50 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
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 [this message]
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=02545bf1c21b45f78eba5e8b37951748@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
Powered by JetHome