From: Guenter Roeck <linux@roeck-us.net>
To: "Matwey V. Kornilov" <matwey@sai.msu.ru>,
Jean Delvare <jdelvare@suse.com>,
Javier Martinez Canillas <javier@osg.samsung.com>,
"open list:HARDWARE MONITORING" <linux-hwmon@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Cc: matwey.kornilov@gmail.com
Subject: Re: [PATCH v3] hwmon: lm75: Handle broken device nodes gracefully
Date: Tue, 2 Feb 2021 11:29:45 -0800 [thread overview]
Message-ID: <c0cf9573-74bb-fef9-a14b-7a5eef781c4a@roeck-us.net> (raw)
In-Reply-To: <20210202183737.28747-1-matwey@sai.msu.ru>
On 2/2/21 10:37 AM, Matwey V. Kornilov wrote:
> There is a logical flaw in lm75_probe() function introduced in
>
> commit e97a45f1b460 ("hwmon: (lm75) Add OF device ID table")
>
> Note, that of_device_get_match_data() returns NULL when no match
> is found. This is the case when OF node exists but has unknown
> compatible line, while the module is still loaded via i2c
> detection.
>
> arch/powerpc/boot/dts/fsl/p2041rdb.dts:
>
> lm75b@48 {
> compatible = "nxp,lm75a";
> reg = <0x48>;
> };
>
> In this case, the sensor is mistakenly considered as ADT75 variant.
>
> Fixes: e97a45f1b460 ("hwmon: (lm75) Add OF device ID table")
> Signed-off-by: Matwey V. Kornilov <matwey@sai.msu.ru>
Looks good, but we'll also need a solution for the existing devicetree
nodes since they are being used. The best solution would probably
be to document and add "nxp,lm75a" to the list of devicetree nodes.
The same applies to other used but not documented compatible strings
(I think you sent a list earlier if I recall correctly).
Sorry that I didn't bring this up earlier, but I am concerned that
if we don't do this, this patch might be considered a regression.
Thanks,
Guenter
> ---
> Changes since v2:
> * fixed typo in the message
> * fixed brackets
>
> drivers/hwmon/lm75.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
> index e447febd121a..53882c334a0d 100644
> --- a/drivers/hwmon/lm75.c
> +++ b/drivers/hwmon/lm75.c
> @@ -561,10 +561,17 @@ static int lm75_probe(struct i2c_client *client)
> int status, err;
> enum lm75_type kind;
>
> - if (client->dev.of_node)
> - kind = (enum lm75_type)of_device_get_match_data(&client->dev);
> - else
> + if (dev->of_node) {
> + const struct of_device_id *match =
> + of_match_device(dev->driver->of_match_table, dev);
> +
> + if (!match)
> + return -ENODEV;
> +
> + kind = (enum lm75_type)(match->data);
> + } else {
> kind = i2c_match_id(lm75_ids, client)->driver_data;
> + }
>
> if (!i2c_check_functionality(client->adapter,
> I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
>
next prev parent reply other threads:[~2021-02-02 19:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-30 10:10 [PATCH] hwmon: lm75: Use zero lm75_type for lm75 Matwey V. Kornilov
2021-01-30 15:31 ` Guenter Roeck
[not found] ` <CAJs94EY=hDwNun_kzNQdMHmC27KEZV6urxcKm9xbHriJ_1m3UQ@mail.gmail.com>
2021-01-30 16:00 ` Guenter Roeck
2021-02-02 14:21 ` [PATCH v2] hwmon: lm75: Handle broken device nodes gracefully Matwey V. Kornilov
2021-02-02 15:08 ` Guenter Roeck
2021-02-02 18:37 ` [PATCH v3] " Matwey V. Kornilov
2021-02-02 19:29 ` Guenter Roeck [this message]
[not found] ` <CAJs94Ea--d7tW6ZYOjMhHsaXAJZjtivazw+0CAopFmNbYsgAgQ@mail.gmail.com>
2021-02-02 20:54 ` 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=c0cf9573-74bb-fef9-a14b-7a5eef781c4a@roeck-us.net \
--to=linux@roeck-us.net \
--cc=javier@osg.samsung.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matwey.kornilov@gmail.com \
--cc=matwey@sai.msu.ru \
/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
all inboxes | Powered by JetHome®