Skip to contentSkip to conversation

iio: proximity: hx9023s: firmware property, safety fixes

PATCH In review Yasin Lee 4 participants 11 messages Feb 13 – Feb 15

Subsystems (2)
lore
Share & tools
lore

Yasin Lee

author
#0 lore raw

v3 cover iio: proximity: hx9023s: firmware property, safety fixes

Hi,

This series contains a set of small fixes and improvements for the hx9023s proximity sensor driver.

The changes include:

- Fixing assignment order for __counted_by.
- Avoiding a division-by-zero case when the sampling frequency is unspecified.
- Allowing the firmware file name to be specified via firmware-name property, along with the corresponding DT binding update.

All changes are independent but related to robustness and platform support, and are grouped together for easier review.

Tested on a DT-based platform with firmware loading enabled.

Thanks for your time and review.

Best regards,
Yasin Lee

---
Changes in v3:
- Patch 1: Refined the commit message to accurately describe the __counted_by requirement.
- Patch 2: Updated the zero-check logic to if (!val && !val2) as suggested by Andy.
- Patch 3: Enhanced the commit message to explain the necessity of the firmware-name property.
- Patch 4: Collected Andy's Reviewed-by tag.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Patch 1: Added Fixes tag
- Patch 2:
- Added Fixes tag
- Changed conditional logic to positive style (val || val2) as suggested
- Patch 3 (dt-bindings):
- Removed redundant description.
- This patch now comes before driver implementation (documentation first)
- Patch 4 (driver):
- Fixed variable declaration order (reverse xmas tree)
- Split declaration and assignment for fw_name
- Removed unnecessary error checking for device_property_read_string()
- Simplified to: fw_name = "hx9023s.bin"; device_property_read_string(...);
- Patch 5: Temporarily dropped (ACPI support)
- Will resubmit separately once TYHX vendor ID is officially registered with UEFI Forum
- Need to provide verified DSDT evidence
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Yasin Lee (4):
iio: proximity: hx9023s: fix assignment order for __counted_by
iio: proximity: hx9023s: Protect against division by zero in set_samp_freq
dt-bindings: iio: proximity: hx9023s: support firmware-name property
iio: proximity: hx9023s: support firmware-name property

 .../devicetree/bindings/iio/proximity/tyhx,hx9023s.yaml       |  4 ++++
 drivers/iio/proximity/hx9023s.c                               | 11 ++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

---
base-commit: c8bfb63c902678228a0a265e22a5f55404988a43
change-id: 20260209-upstream-20260219-a7af6d9a85ad

Best regards,

Signature · 1 line
Yasin Lee <[email protected]>
author
#1 lore raw

PATCH v3 1/4 iio: proximity: hx9023s: fix assignment order for __counted_by

Initialize fw_size before copying firmware data into the flexible array member to match the __counted_by() annotation. This fixes the incorrect assignment order that triggers runtime safety checks.

Fixes e9ed97be4fcc ("iio: proximity: hx9023s: Added firmware file parsing functionality")
---
 drivers/iio/proximity/hx9023s.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/proximity/hx9023s.c +1 -2
index 2918dfc0df54..ad839db6b326 100644
@@ -1034,9 +1034,8 @@ static int hx9023s_send_cfg(const struct firmware *fw, struct hx9023s_data *data
 	if (!bin)
 		return -ENOMEM;
 
-	memcpy(bin->data, fw->data, fw->size);
-
 	bin->fw_size = fw->size;
+	memcpy(bin->data, fw->data, bin->fw_size);
 	bin->fw_ver = bin->data[FW_VER_OFFSET];
 	bin->reg_count = get_unaligned_le16(bin->data + FW_REG_CNT_OFFSET);
 
Signature · 1 line
2.43.0
author
#2 lore raw

Re: [PATCH v3 1/4] iio: proximity: hx9023s: fix assignment order for __counted_by

Hi Andy, Krzysztof,

Thank you both for the review and for the valuable feedback on this series. Regarding Patch 1, I have refined the commit message to accurately describe the __counted_by requirement.
If there are no further concerns on this specific fix, may I have your tags so I can include them in v4?

Thanks again for your time and guidance!

Best regards,
Yasin Lee

Quoted 30 lines · Yasin Lee

Initialize fw_size before copying firmware data into the flexible array member to match the __counted_by() annotation. This fixes the incorrect assignment order that triggers runtime safety checks.

Fixes e9ed97be4fcc ("iio: proximity: hx9023s: Added firmware file parsing functionality")
---
 drivers/iio/proximity/hx9023s.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/proximity/hx9023s.c +1 -3
index 2918dfc0df54..ad839db6b326 100644
@@ -1034,9 +1034,8 @@ static int hx9023s_send_cfg(const struct firmware *fw, struct hx9023s_data *data
        if (!bin)
                return -ENOMEM;
 
-       memcpy(bin->data, fw->data, fw->size);
-
        bin->fw_size = fw->size;
+       memcpy(bin->data, fw->data, bin->fw_size);
        bin->fw_ver = bin->data[FW_VER_OFFSET];
        bin->reg_count = get_unaligned_le16(bin->data + FW_REG_CNT_OFFSET);
 
 
--

2.43.0

author
#3 lore raw

PATCH v3 2/4 iio: proximity: hx9023s: Protect against division by zero in set_samp_freq

In reply to Yasin Lee

Avoid division by zero when sampling frequency is unspecified.

Fixes 60df548277b7 ("iio: proximity: Add driver support for TYHX's HX9023S capacitive proximity sensor")
---
 drivers/iio/proximity/hx9023s.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iio/proximity/hx9023s.c +3 -0
index ad839db6b326..17e00ee2b6f8 100644
@@ -719,6 +719,9 @@ static int hx9023s_set_samp_freq(struct hx9023s_data *data, int val, int val2)
 	struct device *dev = regmap_get_device(data->regmap);
 	unsigned int i, period_ms;
 
+	if (!val && !val2)
+		return -EINVAL;
+
 	period_ms = div_u64(NANO, (val * MEGA + val2));
 
 	for (i = 0; i < ARRAY_SIZE(hx9023s_samp_freq_table); i++) {
Signature · 1 line
2.43.0
Reviewed-by on v3 2/4
#4 lore raw

Re: [PATCH v3 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq

Quoted 1 line · Yasin Lee

Avoid division by zero when sampling frequency is unspecified.

In case of agreement this is the desired behaviour you can add

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw

Re: [PATCH v3 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq

Quoted 5 lines · On Fri, 13 Feb 2026 18:39:16 +0200 Andy Shevchenko…
Quoted 1 line · Yasin Lee

Avoid division by zero when sampling frequency is unspecified.

In case of agreement this is the desired behaviour you can add

It seems sensible to me as avoids undefined behaviour + is unlikely to make any functional difference as I assume that whatever we got from the undef never in practice matched a valid input.

So applied patches 1 and 2 to my fixes-togreg branch. I'm not pushing that out just now though as I want rc1 to rebase it on first.

Thanks,

Jonathan

Quoted 1 line
author
#6 lore raw

Re: [PATCH v3 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq

Quoted 13 lines · Jonathan Cameron
Quoted 5 lines · On Fri, 13 Feb 2026 18:39:16 +0200 Andy Shevchenko…
Quoted 1 line · Yasin Lee

Avoid division by zero when sampling frequency is unspecified.

In case of agreement this is the desired behaviour you can add

It seems sensible to me as avoids undefined behaviour + is unlikely to make any functional difference as I assume that whatever we got from the undef never in practice matched a valid input.

Quoted 7 lines

So applied patches 1 and 2 to my fixes-togreg branch. I'm not pushing that out just now though as I want rc1 to rebase it on first.

Thanks,

Jonathan

Hi Jonathan,

That's great! Thank you for applying the entire series, and thanks to Andy and Krzysztof for the detailed review and guidance throughout the process.

Best regards,
Yasin Lee

Quoted 2 lines
Quoted 1 line
author
#7 lore raw

PATCH v3 3/4 dt-bindings: iio: proximity: hx9023s: support firmware-name property

In reply to Yasin Lee

The hx9023s requires a firmware blob containing board-specific configuration data used to initialize its internal sensing engine.

Although the silicon is identical across platforms, different products may use different electrode layouts, PCB routing, cover materials and mechanical stack-ups. These physical differences require distinct calibration parameters and register configuration tables in order for the sensor to operate correctly.

The driver has always required firmware and historically assumed a single default firmware file name suitable for the reference design. However, this assumption does not hold for boards with different physical sensor layouts.

The default firmware file name remains unchanged and continues to be used for existing platforms. Allowing the firmware file name to be specified via device tree enables selecting the appropriate hardware-specific configuration when the board design differs.

This property does not change the existing ABI and is optional.

---
 Documentation/devicetree/bindings/iio/proximity/tyhx,hx9023s.yaml | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/iio/proximity/tyhx,hx9023s.yaml +4 -0
index 64ce8bc8bd36..cc5b5284c267 100644
@@ -28,6 +28,9 @@ properties:
 
   vdd-supply: true
 
+  firmware-name:
+    maxItems: 1
+
   "#address-cells":
     const: 1
 
@@ -65,6 +68,7 @@ examples:
         interrupt-parent = <&pio>;
         interrupts = <16 IRQ_TYPE_EDGE_FALLING>;
         vdd-supply = <&pp1800_prox>;
+        firmware-name = "hx9023s.bin";
 
         #address-cells = <1>;
         #size-cells = <0>;
Signature · 1 line
2.43.0
Acked-by on v3 3/4
#8 lore raw

Re: [PATCH v3 3/4] dt-bindings: iio: proximity: hx9023s: support firmware-name property

Quoted 8 lines · Yasin Lee

The hx9023s requires a firmware blob containing board-specific configuration data used to initialize its internal sensing engine.

Although the silicon is identical across platforms, different products may use different electrode layouts, PCB routing, cover materials and mechanical stack-ups. These physical differences require distinct calibration parameters and register configuration tables in order for the sensor to operate correctly.

Best regards,
Krzysztof

author
#9 lore raw

PATCH v3 4/4 iio: proximity: hx9023s: support firmware-name property

In reply to Yasin Lee

Add an optional firmware-name property to specify the firmware file. If not provided, the driver falls back to the default firmware name.

---
 drivers/iio/proximity/hx9023s.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/proximity/hx9023s.c +4 -1
index 17e00ee2b6f8..9efaa5b6b5bd 100644
@@ -1088,6 +1088,7 @@ static int hx9023s_probe(struct i2c_client *client)
 	struct device *dev = &client->dev;
 	struct iio_dev *indio_dev;
 	struct hx9023s_data *data;
+	const char *fw_name;
 	int ret;
 
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
@@ -1125,7 +1126,9 @@ static int hx9023s_probe(struct i2c_client *client)
 	if (ret)
 		return dev_err_probe(dev, ret, "channel config failed\n");
 
-	ret = request_firmware_nowait(THIS_MODULE, true, "hx9023s.bin", dev,
+	fw_name = "hx9023s.bin";
+	device_property_read_string(dev, "firmware-name", &fw_name);
+	ret = request_firmware_nowait(THIS_MODULE, true, fw_name, dev,
 				      GFP_KERNEL, data, hx9023s_cfg_update);
 	if (ret)
 		return dev_err_probe(dev, ret, "reg config failed\n");
Signature · 1 line
2.43.0
maintainer
#10 lore raw

Re: [PATCH v3 4/4] iio: proximity: hx9023s: support firmware-name property

Quoted 5 lines · On Fri, 13 Feb 2026 23:14:46 +0800 Yasin Lee <[email protected]> wrote:

Add an optional firmware-name property to specify the firmware file. If not provided, the driver falls back to the default firmware name.

Applied 3-4 to the testing branch of iio.git. I'll be rebasing once rc1 once it's available.

Thanks,

Jonathan

Quoted 28 lines
---
 drivers/iio/proximity/hx9023s.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/proximity/hx9023s.c +4 -1
index 17e00ee2b6f8..9efaa5b6b5bd 100644
@@ -1088,6 +1088,7 @@ static int hx9023s_probe(struct i2c_client *client)
 	struct device *dev = &client->dev;
 	struct iio_dev *indio_dev;
 	struct hx9023s_data *data;
+	const char *fw_name;
 	int ret;
 
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
@@ -1125,7 +1126,9 @@ static int hx9023s_probe(struct i2c_client *client)
 	if (ret)
 		return dev_err_probe(dev, ret, "channel config failed\n");
 
-	ret = request_firmware_nowait(THIS_MODULE, true, "hx9023s.bin", dev,
+	fw_name = "hx9023s.bin";
+	device_property_read_string(dev, "firmware-name", &fw_name);
+	ret = request_firmware_nowait(THIS_MODULE, true, fw_name, dev,
 				      GFP_KERNEL, data, hx9023s_cfg_update);
 	if (ret)
 		return dev_err_probe(dev, ret, "reg config failed\n");