Skip to contentSkip to conversation

dt-bindings: power: supply: bq27xxx: Add BQ27Z558

PATCH Superseded Prachoday Sutar 2 participants 2 messages Nov 26

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dt-bindings: power: supply: bq27xxx: Add BQ27Z558

The TI BQ27Z558 is a single-cell fuel gauge documented in the same Technical Reference Manual as the BQ27Z561-R2 (SLUUC54). It uses the same standard command set and register layout as the BQ27Z561, which is already supported by the bq27xxx driver.

Add a compatible for the BQ27Z558 with "ti,bq27z561" as the fallback, so the existing driver binds without any code changes.

---
Tested on a Kneron KL630-based board with a BQ27Z558, using a vendor Linux 4.9 kernel with the upstream BQ27Z561 support backported to bq27xxx. Voltage, current, capacity, status and temperature read correctly through /sys/class/power_supply.

 .../bindings/power/supply/bq27xxx.yaml        | 72 ++++++++++---------
 1 file changed, 38 insertions(+), 34 deletions(-)
Documentation/devicetree/bindings/power/supply/bq27xxx.yaml +38 -34
index be0f1f729..28b04732e 100644
@@ -18,40 +18,44 @@ description: |
 
 properties:
   compatible:
-    enum:
-      - ti,bq27200
-      - ti,bq27210
-      - ti,bq27500 # deprecated, use revision specific property below
-      - ti,bq27510 # deprecated, use revision specific property below
-      - ti,bq27520 # deprecated, use revision specific property below
-      - ti,bq27500-1
-      - ti,bq27510g1
-      - ti,bq27510g2
-      - ti,bq27510g3
-      - ti,bq27520g1
-      - ti,bq27520g2
-      - ti,bq27520g3
-      - ti,bq27520g4
-      - ti,bq27521
-      - ti,bq27530
-      - ti,bq27531
-      - ti,bq27541
-      - ti,bq27542
-      - ti,bq27546
-      - ti,bq27742
-      - ti,bq27545
-      - ti,bq27411
-      - ti,bq27421
-      - ti,bq27425
-      - ti,bq27426
-      - ti,bq27441
-      - ti,bq27621
-      - ti,bq27z561
-      - ti,bq27z746
-      - ti,bq28z610
-      - ti,bq28z620
-      - ti,bq34z100
-      - ti,bq78z100
+    oneOf:
+      - enum:
+          - ti,bq27200
+          - ti,bq27210
+          - ti,bq27500 # deprecated, use revision specific property below
+          - ti,bq27510 # deprecated, use revision specific property below
+          - ti,bq27520 # deprecated, use revision specific property below
+          - ti,bq27500-1
+          - ti,bq27510g1
+          - ti,bq27510g2
+          - ti,bq27510g3
+          - ti,bq27520g1
+          - ti,bq27520g2
+          - ti,bq27520g3
+          - ti,bq27520g4
+          - ti,bq27521
+          - ti,bq27530
+          - ti,bq27531
+          - ti,bq27541
+          - ti,bq27542
+          - ti,bq27546
+          - ti,bq27742
+          - ti,bq27545
+          - ti,bq27411
+          - ti,bq27421
+          - ti,bq27425
+          - ti,bq27426
+          - ti,bq27441
+          - ti,bq27621
+          - ti,bq27z561
+          - ti,bq27z746
+          - ti,bq28z610
+          - ti,bq28z620
+          - ti,bq34z100
+          - ti,bq78z100
+      - items:
+          - const: ti,bq27z558
+          - const: ti,bq27z561
 
   reg:
     maxItems: 1
Signature · 1 line
2.53.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] dt-bindings: power: supply: bq27xxx: NULL deref in bq27xxx_battery_i2c_probe() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] dt-bindings: power: supply: bq27xxx: NULL deref in bq27xxx_battery_i2c_probe()
--

commit 54d1a3afdd53a67243b18d9017c27b2cdf3485cd
Author: Prachoday Sutar <[email protected]>

dt-bindings: power: supply: bq27xxx: Add BQ27Z558

This commit adds the "ti,bq27z558" compatible string to the bq27xxx fuel gauge device tree binding with "ti,bq27z561" as a fallback.

Quoted 8 lines
Documentation/devicetree/bindings/power/supply/bq27xxx.yaml +0 -0
index be0f1f7292c8f..28b04732e08d9 100644
@@ -18,40 +18,44 @@ description: |
 
 properties:
   compatible:

[ ... ]

Documentation/devicetree/bindings/power/supply/bq27xxx.yaml description: | · line 61

Quoted 6 lines
Documentation/devicetree/bindings/power/supply/bq27xxx.yaml +3 -0
+      - items:
+          - const: ti,bq27z558
+          - const: ti,bq27z561
 
   reg:
     maxItems: 1

[Severity: High]
Does binding via the "ti,bq27z561" fallback trigger a NULL pointer dereference in bq27xxx_battery_i2c_probe()?

When the I2C core creates the client from Device Tree, of_i2c_get_board_info() -> of_alias_from_compatible() populates client->name from the first compatible string ("bq27z558"). During probe, bq27xxx_battery_i2c_of_match_table matches the "ti,bq27z561" fallback, but its entries do not set .data:

drivers/power/supply/bq27xxx_battery_i2c.c:bq27xxx_battery_i2c_probe() {
	const struct i2c_device_id *id = i2c_client_get_device_id(client);
	...
	name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%ld", id->name, num);
	...
	di->chip = id->driver_data;
}

Because "bq27z558" is not in bq27xxx_i2c_id_table, i2c_client_get_device_id(client) returns NULL and probe crashes dereferencing id->name and id->driver_data.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1