From: Russell King - ARM Linux <linux@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Guenter Roeck <linux@roeck-us.net>,
netdev <netdev@vger.kernel.org>,
Florian Fainelli <f.fainelli@gmail.com>,
vadimp@mellanox.com, linux-hwmon@vger.kernel.org
Subject: Re: [PATCH RFC 2/2] net: phy: sfp: Add HWMON support for module sensors
Date: Fri, 29 Jun 2018 16:47:19 +0100 [thread overview]
Message-ID: <20180629154718.GI17271@n2100.armlinux.org.uk> (raw)
In-Reply-To: <20180629074540.GC11285@lunn.ch>
On Fri, Jun 29, 2018 at 09:45:40AM +0200, Andrew Lunn wrote:
> > > + for (i = j = 0; sfp->hwmon_name[i]; i++) {
> > > + if (isalnum(sfp->hwmon_name[i])) {
> > > + if (i != j)
> > > + sfp->hwmon_name[j] = sfp->hwmon_name[i];
> > > + j++;
> > > + }
> > > + }
> >
> > It might be better and simpler to replace invalid characters with '_'
> > instead of dropping them. Also note that '_' is a valid character.
> > Strictly speaking only "-* \t\n" are invalid.
>
> I borrowed this code from the marvell10g driver. I don't know where it
> borrowed it from. Is there a hwmon core function which we can pass an
> arbitrary name to and it returned a sanitised one? Maybe we should add
> one?
... which in turn came from the marvell driver.
> > > + sfp->hwmon_dev = devm_hwmon_device_register_with_info(sfp->dev,
> > > + sfp->hwmon_name, sfp, &sfp_hwmon_chip_info,
> > > + NULL);
> > > +
> > > + return PTR_ERR_OR_ZERO(sfp->hwmon_dev);
> > > +}
> > > +
> > > +static void sfp_hwmon_remove(struct sfp *sfp)
> > > +{
> > > + devm_hwmon_device_unregister(sfp->hwmon_dev);
> >
> > If registartion and removal are not tied to a device, it doesn't make sense
> > to use devm_ functions. Either use hwmon_device_register_with_info()
> > and hwmon_device_unregister(), or drop the remove function.
>
> Yes. I can change it. We have a few different lifetimes involved
> here. You can consider the driver probe being for the SFP cage. The
> SFP module being inserted into the cage is a different life time, and
> the lifetime of the hwmon device.
It should be the lifetime of the inserted module, since the presence
of the monitoring devices is module dependent - and obviously when
the module is removed, there's no monitoring devices accessible.
Guenter is correct, this should not be using the devm_* functions.
Another point is (I've not checked your original patch for this) is
that we don't want to fail the probe of the SFP module if the hwmon
failed to register - we just need to remember not to try to unregister
an invalid pointer thereby oopsing the kernel.
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up
According to speedtest.net: 8.21Mbps down 510kbps up
next prev parent reply other threads:[~2018-06-29 15:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-28 20:41 [PATCH RFC 0/2] HWMON support for SFP modules Andrew Lunn
2018-06-28 20:41 ` [PATCH RFC 1/2] hwmon: Add support for power min, lcrit, min_alarm and lcrit_alarm Andrew Lunn
2018-06-28 22:42 ` Guenter Roeck
2018-06-29 7:21 ` Andrew Lunn
2018-06-29 17:12 ` Guenter Roeck
2018-06-28 20:41 ` [PATCH RFC 2/2] net: phy: sfp: Add HWMON support for module sensors Andrew Lunn
2018-06-28 22:41 ` Guenter Roeck
2018-06-29 7:45 ` Andrew Lunn
2018-06-29 15:47 ` Russell King - ARM Linux [this message]
2018-06-29 17:34 ` Guenter Roeck
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=20180629154718.GI17271@n2100.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=andrew@lunn.ch \
--cc=f.fainelli@gmail.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=netdev@vger.kernel.org \
--cc=vadimp@mellanox.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;
as well as URLs for NNTP newsgroup(s).