Skip to contentSkip to conversation

hwmon: (tmp102) Use device_property_read_string API

PATCH Superseded Flaviu Nistor 3 participants 3 messages May 9 Hardware monitoring

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hwmon: (tmp102) Use device_property_read_string API

Replace of_property_read_string() with the preferded device_property_read_string() in the probe function to read the device label property, improving the driver compatibility since this method is not limited to Device Tree only.

---
 drivers/hwmon/tmp102.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hwmon/tmp102.c +3 -2
index 3aa1a3fbeaa9..79578b28a91d 100644
@@ -15,7 +15,8 @@
 #include <linux/jiffies.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
-#include <linux/of.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
 
 #define	DRIVER_NAME "tmp102"
 
@@ -313,7 +314,7 @@ static int tmp102_probe(struct i2c_client *client)
 	if (!tmp102)
 		return -ENOMEM;
 
-	of_property_read_string(dev->of_node, "label", &tmp102->label);
+	device_property_read_string(dev, "label", &tmp102->label);
 
 	i2c_set_clientdata(client, tmp102);
 
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch introduces an implicit header dependency and leaves cross-firmware compatibility…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch introduces an implicit header dependency and leaves cross-firmware compatibility incomplete by retaining the of_match_ptr() macro. --

commit 8699d5dea7c2614372ba1cab8f6b99f73ebebe1e
Author: Flaviu Nistor <[email protected]>
Subject: hwmon: (tmp102) Use device_property_read_string API

This patch replaces of_property_read_string() with device_property_read_string() for reading the device label. It aims to improve compatibility since the new method is not limited to Device Tree.

Quoted 3 lines

improving the driver
compatibility since this method is not limited to
Device Tree only.

If the goal is to improve non-Device Tree compatibility, shouldn't of_match_ptr() also be removed from the i2c_driver struct?

When CONFIG_OF is disabled on ACPI-only platforms, of_match_ptr() evaluates to NULL. This prevents the standard PRP0001 mechanism from matching the driver via compatible strings.

drivers/hwmon/tmp102.c line 19

Quoted 11 lines
drivers/hwmon/tmp102.c +2 -1
index 3aa1a3fbeaa92..79578b28a91d3 100644
@@ -15,7 +15,8 @@
 #include <linux/jiffies.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
-#include <linux/of.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>

Does removing this include create an implicit header dependency?

The code still uses of_match_ptr() further down in the file:

drivers/hwmon/tmp102.c:

static struct i2c_driver tmp102_driver = {
	.driver.name	= DRIVER_NAME,
	.driver.of_match_table = of_match_ptr(tmp102_of_match),
	...
};

Since of_match_ptr() is defined in linux/of.h, the file now relies on another header to implicitly include it. Dropping the of_match_ptr() macro entirely would safely resolve this implicit dependency and fully support the cross-firmware compatibility goal.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
Quoted 46 lines · On 5/9/26 05:28, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch introduces an implicit header dependency and leaves cross-firmware compatibility incomplete by retaining the of_match_ptr() macro. --

commit 8699d5dea7c2614372ba1cab8f6b99f73ebebe1e
Author: Flaviu Nistor <[email protected]>
Subject: hwmon: (tmp102) Use device_property_read_string API

This patch replaces of_property_read_string() with device_property_read_string() for reading the device label. It aims to improve compatibility since the new method is not limited to Device Tree.

Quoted 3 lines

improving the driver
compatibility since this method is not limited to
Device Tree only.

If the goal is to improve non-Device Tree compatibility, shouldn't of_match_ptr() also be removed from the i2c_driver struct?

When CONFIG_OF is disabled on ACPI-only platforms, of_match_ptr() evaluates to NULL. This prevents the standard PRP0001 mechanism from matching the driver via compatible strings.

drivers/hwmon/tmp102.c line 19

Quoted 11 lines
drivers/hwmon/tmp102.c +2 -1
index 3aa1a3fbeaa92..79578b28a91d3 100644
@@ -15,7 +15,8 @@
  #include <linux/jiffies.h>
  #include <linux/regmap.h>
  #include <linux/regulator/consumer.h>
-#include <linux/of.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>

Does removing this include create an implicit header dependency?

The code still uses of_match_ptr() further down in the file:

drivers/hwmon/tmp102.c:

static struct i2c_driver tmp102_driver = {
	.driver.name	= DRIVER_NAME,
	.driver.of_match_table = of_match_ptr(tmp102_of_match),
	...
};
Quoted 5 lines

Since of_match_ptr() is defined in linux/of.h, the file now relies on another header to implicitly include it. Dropping the of_match_ptr() macro entirely would safely resolve this implicit dependency and fully support the cross-firmware compatibility goal.

Please listen. Sashiko told you that you should drop of_match_ptr() already in its feedback to v1.

Guenter