hwmon: lm90: Fix DT channel constraints and reject unsupported channel 2
v2 cover hwmon: lm90: Fix DT channel constraints and reject unsupported channel 2
The intention of this patch series is to fix DT channel constrains in the dt-bindings and inprove the driver to reject unsupported channel 2.
dt-bindings:
Forbid temperature-offset-millicelsius on channel@0 (local sensor). Rejecting of assigning temperature-offset-millicelsius for channel@0 is already implemented in the driver.
Reject channel@2 for compatibles that have only one remote sensor.
driver:
If the sensor have only one remote channel, reject a possible unsupported channel 2 and return an error, similar to miss-assigment of temperature -offset-millicelsius property to channel@0.
Flaviu Nistor (2):
dt-bindings: hwmon: national,lm90: Fix channel constraints for
temperature offset
hwmon: (lm90) Reject channel 2 on chips with only one remote sensor
.../bindings/hwmon/national,lm90.yaml | 28 +++++++++++++++++-- drivers/hwmon/lm90.c | 5 ++++ 2 files changed, 30 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/2 dt-bindings: hwmon: national,lm90: Fix channel constraints for temperature offset
Limit temperature-offset-millicelsius to remote channels only, since channel 0 is local and this property does not apply to it. Channel 2 is only valid on devices with two remote sensors, so reject channel 2 for compatibles that do not support a second remote channel.
---
Changes in v2:
- Use else statement in if/then block as suggested by Conor Dooley.
- Link to v1: https://lore.kernel.org/all/[email protected]/
.../bindings/hwmon/national,lm90.yaml | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/hwmon/national,lm90.yaml +25 -3
@@ -113,6 +113,23 @@ allOf: properties: ti,extended-range-enable: false + - if: + not: + properties: + compatible: + contains: + enum: + - adi,adt7481 + - dallas,max6695 + - dallas,max6696 + then: + patternProperties: + "^channel@[0-1]$": + properties: + reg: + enum: [0, 1] + "channel@2": false + - if: properties: compatible:
@@ -134,6 +151,11 @@ allOf: "^channel@([0-2])$": properties: temperature-offset-millicelsius: false + else: + patternProperties: + "channel@0": + properties: + temperature-offset-millicelsius: false - if: properties:
@@ -149,7 +171,7 @@ allOf: - onnn,nct1008 then: patternProperties: - "^channel@([0-2])$": + "^channel@([1-2])$": properties: temperature-offset-millicelsius: maximum: 127750
@@ -172,7 +194,7 @@ allOf: - winbond,w83l771 then: patternProperties: - "^channel@([0-2])$": + "^channel@([1-2])$": properties: temperature-offset-millicelsius: maximum: 127875
@@ -186,7 +208,7 @@ allOf: - ti,tmp461 then: patternProperties: - "^channel@([0-2])$": + "^channel@([1-2])$": properties: temperature-offset-millicelsius: maximum: 127937
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 1/2] dt-bindings: hwmon: national,lm90: Fix channel constraints for temperature offset
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Applying `enum: [0, 1]` directly to the `reg` property breaks dtbs validation because `reg`…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Applying enum: [0, 1] directly to the reg property breaks dtbs validation because reg evaluates as an array. --
commit 962bb439f62765fdf82aa8ab6bf085e5158b3bb7
Author: Flaviu Nistor <[email protected]>
dt-bindings: hwmon: national,lm90: Fix channel constraints for temperature offset
This commit restricts temperature-offset-millicelsius to remote channels and rejects channel 2 for chips with only one remote sensor. It adds conditional schema rules to limit the allowed channels based on the compatible string.
Quoted 13 lines
Documentation/devicetree/bindings/hwmon/national,lm90.yaml +5
-0@@ -113,6 +113,23 @@ allOf: properties: ti,extended-range-enable: false + - if: + not: + properties: + compatible: + contains:
Documentation/devicetree/bindings/hwmon/national,lm90.yaml allOf: · line 130
Quoted 10 lines
Documentation/devicetree/bindings/hwmon/national,lm90.yaml +10
-0+ enum: + - adi,adt7481 + - dallas,max6695 + - dallas,max6696 + then: + patternProperties: + "^channel@[0-1]$": + properties: + reg: + enum: [0, 1]
[Severity: Low]
Does this schema constraint fail validation?
The dt-schema tooling treats reg as an array based on the core schemas. Since this block applies enum: [0, 1] directly to reg, an array value like [0] or [1] will not match the scalar integers 0 or 1 provided in the enum constraint. As a result, valid device tree nodes containing channel@0 or channel@1 could fail make dtbs_check with a type mismatch error.
Should this be constrained inside an items block instead, such as
items: enum: [0, 1]?
Quoted 1 line
Documentation/devicetree/bindings/hwmon/national,lm90.yaml +1
-0+ "channel@2": false
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v2 1/2] dt-bindings: hwmon: national,lm90: Fix channel constraints for temperature offset
In reply to Flaviu NistorQuoted 28 lines · Flaviu Nistor
Limit temperature-offset-millicelsius to remote channels only, since channel 0 is local and this property does not apply to it. Channel 2 is only valid on devices with two remote sensors, so reject channel 2 for compatibles that do not support a second remote channel.
Signed-off-by Flaviu Nistor <[email protected]>---
Changes in v2:
- Use else statement in if/then block as suggested by Conor Dooley.
- Link to v1: https://lore.kernel.org/all/[email protected]/.../bindings/hwmon/national,lm90.yaml | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/hwmon/national,lm90.yaml +6
-0@@ -113,6 +113,23 @@ allOf: properties: ti,extended-range-enable: false + - if: + not: + properties: + compatible: + contains: + enum:
Documentation/devicetree/bindings/hwmon/national,lm90.yaml allOf: · line 131
Quoted 10 lines
Documentation/devicetree/bindings/hwmon/national,lm90.yaml +9
-0+ - adi,adt7481 + - dallas,max6695 + - dallas,max6696 + then: + patternProperties: + "^channel@[0-1]$": + properties: + reg: + enum: [0, 1]
Is this needed? If channel@2 is false, then you won't be able to get to this point to begin with, right?
Conor.
Quoted 47 lines
Documentation/devicetree/bindings/hwmon/national,lm90.yaml +2
-0+ "channel@2": false + - if: properties:compatible:
Documentation/devicetree/bindings/hwmon/national,lm90.yaml +8
-3@@ -134,6 +151,11 @@ allOf: "^channel@([0-2])$": properties: temperature-offset-millicelsius: false + else: + patternProperties: + "channel@0": + properties: + temperature-offset-millicelsius: false - if: properties:@@ -149,7 +171,7 @@ allOf: - onnn,nct1008 then: patternProperties: - "^channel@([0-2])$": + "^channel@([1-2])$": properties: temperature-offset-millicelsius: maximum: 127750@@ -172,7 +194,7 @@ allOf: - winbond,w83l771 then: patternProperties: - "^channel@([0-2])$": + "^channel@([1-2])$": properties: temperature-offset-millicelsius: maximum: 127875@@ -186,7 +208,7 @@ allOf: - ti,tmp461 then: patternProperties: - "^channel@([0-2])$": + "^channel@([1-2])$": properties: temperature-offset-millicelsius: maximum: 127937Signature · 1 line
2.34.1
Conor Dooley
Acked-byRe: [PATCH v2 1/2] dt-bindings: hwmon: national,lm90: Fix channel constraints for temperature offset
Quoted 34 lines · Conor Dooley
Quoted 32 lines · Flaviu Nistor
Limit temperature-offset-millicelsius to remote channels only, since channel 0 is local and this property does not apply to it. Channel 2 is only valid on devices with two remote sensors, so reject channel 2 for compatibles that do not support a second remote channel.
Signed-off-by Flaviu Nistor <[email protected]>---
Changes in v2:
- Use else statement in if/then block as suggested by Conor Dooley.
- Link to v1: https://lore.kernel.org/all/[email protected]/.../bindings/hwmon/national,lm90.yaml | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/hwmon/national,lm90.yaml +10
-0@@ -113,6 +113,23 @@ allOf: properties: ti,extended-range-enable: false + - if: + not: + properties: + compatible: + contains: + enum: + - adi,adt7481 + - dallas,max6695 + - dallas,max6696 + then:
Quoted 8 lines
Documentation/devicetree/bindings/hwmon/national,lm90.yaml allOf: · line 130
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/national,lm90.yaml +5
-0+ patternProperties: + "^channel@[0-1]$": + properties: + reg: + enum: [0, 1]Is this needed? If channel@2 is false, then you won't be able to get to this point to begin with, right?
Hmm, actually keep it. It'd fail dtbs_check but I don't think dt_binding_check fails for channel@0 + reg = <2>
pw-bot: not-applicable
Quoted 50 lines
Conor.
Quoted 47 lines
Documentation/devicetree/bindings/hwmon/national,lm90.yaml +10
-3+ "channel@2": false + - if: properties: compatible:@@ -134,6 +151,11 @@ allOf: "^channel@([0-2])$": properties: temperature-offset-millicelsius: false + else: + patternProperties: + "channel@0": + properties: + temperature-offset-millicelsius: false - if: properties:@@ -149,7 +171,7 @@ allOf: - onnn,nct1008 then: patternProperties: - "^channel@([0-2])$": + "^channel@([1-2])$": properties: temperature-offset-millicelsius: maximum: 127750@@ -172,7 +194,7 @@ allOf: - winbond,w83l771 then: patternProperties: - "^channel@([0-2])$": + "^channel@([1-2])$": properties: temperature-offset-millicelsius: maximum: 127875@@ -186,7 +208,7 @@ allOf: - ti,tmp461 then: patternProperties: - "^channel@([0-2])$": + "^channel@([1-2])$": properties: temperature-offset-millicelsius: maximum: 127937Signature · 1 line
2.34.1
Re: [PATCH v2 1/2] dt-bindings: hwmon: national,lm90: Fix channel constraints for temperature offset
In reply to Flaviu NistorQuoted 7 lines · Flaviu Nistor
Limit temperature-offset-millicelsius to remote channels only, since channel 0 is local and this property does not apply to it. Channel 2 is only valid on devices with two remote sensors, so reject channel 2 for compatibles that do not support a second remote channel.
Signed-off-by Flaviu Nistor <[email protected]>Acked-by Conor Dooley <[email protected]>
Applied.
Thanks,
Guenter
PATCH v2 2/2 hwmon: (lm90) Reject channel 2 on chips with only one remote sensor
In reply to Flaviu NistorValidate firmware channel definitions against chip capabilities and return -EINVAL when channel 2 is configured on devices with 1 remote channel.
--- drivers/hwmon/lm90.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/hwmon/lm90.c +5 -0
@@ -2712,6 +2712,11 @@ static int lm90_probe_channel(struct i2c_client *client,return -EINVAL ; } +if (id ==2 && !(data->flags &LM90_HAVE_TEMP3 )) { +dev_err (dev,"channel %d is not supported for this chip in %pfw\n" , id, child); +return -EINVAL ; + } + err =fwnode_property_read_string (child,"label" , &data->channel_label[id]);if (err == -ENODATA || err == -EILSEQ ) {dev_err (dev,"invalid label property in %pfw\n" , child);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 2/2] hwmon: (lm90) Reject channel 2 on chips with only one remote sensor
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Incorrect format specifier '%d' used for 'u32' variable. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Incorrect format specifier '%d' used for 'u32' variable.
--
commit dbab4ee8e2d548c97ffd31b1a3d640af352905b1
Author: Flaviu Nistor <[email protected]>
hwmon: (lm90) Reject channel 2 on chips with only one remote sensor
This commit validates firmware channel definitions against chip capabilities and returns -EINVAL when channel 2 is configured on devices with 1 remote channel.
drivers/hwmon/lm90.c static int lm90_probe_channel(struct i2c_client *client, · line 2716
Quoted 10 lines
drivers/hwmon/lm90.c +2
-0@@ -2712,6 +2712,11 @@ static int lm90_probe_channel(struct i2c_client *client,return -EINVAL ; } +if (id ==2 && !(data->flags &LM90_HAVE_TEMP3 )) { +dev_err (dev,"channel %d is not supported for this chip in %pfw\n" , id, child);
[Severity: Low]
Does this code use the correct format specifier for the id variable?
While passing an unsigned 32-bit integer to a %d specifier works for small values (since id is guaranteed to be exactly 2 on this path), it is semantically incorrect for a u32 variable and violates format string contracts, leading to potential compiler warnings (-Wformat).
Would it be better to use %u as the format specifier for a u32?
Quoted 4 lines
drivers/hwmon/lm90.c +3
-0+return -EINVAL ; + } + err =fwnode_property_read_string (child,"label" , &data->channel_label[id]);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 2/2] hwmon: (lm90) Reject channel 2 on chips with only one remote sensor
In reply to Flaviu NistorQuoted 4 lines · Flaviu Nistor
Validate firmware channel definitions against chip capabilities and return
-EINVALwhen channel 2 is configured on devices with 1 remote channel.Signed-off-by Flaviu Nistor <[email protected]>
Applied.
Thanks,
Guenter