From: Eduardo Valentin <eduval@amazon.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Eduardo Valentin <eduval@amazon.com>,
Jean Delvare <jdelvare@suse.com>, <linux-hwmon@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] hwmon: core: add thermal sensors only if dev->of_node is present
Date: Wed, 29 May 2019 16:12:56 -0700 [thread overview]
Message-ID: <20190529231256.GB18339@u40b0340c692b58f6553c.ant.amazon.com> (raw)
In-Reply-To: <20190528150821.GB5516@roeck-us.net>
On Tue, May 28, 2019 at 08:08:21AM -0700, Guenter Roeck wrote:
> Hi Eduardo,
>
> On Fri, May 17, 2019 at 04:13:36PM -0700, Eduardo Valentin wrote:
> > Drivers may register to hwmon and request for also registering
> > with the thermal subsystem (HWMON_C_REGISTER_TZ). However,
> > some of these driver, e.g. marvell phy, may be probed from
> > Device Tree or being dynamically allocated, and in the later
> > case, it will not have a dev->of_node entry.
> >
> > Registering with hwmon without the dev->of_node may result in
> > different outcomes depending on the device tree, which may
> > be a bit misleading. If the device tree blob has no 'thermal-zones'
> > node, the *hwmon_device_register*() family functions are going
> > to gracefully succeed, because of-thermal,
> > *thermal_zone_of_sensor_register() return -ENODEV in this case,
> > and the hwmon error path handles this error code as success to
> > cover for the case where CONFIG_THERMAL_OF is not set.
> > However, if the device tree blob has the 'thermal-zones'
> > entry, the *hwmon_device_register*() will always fail on callers
> > with no dev->of_node, propagating -EINVAL.
> >
> > If dev->of_node is not present, calling of-thermal does not
> > make sense. For this reason, this patch checks first if the
> > device has a of_node before going over the process of registering
> > with the thermal subsystem of-thermal interface. And in this case,
> > when a caller of *hwmon_device_register*() with HWMON_C_REGISTER_TZ
> > and no dev->of_node will still register with hwmon, but not with
> > the thermal subsystem. If all the hwmon part bits are in place,
> > the registration will succeed.
> >
> Makes sense. I'd apply it as-is, but it would be better if you resend
> it to the list to give others a chance to comment.
Ok Cool.
Yeah, the patches were copied to the mailing list. Only the cover letter
somehow I forgot to copy the mailing lists while git-sending-email.
I will resend the two patches (and the cover letter) after fixing
the comment on patch 2/2.
>
> Thanks,
> Guenter
>
> > Cc: Jean Delvare <jdelvare@suse.com>
> > Cc: Guenter Roeck <linux@roeck-us.net>
> > Cc: linux-hwmon@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Eduardo Valentin <eduval@amazon.com>
> > ---
> > drivers/hwmon/hwmon.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> > index fcdbac4a56e3..6b3559f58b67 100644
> > --- a/drivers/hwmon/hwmon.c
> > +++ b/drivers/hwmon/hwmon.c
> > @@ -619,7 +619,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
> > if (err)
> > goto free_hwmon;
> >
> > - if (dev && chip && chip->ops->read &&
> > + if (dev && dev->of_node && chip && chip->ops->read &&
> > chip->info[0]->type == hwmon_chip &&
> > (chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) {
> > const struct hwmon_channel_info **info = chip->info;
> > --
> > 2.21.0
> >
--
All the best,
Eduardo Valentin
next prev parent reply other threads:[~2019-05-29 23:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190517231337.27859-1-eduval@amazon.com>
2019-05-17 23:13 ` [PATCH 1/2] hwmon: core: add thermal sensors only if dev->of_node is present Eduardo Valentin
2019-05-28 15:08 ` Guenter Roeck
2019-05-29 23:12 ` Eduardo Valentin [this message]
2019-05-17 23:13 ` [PATCH 2/2] hwmon: core: fix potential memory leak in *hwmon_device_register* Eduardo Valentin
2019-05-28 15:06 ` Guenter Roeck
2019-05-29 23:14 ` Eduardo Valentin
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=20190529231256.GB18339@u40b0340c692b58f6553c.ant.amazon.com \
--to=eduval@amazon.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/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).