* [PATCH v7 3/4] hwmon: (sht3x) Add devicetree support
2026-07-13 7:45 [PATCH v7 0/4] hwmon: (sht3x) Add support for GXCAS GXHT30 Zaixiang Xu
@ 2026-07-13 7:45 ` Zaixiang Xu
0 siblings, 0 replies; 2+ messages in thread
From: Zaixiang Xu @ 2026-07-13 7:45 UTC (permalink / raw)
To: Guenter Roeck
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-hwmon,
devicetree, linux-kernel, Zaixiang Xu
Add an of_device_id table to support devicetree based instantiation
of the supported sensors.
The devicetree binding models all higher accuracy parts with a
fallback to the base part of their group, so only the two base
compatibles need to be listed. The match data distinguishes the
humidity and temperature parts (SHT3x) from the temperature-only
parts (STS3x), which require different configuration.
Start enum sht3x_chips at 1: with sht3x equal to 0, the OF match
data for the SHT devices would be NULL, causing i2c_get_match_data()
to fall back to i2c_device_id name matching, which fails for
devicetree names. The devices would then only work because the
resulting chip id 0 happens to equal sht3x. Non-zero match data
avoids relying on that coincidence.
Signed-off-by: Zaixiang Xu <zaixiang.xu.dev@gmail.com>
---
drivers/hwmon/sht3x.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c
index c2f6b73aa7f3..6d47cfd340f8 100644
--- a/drivers/hwmon/sht3x.c
+++ b/drivers/hwmon/sht3x.c
@@ -61,7 +61,7 @@ static const unsigned char sht3x_cmd_read_serial_number[] = { 0x37, 0x80 };
#define SHT3X_MAX_HUMIDITY 100000
enum sht3x_chips {
- sht3x,
+ sht3x = 1,
sts3x,
};
@@ -939,8 +939,19 @@ static const struct i2c_device_id sht3x_ids[] = {
MODULE_DEVICE_TABLE(i2c, sht3x_ids);
+static const struct of_device_id sht3x_of_match[] = {
+ { .compatible = "sensirion,sht30", .data = (void *)(uintptr_t)sht3x },
+ { .compatible = "sensirion,sts30", .data = (void *)(uintptr_t)sts3x },
+ { }
+};
+
+MODULE_DEVICE_TABLE(of, sht3x_of_match);
+
static struct i2c_driver sht3x_i2c_driver = {
- .driver.name = "sht3x",
+ .driver = {
+ .name = "sht3x",
+ .of_match_table = sht3x_of_match,
+ },
.probe = sht3x_probe,
.id_table = sht3x_ids,
};
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v7 3/4] hwmon: (sht3x) Add devicetree support
[not found] <20260713080129.D8A8E1F00A3D@smtp.kernel.org>
@ 2026-07-13 8:28 ` Zaixiang Xu
0 siblings, 0 replies; 2+ messages in thread
From: Zaixiang Xu @ 2026-07-13 8:28 UTC (permalink / raw)
To: linux-hwmon, devicetree
Cc: Guenter Roeck, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-kernel, sashiko-reviews, Zaixiang Xu
On Mon, 13 Jul 2026 08:01:29 +0000, sashiko-bot@kernel.org wrote:
> While reviewing this patch, I noticed a few pre-existing regressions
> in this file that might be worth addressing.
>
> [Severity: Critical]
> This is a pre-existing issue, but does this unaligned memory access
> crash strict-alignment architectures?
[...]
> [Severity: High]
> This isn't a bug introduced by this patch, but does this integer
> arithmetic overflow?
Thanks for the report. All five findings are in pre-existing code and
are not touched by this series, so I would prefer to keep them
separate from the devicetree support here.
I checked the first two: the unaligned access in sht3x_update_client()
(buf + 3 is an odd offset into a byte buffer, so it needs
get_unaligned_be16()), and the limit_write() overflow (temperature is
clamped to 130000, and (130000 + 45000) * 24543 = 4295025000 just
exceeds U32_MAX, so writing the maximum limit wraps the raw
temperature field to 0). Both look real.
I plan to go through all five and send fixes as a separate series
after this one.
Thanks,
Zaixiang
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-13 8:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260713080129.D8A8E1F00A3D@smtp.kernel.org>
2026-07-13 8:28 ` [PATCH v7 3/4] hwmon: (sht3x) Add devicetree support Zaixiang Xu
2026-07-13 7:45 [PATCH v7 0/4] hwmon: (sht3x) Add support for GXCAS GXHT30 Zaixiang Xu
2026-07-13 7:45 ` [PATCH v7 3/4] hwmon: (sht3x) Add devicetree support Zaixiang Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox