hwmon: (lm90) Switch channel parsing to fwnode APIs
Subsystems (2)
PATCH v2 1/1 hwmon: (lm90) Switch channel parsing to fwnode APIs
Replace OF property handling with fwnode in the probe function to read the channels properties, improving the driver compatibility since this method is not limited to Device Tree only.
Add also the needed headers for explicit include and clean up related function naming.
---
Changes in v2:
- Remove <linux/mod_devicetable.h> as suggested by Uwe Kleine-Konig.
- Link to v1: https://lore.kernel.org/all/[email protected]/
drivers/hwmon/lm90.c | 47 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-)
drivers/hwmon/lm90.c +22 -25
@@ -101,6 +101,7 @@#include <linux/bits.h> #include <linux/device.h> #include <linux/err.h> +#include <linux/fwnode.h> #include <linux/i2c.h> #include <linux/init.h> #include <linux/interrupt.h>
@@ -108,7 +109,7 @@#include <linux/hwmon.h> #include <linux/kstrtox.h> #include <linux/module.h> -#include <linux/of.h> +#include <linux/property.h> #include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/workqueue.h>
@@ -295,7 +296,7 @@ static const struct i2c_device_id lm90_id[] = { };MODULE_DEVICE_TABLE (i2c, lm90_id); -static const struct of_device_id __maybe_unused lm90_of_match[] = { +static const struct of_device_id lm90_of_match[] = { { .compatible ="adi,adm1032" , .data = (void *)adm1032
@@ -2602,7 +2603,6 @@ static void lm90_stop_work(void *_data)static int lm90_init_client (struct i2c_client *client,struct lm90_data *data) { -struct device_node *np = client->dev.of_node;int config, convrate;if (data->flags &LM90_HAVE_CONVRATE ) {
@@ -2626,7 +2626,7 @@ static int lm90_init_client(struct i2c_client *client, struct lm90_data *data)/* Check Temperature Range Select */ if (data->flags &LM90_HAVE_EXTENDED_TEMP ) { -if (of_property_read_bool (np,"ti,extended-range-enable" )) +if (device_property_read_bool (&client->dev,"ti,extended-range-enable" )) config |=0x04 ;if (!(config &0x04 )) data->flags &= ~LM90_HAVE_EXTENDED_TEMP ;
@@ -2692,8 +2692,8 @@ static irqreturn_t lm90_irq_thread(int irq, void *dev_id)return IRQ_NONE ; } -static int lm90_probe_channel_from_dt (struct i2c_client *client, -struct device_node *child, +static int lm90_probe_channel (struct i2c_client *client, +struct fwnode_handle *child,struct lm90_data *data) {u32 id;
@@ -2701,27 +2701,27 @@ static int lm90_probe_channel_from_dt(struct i2c_client *client,int err;struct device *dev = &client->dev; - err =of_property_read_u32 (child,"reg" , &id); + err =fwnode_property_read_u32 (child,"reg" , &id);if (err) { -dev_err (dev,"missing reg property of %pOFn\n" , child); +dev_err (dev,"missing reg property of %pfw\n" , child);return err; }if (id >=MAX_CHANNELS ) { -dev_err (dev,"invalid reg property value %d in %pOFn\n" , id, child); +dev_err (dev,"invalid reg property value %d in %pfw\n" , id, child);return -EINVAL ; } - err =of_property_read_string (child,"label" , &data->channel_label[id]); + err =fwnode_property_read_string (child,"label" , &data->channel_label[id]);if (err == -ENODATA || err == -EILSEQ ) { -dev_err (dev,"invalid label property in %pOFn\n" , child); +dev_err (dev,"invalid label property in %pfw\n" , child);return err; }if (data->channel_label[id]) data->channel_config[id] |=HWMON_T_LABEL ; - err =of_property_read_s32 (child,"temperature-offset-millicelsius" , &val); + err =fwnode_property_read_u32 (child,"temperature-offset-millicelsius" , &val);if (!err) {if (id ==0 ) {dev_err (dev,"temperature-offset-millicelsius can't be set for internal channel\n" );
@@ -2739,18 +2739,17 @@ static int lm90_probe_channel_from_dt(struct i2c_client *client,return 0 ; } -static int lm90_parse_dt_channel_info (struct i2c_client *client, -struct lm90_data *data) +static int lm90_parse_channel_info (struct i2c_client *client, +struct lm90_data *data) {int err;struct device *dev = &client->dev; -const struct device_node *np = dev->of_node; -for_each_child_of_node_scoped (np, child) { -if (strcmp (child->name,"channel" )) +device_for_each_child_node_scoped (dev, child) { +if (!fwnode_name_eq (child,"channel" ))continue ; - err =lm90_probe_channel_from_dt (client, child, data); + err =lm90_probe_channel (client, child, data);if (err)return err; }
@@ -2887,12 +2886,10 @@ static int lm90_probe(struct i2c_client *client)/* Set maximum conversion rate */ data->max_convrate = lm90_params[data->kind].max_convrate; -/* Parse device-tree channel information */ -if (client->dev.of_node) { - err =lm90_parse_dt_channel_info (client, data); -if (err) -return err; - } +/* Parse channel information */ + err =lm90_parse_channel_info (client, data); +if (err) +return err;/* Initialize the LM90 chip */ err =lm90_init_client (client, data);
@@ -2985,7 +2982,7 @@ static struct i2c_driver lm90_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "lm90", - .of_match_table = of_match_ptr(lm90_of_match), + .of_match_table = lm90_of_match, .pm = pm_sleep_ptr(&lm90_pm_ops), }, .probe = lm90_probe,
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Low] Incompatible pointer type causing build failure
Pre-existing issues:
- [Critical] Sysfs read triggers NULL pointer dereference via uninitialized hwmon_dev --
--- Patch [1]: [PATCH v2] hwmon: (lm90) Switch channel parsing to fwnode APIs --- commit 3d5d792e5529b3545ccefc21f7dfd9c2acecc999
Author: Flaviu Nistor <[email protected]>
hwmon: (lm90) Switch channel parsing to fwnode APIs
This commit replaces OF property handling with fwnode APIs in the probe function to read channel properties. This improves compatibility by no longer limiting it to Device Tree.
Quoted 4 lines
drivers/hwmon/lm90.c +0
-0
[ ... ]
Quoted 1 line
drivers/hwmon/lm90.c +0
-0@@ -2701,27 +2701,27 @@ static int lm90_probe_channel_from_dt(struct i2c_client *client,
[ ... ]
drivers/hwmon/lm90.c static int lm90_probe_channel_from_dt(struct i2c_client *client, · line 2724
Quoted 2 lines
drivers/hwmon/lm90.c +1
-1- err =of_property_read_s32 (child,"temperature-offset-millicelsius" , &val); + err =fwnode_property_read_u32 (child,"temperature-offset-millicelsius" , &val);
[Severity: Low]
Will this cause a build failure or compiler warning?
In lm90_probe_channel(), val is declared as an s32, but it is being passed to fwnode_property_read_u32() which expects a u32 pointer. This pointer type mismatch can trigger a -Wincompatible-pointer-types error in modern builds.
[ ... ]
Quoted 7 lines
drivers/hwmon/lm90.c +0
-3@@ -2887,12 +2886,10 @@ static int lm90_probe(struct i2c_client *client)/* Set maximum conversion rate */ data->max_convrate = lm90_params[data->kind].max_convrate; -/* Parse device-tree channel information */ -if (client->dev.of_node) { - err =lm90_parse_dt_channel_info (client, data);
drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client) · line 2895
Quoted 10 lines
drivers/hwmon/lm90.c +4
-3-if (err) -return err; - } +/* Parse channel information */ + err =lm90_parse_channel_info (client, data); +if (err) +return err;/* Initialize the LM90 chip */ err =lm90_init_client (client, data);
[Severity: Critical]
This is a pre-existing issue, but does this create a race condition that results in a NULL pointer dereference?
In lm90_probe(), the sysfs files are exposed when calling devm_hwmon_device_register_with_info() later in the function:
hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, &data->chip, NULL); if (IS_ERR(hwmon_dev)) return PTR_ERR(hwmon_dev); data->hwmon_dev = hwmon_dev;
If an unprivileged userspace process reads a sysfs attribute before data->hwmon_dev is initialized, it triggers lm90_temp_read(), which schedules data->report_work.
The asynchronous work runs lm90_report_alarms():
struct device *hwmon_dev = data->hwmon_dev; ... if (st & LM90_STATUS_LLOW) hwmon_notify_event(hwmon_dev, hwmon_temp, hwmon_temp_min_alarm, 0);
This would pass the still-NULL hwmon_dev to hwmon_notify_event(), causing a kernel panic. Should data->hwmon_dev be initialized before the device is registered?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v2 1/1 hwmon: (lm90) Switch channel parsing to fwnode APIs
Quoted 39 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 2 potential issue(=
s) to consider:New issues:
- [Low] Incompatible pointer type causing build failurePre-existing issues:
- [Critical] Sysfs read triggers NULL pointer dereference via uninitialized=hwmon_dev
----- Patch [1]: [PATCH v2] hwmon: (lm90) Switch channel parsing to fwnode AP= Is ---
commit3d5d792e5529b3545ccefc21f7dfd9c2acecc999
Author: Flaviu Nistor <[email protected]>hwmon: (lm90) Switch channel parsing to fwnode APIs
=20
This commit replaces OF property handling with fwnode APIs in the probe function to read channel properties. This improves compatibility by no long= er
limiting it to Device Tree..com/
Quoted 4 lines
drivers/hwmon/lm90.c +0
-0[ ... ]
drivers/hwmon/lm90.c static int lm90_probe_channel_from_dt(struct i2c_=
Quoted 1 line
drivers/hwmon/lm90.c +0
-0@@ -2701,27 +2701,27 @@ static int lm90_probe_channel_from_dt(struct i2c_=client *client,
[ ... ]drivers/hwmon/lm90.c static int lm90_probe_channel_from_dt(struct i2c_= · line 2702
Quoted 3 lines
drivers/hwmon/lm90.c +1
-1-=09err =3D of_property_read_s32(child, "temperature-offset-millicelsius"= , &val); +=09err =3D fwnode_property_read_u32(child, "temperature-offset-millicels=ius", &val);
Quoted 7 lines
[Severity: Low]
Will this cause a build failure or compiler warning?In
lm90_probe_channel(), val is declared as an s32, but it is being passed tofwnode_property_read_u32()which expects a u32 pointer. This pointer typ= e
mismatch can trigger a -Wincompatible-pointer-types error in modern builds.
This is absolutely true and I can't understand how this got into the patch since I have test is. I will send a v3 correcting s32 to u32.
Sorry for this!
Best regards,
Flaviu
PATCH v2 1/1 hwmon: (lm90) Switch channel parsing to fwnode APIs
On Fri, 17 Jul 2026 10:06, Flaviu Nistor wrote
Quoted 48 lines · sashiko-bot
Quoted 39 lines
Thank you for your contribution! Sashiko AI review found 2 potential issue(=
s) to consider:New issues:
- [Low] Incompatible pointer type causing build failurePre-existing issues:
- [Critical] Sysfs read triggers NULL pointer dereference via uninitialized=hwmon_dev
----- Patch [1]: [PATCH v2] hwmon: (lm90) Switch channel parsing to fwnode AP= Is ---
commit3d5d792e5529b3545ccefc21f7dfd9c2acecc999
Author: Flaviu Nistor <[email protected]>hwmon: (lm90) Switch channel parsing to fwnode APIs
=20
This commit replaces OF property handling with fwnode APIs in the probe function to read channel properties. This improves compatibility by no long= er
limiting it to Device Tree..com/
Quoted 4 lines
drivers/hwmon/lm90.c +0
-0[ ... ]
drivers/hwmon/lm90.c static int lm90_probe_channel_from_dt(struct i2c_=
Quoted 1 line
drivers/hwmon/lm90.c +0
-0@@ -2701,27 +2701,27 @@ static int lm90_probe_channel_from_dt(struct i2c_=client *client,
[ ... ]drivers/hwmon/lm90.c static int lm90_probe_channel_from_dt(struct i2c_= · line 2702
Quoted 3 lines
drivers/hwmon/lm90.c +1
-1-=09err =3D of_property_read_s32(child, "temperature-offset-millicelsius"= , &val); +=09err =3D fwnode_property_read_u32(child, "temperature-offset-millicels=ius", &val);
Quoted 7 lines
[Severity: Low]
Will this cause a build failure or compiler warning?In
lm90_probe_channel(), val is declared as an s32, but it is being passed tofwnode_property_read_u32()which expects a u32 pointer. This pointer typ= e
mismatch can trigger a -Wincompatible-pointer-types error in modern builds.
Quoted 7 lines
This is absolutely true and I can't understand how this got into the patch since I have test is. I will send a v3 correcting s32 to u32.
Sorry for this!Best regards,
Flaviu
I have double checked and there is no warning or error when building the driver. Please ignore my previews reply as v2 can be used. I had in mind something different and it looks like not a great morning start. I am sorry for the noise on the mailing list.
Best regards,
Flaviu
Guenter Roeck
maintainerQuoted 53 lines · Flaviu Nistor
On Fri, 17 Jul 2026 10:06, Flaviu Nistor wrote
Quoted 52 lines · sashiko-bot
Quoted 39 lines
Thank you for your contribution! Sashiko AI review found 2 potential issue(=
s) to consider:New issues:
- [Low] Incompatible pointer type causing build failurePre-existing issues:
- [Critical] Sysfs read triggers NULL pointer dereference via uninitialized=hwmon_dev
----- Patch [1]: [PATCH v2] hwmon: (lm90) Switch channel parsing to fwnode AP= Is ---
commit3d5d792e5529b3545ccefc21f7dfd9c2acecc999
Author: Flaviu Nistor <[email protected]>hwmon: (lm90) Switch channel parsing to fwnode APIs
=20
This commit replaces OF property handling with fwnode APIs in the probe function to read channel properties. This improves compatibility by no long= er
limiting it to Device Tree..com/
Quoted 4 lines
drivers/hwmon/lm90.c +0
-0[ ... ]
drivers/hwmon/lm90.c static int lm90_probe_channel_from_dt(struct i2c_=
Quoted 1 line
drivers/hwmon/lm90.c +0
-0@@ -2701,27 +2701,27 @@ static int lm90_probe_channel_from_dt(struct i2c_=client *client,
[ ... ]drivers/hwmon/lm90.c static int lm90_probe_channel_from_dt(struct i2c_= · line 2702
Quoted 3 lines
drivers/hwmon/lm90.c +1
-1-=09err =3D of_property_read_s32(child, "temperature-offset-millicelsius"= , &val); +=09err =3D fwnode_property_read_u32(child, "temperature-offset-millicels=ius", &val);
Quoted 7 lines
[Severity: Low]
Will this cause a build failure or compiler warning?In
lm90_probe_channel(), val is declared as an s32, but it is being passed tofwnode_property_read_u32()which expects a u32 pointer. This pointer typ= e
mismatch can trigger a -Wincompatible-pointer-types error in modern builds.This is absolutely true and I can't understand how this got into the patch since I have test is. I will send a v3 correcting s32 to u32.
Sorry for this!
Quoted 8 lines
Quoted 3 lines
Best regards,
FlaviuI have double checked and there is no warning or error when building the driver. Please ignore my previews reply as v2 can be used. I had in mind something different and it looks like not a great morning start. I am sorry for the noise on the mailing list.
So how do you expect the driver to handle negative temperature offsets ? By silently auto-converting it to s32 and hoping that the firmware core handles it correctly ?
Yes, I know, of_property_read_s32() maps to of_property_read_u32(), but the API at least suggests that signed values are handled correctly. That is not the case with fwnode_property_read_u32().
Guenter
Guenter Roeck
maintainerQuoted 17 lines · Flaviu Nistor
Replace OF property handling with fwnode in the probe function to read the channels properties, improving the driver compatibility since this method is not limited to Device Tree only.
Add also the needed headers for explicit include and clean up related function naming.Signed-off-by Flaviu Nistor <[email protected]>---
Changes in v2:
- Remove <linux/mod_devicetable.h> as suggested by Uwe Kleine-Konig.
- Link to v1: https://lore.kernel.org/all/[email protected]/drivers/hwmon/lm90.c | 47 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-)drivers/hwmon/lm90.c +0
-0
...
drivers/hwmon/lm90.c static int lm90_probe_channel_from_dt(struct i2c_client *client, · line 2724
Quoted 2 lines
drivers/hwmon/lm90.c +1
-1- err =of_property_read_s32 (child,"temperature-offset-millicelsius" , &val); + err =fwnode_property_read_u32 (child,"temperature-offset-millicelsius" , &val);
I understand you consider it to be irrelevant, but temperature offsets can be negative. Please explain how this is handled.
Thanks,
Guenter
Quoted 20 lines · Guenter Roeck
Quoted 17 lines · Flaviu Nistor
Replace OF property handling with fwnode in the probe function to read the channels properties, improving the driver compatibility since this method is not limited to Device Tree only.
Add also the needed headers for explicit include and clean up related function naming.Signed-off-by Flaviu Nistor <[email protected]>---
Changes in v2:
- Remove <linux/mod_devicetable.h> as suggested by Uwe Kleine-Konig.
- Link to v1: https://lore.kernel.org/all/[email protected]/drivers/hwmon/lm90.c | 47 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-)drivers/hwmon/lm90.c +0
-0...
Quoted 6 lines
drivers/hwmon/lm90.c static int lm90_probe_channel_from_dt(struct i2c_client *client, · line 2724
Quoted 2 lines
drivers/hwmon/lm90.c +1
-1- err =of_property_read_s32 (child,"temperature-offset-millicelsius" , &val); + err =fwnode_property_read_u32 (child,"temperature-offset-millicelsius" , &val);I understand you consider it to be irrelevant, but temperature offsets can be negative. Please explain how this is handled.
It is no about the fact that I consider it irrelevant, but rather I was mislead that of_property_read_s32 maps to of_property_read_u32(), and the new fwnode API does not have a dedicated function for signed values.
I see as a solution to add a similar approach to include/linux/property.h. Add a new fwnode_property_read_s32 that maps to fwnode_property_read_u32, and then use it in the driver. I will try to send a new patch series to have a working solution.
Thanks and best regards,
Flaviu
Quoted 2 lines
Thanks,
Guenter
Guenter Roeck
maintainerQuoted 28 lines · Flaviu Nistor
Quoted 20 lines · Guenter Roeck
Quoted 17 lines · Flaviu Nistor
Replace OF property handling with fwnode in the probe function to read the channels properties, improving the driver compatibility since this method is not limited to Device Tree only.
Add also the needed headers for explicit include and clean up related function naming.Signed-off-by Flaviu Nistor <[email protected]>---
Changes in v2:
- Remove <linux/mod_devicetable.h> as suggested by Uwe Kleine-Konig.
- Link to v1: https://lore.kernel.org/all/[email protected]/drivers/hwmon/lm90.c | 47 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-)drivers/hwmon/lm90.c +0
-0...
Quoted 6 lines
drivers/hwmon/lm90.c static int lm90_probe_channel_from_dt(struct i2c_client *client, · line 2724
Quoted 2 lines
drivers/hwmon/lm90.c +1
-1- err =of_property_read_s32 (child,"temperature-offset-millicelsius" , &val); + err =fwnode_property_read_u32 (child,"temperature-offset-millicelsius" , &val);I understand you consider it to be irrelevant, but temperature offsets can be negative. Please explain how this is handled.
Quoted 7 lines
It is no about the fact that I consider it irrelevant, but rather I was mislead that
of_property_read_s32maps toof_property_read_u32(), and the new fwnode API does not have a dedicated function for signed values.
I see as a solution to add a similar approach toinclude/linux/property.h. Add a newfwnode_property_read_s32that maps tofwnode_property_read_u32, and then use it in the driver. I will try to send a new patch series to have a working solution.
Type casting in the driver and adding a comment explaining the reason would be perfectly fine. What is not ok is to silently ignore it. Also, it will need to be tested if it is working as intended. For of_property_read_s32() we can assume that it works since there is an API function. That is not the case for the fwnode API, which either means that the fwnode API does not support negative properties or that no one needed and/or tested it.
Guenter