[PATCH 2/3] hwmon: lenovo-ec-sensors: Fix NULL pointer dereference when DMI match fails

From: Kean

Date: Wed May 13 2026 - 21:16:17 EST


dmi_first_match() returns NULL if the running system does not match any
entry in thinkstation_dmi_table. Without a NULL check, the subsequent
dmi_id->driver_data access dereferences a NULL pointer, causing a kernel
oops or panic.

Add a NULL check and return -ENODEV to gracefully fail the probe when
the driver is loaded on an unsupported platform.

Signed-off-by: Kean <rh_king@xxxxxxx>

Reviewed-by: Mark Pearson <mpearson-lenovo@xxxxxxxxx>
---
drivers/hwmon/lenovo-ec-sensors.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/hwmon/lenovo-ec-sensors.c b/drivers/hwmon/lenovo-ec-sensors.c
index a32b1f2c6a3a..b0f2a04ce679 100644
--- a/drivers/hwmon/lenovo-ec-sensors.c
+++ b/drivers/hwmon/lenovo-ec-sensors.c
@@ -546,6 +546,8 @@ static int lenovo_ec_probe(struct platform_device *pdev)
}

dmi_id = dmi_first_match(thinkstation_dmi_table);
+ if (!dmi_id)
+ return -ENODEV;

switch ((long)dmi_id->driver_data) {
case 0:
--
2.47.3