Skip to contentSkip to conversation

Add support for MAX20830 PMBUS

PATCH Superseded Alexis Czezar Torreno 5 participants 12 messages Apr 16 – Apr 17

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Alexis Czezar Torreno

author maintainer
#0 lore raw

v2 cover Add support for MAX20830 PMBUS

This series adds support for the Analog Devices MAX20830 step-down switching regulator with PMBus interface.

The MAX20830 provides 2.7V to 16V input, 0.4V to 5.8V output, and up to 30A output current. It supports monitoring of input/output voltage, output current, and temperature via PMBus.

Datasheet: https://www.analog.com/en/products/max20830.html

---
Changes in v2:
- bindings:
- did not add interrupt, smbalert pin does not exist in device.
- added allof with ref to regulator.yaml
- changed additionalprop to unevaluatedprop
- device node name in example changed to regulator
- driver:
- max20830.rst: Added missing in2_alarm
- max20830.c:
- added missing quotes in MODULE_IMPORT_NS
- added comment on why i2c_smbus_read_i2c_block_data is used
- first byte of buffer used as length instead of the return value
- "unsupported device" log now does not print first byte of buffer
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Alexis Czezar Torreno (2):
dt-bindings: hwmon: pmbus: add max20830
hwmon: (pmbus/max20830) add driver for max20830

 .../bindings/hwmon/pmbus/adi,max20830.yaml         | 61 +++++++++++++++
 Documentation/hwmon/index.rst                      |  1 +
 Documentation/hwmon/max20830.rst                   | 49 ++++++++++++
 MAINTAINERS                                        |  9 +++
 drivers/hwmon/pmbus/Kconfig                        |  9 +++
 drivers/hwmon/pmbus/Makefile                       |  1 +
 drivers/hwmon/pmbus/max20830.c                     | 86 ++++++++++++++++++++++
 7 files changed, 216 insertions(+)

---
base-commit: fb447217c59a13b2fff22d94de2498c185cd9032
change-id: 20260414-dev_max20830-9460b92cf6aa

Best regards,

Signature · 1 line
Alexis Czezar Torreno <[email protected]>
author maintainer
#1 lore raw

PATCH v2 1/2 dt-bindings: hwmon: pmbus: add max20830

Add device tree documentation for MAX20830 step-down DC-DC switching regulator with PMBus interface.

---
 .../bindings/hwmon/pmbus/adi,max20830.yaml         | 61 ++++++++++++++++++++++
 MAINTAINERS                                        |  7 +++
 2 files changed, 68 insertions(+)
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml new file +61 -0
new file mode 100644
index 0000000000000000000000000000000000000000..8b3ec1ffa0c9460de2122f6606ce3dcbcdfbbcc7
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/pmbus/adi,max20830.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX20830 Step-Down Switching Regulator with PMBus
+
+maintainers:
+  - Alexis Czezar Torreno <[email protected]>
+
+description: |
+  The MAX20830 is a fully integrated step-down DC-DC switching regulator with
+  PMBus interface. It provides 2.7V to 16V input, 0.4V to 5.8V adjustable
+  output, and up to 30A output current. It allows monitoring of input/output
+  voltage, output current and temperature through the PMBus serial interface.
+  Datasheet:
+    https://www.analog.com/en/products/max20830.html
+
+allOf:
+  - $ref: /schemas/regulator/regulator.yaml#
+
+properties:
+  compatible:
+    const: adi,max20830
+
+  reg:
+    maxItems: 1
+
+  vddh-supply:
+    description:
+      Phandle to the regulator that provides the VDDH power supply.
+
+  avdd-supply:
+    description:
+      Phandle to the regulator that provides the AVDD power supply.
+
+  ldoin-supply:
+    description:
+      Optional 2.5V to 5.5V LDO input supply.
+
+required:
+  - compatible
+  - reg
+  - vddh-supply
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        regulator@30 {
+            compatible = "adi,max20830";
+            reg = <0x30>;
+            vddh-supply = <&vddh>;
+        };
+    };
+...
MAINTAINERS +7 -0
index 0a3991c10ade20dd79cc7d1bf2a1d307ba6bd19d..031c743e979521a92ed9ac67915c178ce31727bd 100644
@@ -15579,6 +15579,13 @@ F:	Documentation/devicetree/bindings/hwmon/pmbus/adi,max17616.yaml
 F:	Documentation/hwmon/max17616.rst
 F:	drivers/hwmon/pmbus/max17616.c
 
+MAX20830 HARDWARE MONITOR DRIVER
+M:	Alexis Czezar Torreno <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml
+
 MAX2175 SDR TUNER DRIVER
 M:	Ramesh Shanmugasundaram <[email protected]>
 L:	[email protected]
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: hwmon: pmbus: add max20830

Quoted 33 lines · Alexis Czezar Torreno

Add device tree documentation for MAX20830 step-down DC-DC switching regulator with PMBus interface.

---
 .../bindings/hwmon/pmbus/adi,max20830.yaml         | 61 ++++++++++++++++++++++
 MAINTAINERS                                        |  7 +++
 2 files changed, 68 insertions(+)
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml new file +18 -0
new file mode 100644
index 0000000000000000000000000000000000000000..8b3ec1ffa0c9460de2122f6606ce3dcbcdfbbcc7
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/pmbus/adi,max20830.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX20830 Step-Down Switching Regulator with PMBus
+
+maintainers:
+  - Alexis Czezar Torreno <[email protected]>
+
+description: |
+  The MAX20830 is a fully integrated step-down DC-DC switching regulator with
+  PMBus interface. It provides 2.7V to 16V input, 0.4V to 5.8V adjustable
+  output, and up to 30A output current. It allows monitoring of input/output
+  voltage, output current and temperature through the PMBus serial interface.
+  Datasheet:
+    https://www.analog.com/en/products/max20830.html

Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml line 28

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml new file +10 -0
+
+allOf:
+  - $ref: /schemas/regulator/regulator.yaml#
+
+properties:
+  compatible:
+    const: adi,max20830
+
+  reg:
+    maxItems: 1

On the previous version, you got an LLM comment about not having the interrupts property amongst other things.
I think the other things got implemented, but I didn't see any reply to the bot about that?
I think the answer is that it shouldn't because the pin it referenced doesn't exist, but when looking at the schematic I have to wonder if there should be an interrupts property for dealing with "pgood"?

Cheers,
Conor.

Quoted 55 lines
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml new file +33 -0
+
+  vddh-supply:
+    description:
+      Phandle to the regulator that provides the VDDH power supply.
+
+  avdd-supply:
+    description:
+      Phandle to the regulator that provides the AVDD power supply.
+
+  ldoin-supply:
+    description:
+      Optional 2.5V to 5.5V LDO input supply.
+
+required:
+  - compatible
+  - reg
+  - vddh-supply
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        regulator@30 {
+            compatible = "adi,max20830";
+            reg = <0x30>;
+            vddh-supply = <&vddh>;
+        };
+    };
+...
MAINTAINERS +7 -0
index 0a3991c10ade20dd79cc7d1bf2a1d307ba6bd19d..031c743e979521a92ed9ac67915c178ce31727bd 100644
@@ -15579,6 +15579,13 @@ F:	Documentation/devicetree/bindings/hwmon/pmbus/adi,max17616.yaml
 F:	Documentation/hwmon/max17616.rst
 F:	drivers/hwmon/pmbus/max17616.c
 
+MAX20830 HARDWARE MONITOR DRIVER
+M:	Alexis Czezar Torreno <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml
+
 MAX2175 SDR TUNER DRIVER
 M:	Ramesh Shanmugasundaram <[email protected]>
 L:	[email protected]
Signature · 2 lines
-- 
2.34.1
maintainer
#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: hwmon: pmbus: add max20830

Quoted 43 lines · Conor Dooley
Quoted 42 lines · Alexis Czezar Torreno

Add device tree documentation for MAX20830 step-down DC-DC switching regulator with PMBus interface.

---
 .../bindings/hwmon/pmbus/adi,max20830.yaml         | 61 ++++++++++++++++++++++
 MAINTAINERS                                        |  7 +++
 2 files changed, 68 insertions(+)
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml new file +27 -0
new file mode 100644
index 0000000000000000000000000000000000000000..8b3ec1ffa0c9460de2122f6606ce3dcbcdfbbcc7
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/pmbus/adi,max20830.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX20830 Step-Down Switching Regulator with PMBus
+
+maintainers:
+  - Alexis Czezar Torreno <[email protected]>
+
+description: |
+  The MAX20830 is a fully integrated step-down DC-DC switching regulator with
+  PMBus interface. It provides 2.7V to 16V input, 0.4V to 5.8V adjustable
+  output, and up to 30A output current. It allows monitoring of input/output
+  voltage, output current and temperature through the PMBus serial interface.
+  Datasheet:
+    https://www.analog.com/en/products/max20830.html
+
+allOf:
+  - $ref: /schemas/regulator/regulator.yaml#
+
+properties:
+  compatible:
+    const: adi,max20830
+
+  reg:
Quoted 8 lines

Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml line 28

Quoted 1 line
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml new file +1 -0
+    maxItems: 1

On the previous version, you got an LLM comment about not having the interrupts property amongst other things.
I think the other things got implemented, but I didn't see any reply to the bot about that?
I think the answer is that it shouldn't because the pin it referenced doesn't exist, but when looking at the schematic I have to wonder if

I had to look this up in the datasheet. A SMBus chip with no alert pin is a bit odd, but you are correct.

Quoted 2 lines

there should be an interrupts property for dealing with "pgood"?

FWIW, I have never seen that. Normally such pins are used to take devices out of reset.

Thanks,
Guenter

#4 lore raw

Re: [PATCH v2 1/2] dt-bindings: hwmon: pmbus: add max20830

Quoted 53 lines · Guenter Roeck
Quoted 43 lines · Conor Dooley
Quoted 42 lines · Alexis Czezar Torreno

Add device tree documentation for MAX20830 step-down DC-DC switching regulator with PMBus interface.

---
 .../bindings/hwmon/pmbus/adi,max20830.yaml         | 61 ++++++++++++++++++++++
 MAINTAINERS                                        |  7 +++
 2 files changed, 68 insertions(+)
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml new file +27 -0
new file mode 100644
index 0000000000000000000000000000000000000000..8b3ec1ffa0c9460de2122f6606ce3dcbcdfbbcc7
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/pmbus/adi,max20830.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX20830 Step-Down Switching Regulator with PMBus
+
+maintainers:
+  - Alexis Czezar Torreno <[email protected]>
+
+description: |
+  The MAX20830 is a fully integrated step-down DC-DC switching regulator with
+  PMBus interface. It provides 2.7V to 16V input, 0.4V to 5.8V adjustable
+  output, and up to 30A output current. It allows monitoring of input/output
+  voltage, output current and temperature through the PMBus serial interface.
+  Datasheet:
+    https://www.analog.com/en/products/max20830.html
+
+allOf:
+  - $ref: /schemas/regulator/regulator.yaml#
+
+properties:
+  compatible:
+    const: adi,max20830
+
+  reg:
Quoted 8 lines

Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml line 28

Quoted 1 line
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml new file +1 -0
+    maxItems: 1

On the previous version, you got an LLM comment about not having the interrupts property amongst other things.
I think the other things got implemented, but I didn't see any reply to the bot about that?
I think the answer is that it shouldn't because the pin it referenced doesn't exist, but when looking at the schematic I have to wonder if

Quoted 7 lines

I had to look this up in the datasheet. A SMBus chip with no alert pin is a bit odd, but you are correct.

Quoted 2 lines

there should be an interrupts property for dealing with "pgood"?

FWIW, I have never seen that. Normally such pins are used to take devices out of reset.

It's an output on this device seemingly. I don't care if the driver ignores it, but for completeness (and we like completeness with bindings) I think it should be documented as an interrupt or gpio.

author maintainer
#5 lore raw

RE: [PATCH v2 1/2] dt-bindings: hwmon: pmbus: add max20830

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

On the previous version, you got an LLM comment about not having the interrupts property amongst other things.
I think the other things got implemented, but I didn't see any reply to the bot about that?

I wasn't sure if it was that type of bot. I'll try replying on the other patch review. I just added a note in the cover letter change log about the lacking smbalert.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

I think the answer is that it shouldn't because the pin it referenced doesn't exist, but when looking at the schematic I have to wonder if

I had to look this up in the datasheet. A SMBus chip with no alert pin is a bit odd, but you are correct.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

there should be an interrupts property for dealing with "pgood"?

FWIW, I have never seen that. Normally such pins are used to take devices out of reset.

It's an output on this device seemingly. I don't care if the driver ignores it, but for completeness (and we like completeness with
bindings) I think it should be documented as an interrupt or gpio.

Alright, I'll add it as an interrupt: optional power-good signal

Regards,
Alexis

maintainer
#6 lore raw

Re: [PATCH v2 1/2] dt-bindings: hwmon: pmbus: add max20830

Quoted 19 lines · Alexis Czezar
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

On the previous version, you got an LLM comment about not having the interrupts property amongst other things.
I think the other things got implemented, but I didn't see any reply to the bot about that?

I wasn't sure if it was that type of bot. I'll try replying on the other patch review. I just added a note in the cover letter change log about the lacking smbalert.

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

I think the answer is that it shouldn't because the pin it referenced doesn't exist, but when looking at the schematic I have to wonder if

I had to look this up in the datasheet. A SMBus chip with no alert pin is a bit odd, but you are correct.

Quoted 2 lines

there should be an interrupts property for dealing with "pgood"?

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

FWIW, I have never seen that. Normally such pins are used to take devices out of reset.

It's an output on this device seemingly. I don't care if the driver ignores it, but for completeness (and we like completeness with
bindings) I think it should be documented as an interrupt or gpio.

Alright, I'll add it as an interrupt: optional power-good signal

Uuh, that really doesn't make any sense. Please at least make it a gpio pin, matching pwr-good-gpios of ti,tps65185.yaml.

Guenter

author maintainer
#7 lore raw

RE: [PATCH v2 1/2] dt-bindings: hwmon: pmbus: add max20830

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

It's an output on this device seemingly. I don't care if the driver ignores it, but for completeness (and we like completeness with bindings) I think it should be documented as an interrupt or gpio.

Quoted 6 lines
Quoted 2 lines

Alright, I'll add it as an interrupt: optional power-good signal

Uuh, that really doesn't make any sense. Please at least make it a gpio pin, matching pwr-good-gpios of ti,tps65185.yaml.

I see, will do.

author maintainer
#8 lore raw

PATCH v2 2/2 hwmon: (pmbus/max20830) add driver for max20830

In reply to Alexis Czezar Torreno

Add support for MAX20830 step-down DC-DC switching regulator with PMBus interface. It allows monitoring of input/output voltage, output current and temperature through the PMBus serial interface.

---
 Documentation/hwmon/index.rst    |  1 +
 Documentation/hwmon/max20830.rst | 49 +++++++++++++++++++++++
 MAINTAINERS                      |  2 +
 drivers/hwmon/pmbus/Kconfig      |  9 +++++
 drivers/hwmon/pmbus/Makefile     |  1 +
 drivers/hwmon/pmbus/max20830.c   | 86 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 148 insertions(+)
Documentation/hwmon/index.rst +1 -0
index 8b655e5d6b68b90c697a52c7bf526e81d370caf7..56f7eb761be76dd627a2f34135abad05203b0582 100644
@@ -158,6 +158,7 @@ Hardware Monitoring Kernel Drivers
    max197
    max20730
    max20751
+   max20830
    max31722
    max31730
    max31760
Documentation/hwmon/max20830.rst new file +49 -0

49 lines not on this page · raw message

MAINTAINERS +2 -0
index 031c743e979521a92ed9ac67915c178ce31727bd..d6a6745e2dae29c3b8f80bbe61c54a2f5ecd9f47 100644
@@ -15585,6 +15585,8 @@ L:	[email protected]
 S:	Supported
 W:	https://ez.analog.com/linux-software-drivers
 F:	Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml
+F:	Documentation/hwmon/max20830.rst
+F:	drivers/hwmon/pmbus/max20830.c
 
 MAX2175 SDR TUNER DRIVER
 M:	Ramesh Shanmugasundaram <[email protected]>
drivers/hwmon/pmbus/Kconfig +9 -0
index 8f4bff375ecbc355f5ed3400855c2852ec2aa5ef..987705bf45b75b7b91ccc469247909f3c3f53d77 100644
@@ -365,6 +365,15 @@ config SENSORS_MAX20751
 	  This driver can also be built as a module. If so, the module will
 	  be called max20751.
 
+config SENSORS_MAX20830
+	tristate "Analog Devices MAX20830"
+	help
+	  If you say yes here you get hardware monitoring support for Analog
+	  Devices MAX20830.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called max20830.
+
 config SENSORS_MAX31785
 	tristate "Maxim MAX31785 and compatibles"
 	help
drivers/hwmon/pmbus/Makefile +1 -0
index 7129b62bc00f8a2e98de14004997752a856dfda2..bc52f930e0825a902a0dd1c9e2b44f2e8d577c35 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_SENSORS_MAX16601)	+= max16601.o
 obj-$(CONFIG_SENSORS_MAX17616)	+= max17616.o
 obj-$(CONFIG_SENSORS_MAX20730)	+= max20730.o
 obj-$(CONFIG_SENSORS_MAX20751)	+= max20751.o
+obj-$(CONFIG_SENSORS_MAX20830)	+= max20830.o
 obj-$(CONFIG_SENSORS_MAX31785)	+= max31785.o
 obj-$(CONFIG_SENSORS_MAX34440)	+= max34440.o
 obj-$(CONFIG_SENSORS_MAX8688)	+= max8688.o
drivers/hwmon/pmbus/max20830.c new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v2 2/2] hwmon: (pmbus/max20830) add driver for max20830

Sashiko AI review found 2 potential issue(s): - [High] Missing validation for short reads from `i2c_smbus_read_i2c_block_data()` can lead to uninitialized stack memory access and information leak.…

Sashiko AI review found 2 potential issue(s):
- [High] Missing validation for short reads from i2c_smbus_read_i2c_block_data() can lead to uninitialized stack memory access and information leak.
- [Low] Off-by-one error when null-terminating the device ID string truncates the last character of the payload.
--

commit 479738352902d3197058c3172cee31960249a6a5
Author: Alexis Czezar Torreno <[email protected]>

hwmon: (pmbus/max20830) add driver for max20830

This adds support for the MAX20830 step-down DC-DC switching regulator with a PMBus interface, allowing monitoring of input/output voltages, output current, and temperature.

Quoted 5 lines
drivers/hwmon/pmbus/max20830.c new file +0 -0
new file mode 100644
index 0000000000000..21ea8b59150cb

[ ... ]

drivers/hwmon/pmbus/max20830.c line 44

Quoted 5 lines
drivers/hwmon/pmbus/max20830.c new file +5 -0
+	ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
+					    I2C_SMBUS_BLOCK_MAX, buf);
+	if (ret < 0)
+		return dev_err_probe(&client->dev, ret,
+				     "Failed to read IC_DEVICE_ID\n");

i2c_smbus_read_i2c_block_data() returns the number of bytes read on success. If the I2C controller performs a short read, returning fewer bytes than expected, buf will contain uninitialized stack memory for the remaining bytes.

If buf[0] coincidentally contains 9, the len != 9 check below will pass. Could this lead to uninitialized stack memory being accessed and printed by dev_err_probe() on a mismatch? Should we verify the number of bytes read (e.g., ret >= 10) instead of just ret < 0?

drivers/hwmon/pmbus/max20830.c line 52

Quoted 8 lines
drivers/hwmon/pmbus/max20830.c new file +8 -0
+
+	/* First byte is the block length. */
+	len = buf[0];
+	if (len != 9)
+		return dev_err_probe(&client->dev, -ENODEV,
+				     "Unexpected IC_DEVICE_ID response\n");
+
+	buf[len] = '\0';

Since the payload of length len occupies buf[1] through buf[len], doesn't setting buf[len] to '\0' overwrite the final byte of the device ID payload?

While this 9th byte is ignored by the 8-byte strncmp() call below, it will cause the dev_err_probe() error log to print a truncated string. Should the null terminator be placed at buf[len + 1] instead?

Quoted 3 lines
drivers/hwmon/pmbus/max20830.c new file +3 -0
+	if (strncmp(buf + 1, "MAX20830", 8))
+		return dev_err_probe(&client->dev, -ENODEV,
+				     "Unsupported device: '%s'\n", buf + 1);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author maintainer
#10 lore raw

RE: [PATCH v2 2/2] hwmon: (pmbus/max20830) add driver for max20830

Quoted 38 lines

Sashiko AI review found 2 potential issue(s):
- [High] Missing validation for short reads from i2c_smbus_read_i2c_block_data() can lead to uninitialized stack memory access and information leak.
- [Low] Off-by-one error when null-terminating the device ID string truncates the last character of the payload.
--

commit 479738352902d3197058c3172cee31960249a6a5
Author: Alexis Czezar Torreno <[email protected]>

hwmon: (pmbus/max20830) add driver for max20830

This adds support for the MAX20830 step-down DC-DC switching regulator with a PMBus interface, allowing monitoring of input/output voltages, output current, and temperature.

Quoted 5 lines
(quoted diff) +0 -0

b/drivers/hwmon/pmbus/max20830.c new file mode 100644 index 0000000000000..21ea8b59150cb

drivers/hwmon/pmbus/max20830.c new file +0 -0

[ ... ]

drivers/hwmon/pmbus/max20830.c line 44

Quoted 5 lines
drivers/hwmon/pmbus/max20830.c new file +5 -0
+	ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
+					    I2C_SMBUS_BLOCK_MAX, buf);
+	if (ret < 0)
+		return dev_err_probe(&client->dev, ret,
+				     "Failed to read IC_DEVICE_ID\n");

i2c_smbus_read_i2c_block_data() returns the number of bytes read on success.
If the I2C controller performs a short read, returning fewer bytes than expected, buf will contain uninitialized stack memory for the remaining bytes.

Quoted 4 lines

If buf[0] coincidentally contains 9, the len != 9 check below will pass. Could this lead to uninitialized stack memory being accessed and printed by dev_err_probe() on a mismatch? Should we verify the number of bytes read (e.g., ret >= 10) instead of just ret < 0?

It was suggested to me to just initialize the buffer to avoid this issue.

Quoted 13 lines

drivers/hwmon/pmbus/max20830.c line 52

Quoted 9 lines
drivers/hwmon/pmbus/max20830.c new file +8 -0
+
+	/* First byte is the block length. */
+	len = buf[0];
+	if (len != 9)
+		return dev_err_probe(&client->dev, -ENODEV,
+				     "Unexpected IC_DEVICE_ID response\n");
+
+	buf[len] = '\0';

Since the payload of length len occupies buf[1] through buf[len], doesn't setting buf[len] to '\0' overwrite the final byte of the device ID payload?

Quoted 3 lines

While this 9th byte is ignored by the 8-byte strncmp() call below, it will cause the dev_err_probe() error log to print a truncated string. Should the null terminator be placed at buf[len + 1] instead?

When literally reading the ID from the device the device replies with:
{ 0x09, M, A, X, 2, 0, 8, 3, 0} - nothing follows not even terminator.

buf[0] is 9, so len = 9, it apparently includes itself in the length/number of bytes. Actual data exist from buf[1] to buf[len-1], hence buf[len] to '\0' is actually correct.

I can add comments on the code to clarify this.

Quoted 12 lines

drivers/hwmon/pmbus/max20830.c line 55

Quoted 4 lines
drivers/hwmon/pmbus/max20830.c new file +3 -0
+	if (strncmp(buf + 1, "MAX20830", 8))
+		return dev_err_probe(&client->dev, -ENODEV,
+				     "Unsupported device: '%s'\n", buf + 1);

--
Sashiko AI review *
https://urldefense.com/v3/__https://sashiko.dev/*/patchset/20260416-
dev_max20830-v2-0- [email protected]?part=2__;Iw!!A3Ni8CS0y2Y!6tnYi0B1txw5D1iHlO wMF5xTB08wkOaqxNEZnQLyd615sTaced0WcqjVwJpIAN6vuhsxvyz81g- FcmRT1xWRgDSmicnZcYI$

#11 lore raw

Re: [PATCH v2 2/2] hwmon: (pmbus/max20830) add driver for max20830

In reply to Alexis Czezar Torreno
Quoted 149 lines · Alexis Czezar Torreno

Add support for MAX20830 step-down DC-DC switching regulator with PMBus interface. It allows monitoring of input/output voltage, output current and temperature through the PMBus serial interface.

---
 Documentation/hwmon/index.rst    |  1 +
 Documentation/hwmon/max20830.rst | 49 +++++++++++++++++++++++
 MAINTAINERS                      |  2 +
 drivers/hwmon/pmbus/Kconfig      |  9 +++++
 drivers/hwmon/pmbus/Makefile     |  1 +
 drivers/hwmon/pmbus/max20830.c   | 86 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 148 insertions(+)
Documentation/hwmon/index.rst +1 -0
index 8b655e5d6b68b90c697a52c7bf526e81d370caf7..56f7eb761be76dd627a2f34135abad05203b0582 100644
@@ -158,6 +158,7 @@ Hardware Monitoring Kernel Drivers
    max197
    max20730
    max20751
+   max20830
    max31722
    max31730
    max31760
Documentation/hwmon/max20830.rst new file +49 -0
new file mode 100644
index 0000000000000000000000000000000000000000..936e409dcc5c0898dde27d782308d4a7e1357e73
@@ -0,0 +1,49 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver max20830
+======================
+
+Supported chips:
+
+  * Analog Devices MAX20830
+
+    Prefix: 'max20830'
+
+    Addresses scanned: -
+
+    Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/max20830.pdf
+
+Author:
+
+  - Alexis Czezar Torreno <[email protected]>
+
+
+Description
+-----------
+
+This driver supports hardware monitoring for Analog Devices MAX20830
+Step-Down Switching Regulator with PMBus Interface.
+
+The MAX20830 is a 2.7V to 16V, 30A fully integrated step-down DC-DC switching
+regulator. Through the PMBus interface, the device can monitor input/output
+voltages, output current and temperature.
+
+The driver is a client driver to the core PMBus driver. Please see
+Documentation/hwmon/pmbus.rst for details on PMBus client drivers.
+
+Sysfs entries
+-------------
+
+================= ========================================
+in1_label         "vin"
+in1_input         Measured input voltage
+in1_alarm         Input voltage alarm
+in2_label         "vout1"
+in2_input         Measured output voltage
+in2_alarm         Output voltage alarm
+curr1_label       "iout1"
+curr1_input       Measured output current
+curr1_alarm       Output current alarm
+temp1_input       Measured temperature
+temp1_alarm       Chip temperature alarm
+================= ========================================
MAINTAINERS +2 -0
index 031c743e979521a92ed9ac67915c178ce31727bd..d6a6745e2dae29c3b8f80bbe61c54a2f5ecd9f47 100644
@@ -15585,6 +15585,8 @@ L:	[email protected]
 S:	Supported
 W:	https://ez.analog.com/linux-software-drivers
 F:	Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml
+F:	Documentation/hwmon/max20830.rst
+F:	drivers/hwmon/pmbus/max20830.c
 
 MAX2175 SDR TUNER DRIVER
 M:	Ramesh Shanmugasundaram <[email protected]>
drivers/hwmon/pmbus/Kconfig +9 -0
index 8f4bff375ecbc355f5ed3400855c2852ec2aa5ef..987705bf45b75b7b91ccc469247909f3c3f53d77 100644
@@ -365,6 +365,15 @@ config SENSORS_MAX20751
 	  This driver can also be built as a module. If so, the module will
 	  be called max20751.
 
+config SENSORS_MAX20830
+	tristate "Analog Devices MAX20830"
+	help
+	  If you say yes here you get hardware monitoring support for Analog
+	  Devices MAX20830.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called max20830.
+
 config SENSORS_MAX31785
 	tristate "Maxim MAX31785 and compatibles"
 	help
drivers/hwmon/pmbus/Makefile +1 -0
index 7129b62bc00f8a2e98de14004997752a856dfda2..bc52f930e0825a902a0dd1c9e2b44f2e8d577c35 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_SENSORS_MAX16601)	+= max16601.o
 obj-$(CONFIG_SENSORS_MAX17616)	+= max17616.o
 obj-$(CONFIG_SENSORS_MAX20730)	+= max20730.o
 obj-$(CONFIG_SENSORS_MAX20751)	+= max20751.o
+obj-$(CONFIG_SENSORS_MAX20830)	+= max20830.o
 obj-$(CONFIG_SENSORS_MAX31785)	+= max31785.o
 obj-$(CONFIG_SENSORS_MAX34440)	+= max34440.o
 obj-$(CONFIG_SENSORS_MAX8688)	+= max8688.o
drivers/hwmon/pmbus/max20830.c new file +17 -0
new file mode 100644
index 0000000000000000000000000000000000000000..21ea8b59150cb0564f1776ee08131bad7fdef003
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Hardware monitoring driver for Analog Devices MAX20830
+ *
+ * Copyright (C) 2026 Analog Devices, Inc.
+ */
+
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include "pmbus.h"
+
+static struct pmbus_driver_info max20830_info = {
+	.pages = 1,
+	.format[PSC_VOLTAGE_IN] = linear,
+	.format[PSC_VOLTAGE_OUT] = linear,
+	.format[PSC_CURRENT_OUT] = linear,

drivers/hwmon/pmbus/max20830.c line 27

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c new file +10 -0
+	.format[PSC_TEMPERATURE] = linear,
+	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT |
+		PMBUS_HAVE_TEMP |
+		PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT |
+		PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP,
+};
+
+static int max20830_probe(struct i2c_client *client)
+{
+	u8 buf[I2C_SMBUS_BLOCK_MAX + 1];

AI seems a bit paranoid but maybe to be on the safe side just initialize the above buffer.

Quoted 15 lines
drivers/hwmon/pmbus/max20830.c new file +15 -0
+	u8 len;
+	int ret;
+
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_READ_I2C_BLOCK))
+		return -ENODEV;
+
+	/*
+	 * Use i2c_smbus_read_i2c_block_data() instead of
+	 * i2c_smbus_read_block_data() to support I2C controllers
+	 * which do not support SMBus block reads.
+	 */
+	ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
+					    I2C_SMBUS_BLOCK_MAX, buf);
+	if (ret < 0)

drivers/hwmon/pmbus/max20830.c line 52

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c new file +10 -0
+		return dev_err_probe(&client->dev, ret,
+				     "Failed to read IC_DEVICE_ID\n");
+
+	/* First byte is the block length. */
+	len = buf[0];
+	if (len != 9)
+		return dev_err_probe(&client->dev, -ENODEV,
+				     "Unexpected IC_DEVICE_ID response\n");
+
+	buf[len] = '\0';

It looks like it has a point in the above though.

- Nuno Sá