All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matwey V. Kornilov" <matwey@sai.msu.ru>
To: Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Javier Martinez Canillas <javier@osg.samsung.com>,
	linux-hwmon@vger.kernel.org (open list:HARDWARE MONITORING),
	linux-kernel@vger.kernel.org (open list)
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Matwey V. Kornilov" <matwey@sai.msu.ru>
Subject: [PATCH v4 4/4] hwmon: lm75: Handle broken device nodes gracefully
Date: Sat,  6 Feb 2021 12:51:21 +0300	[thread overview]
Message-ID: <20210206095121.20625-5-matwey@sai.msu.ru> (raw)
In-Reply-To: <20210206095121.20625-1-matwey@sai.msu.ru>

There is a logical flaw in lm75_probe() function introduced in

    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>
---
 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 3e4374aa2f99..cd2cda4f557a 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -567,10 +567,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))
-- 
2.26.2


      parent reply	other threads:[~2021-02-06  9:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-30 10:38 [PATCH 1/2] hwmon: lm75: Add NXP LM75A to of_match list Matwey V. Kornilov
2021-01-30 10:38 ` [PATCH 2/2] hwmon: lm75: Add another name for NXP LM75B " Matwey V. Kornilov
2021-01-30 15:41 ` [PATCH 1/2] hwmon: lm75: Add NXP LM75A " Guenter Roeck
     [not found]   ` <CAJs94EbBAK1LAZt4pfbzbUCxJtRo8kTAxdaN=y_gRbuvX0rz8Q@mail.gmail.com>
2021-02-03 19:57     ` Guenter Roeck
2021-02-06  9:51       ` [PATCH v4 0/4] hwmon: lm75: Handle broken device nodes gracefully Matwey V. Kornilov
2021-02-06  9:51         ` [PATCH v4 1/4] hwmon: lm75: Add lm75 to of_match list Matwey V. Kornilov
2021-02-06 16:46           ` Guenter Roeck
2021-02-10 19:47             ` Rob Herring
2021-02-06  9:51         ` [PATCH v4 2/4] hwmon: lm75: Add nxp,lm75a " Matwey V. Kornilov
2021-02-06 16:48           ` Guenter Roeck
2021-02-06 16:54             ` Guenter Roeck
2021-02-06  9:51         ` [PATCH v4 3/4] hwmon: lm75: Add ti,lm75 " Matwey V. Kornilov
2021-02-06 16:54           ` Guenter Roeck
2021-02-06  9:51         ` Matwey V. Kornilov [this message]

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=20210206095121.20625-5-matwey@sai.msu.ru \
    --to=matwey@sai.msu.ru \
    --cc=javier@osg.samsung.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --subject='Re: [PATCH v4 4/4] hwmon: lm75: Handle broken device nodes gracefully' \
    /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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.