From 3d23ad05be446716fe5244ac297cc0b475bcd9ab Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:28:04 +1100 Subject: [PATCH] hwmon: macsmc: Select sensor keys by key metadata, not by SoC macsmc_hwmon_is_m3() matched apple,t6030/t6031/t6032/t6034/t8122 and gated two things that do not depend on the SoC: 1. The key check in macsmc_hwmon_create_sensor(). A sensor node was admitted only if the SMC reports its key readable and as a 4-byte "flt " or 8-byte "ioft" value, but only on those five SoCs. The gate was added to keep the earlier admission policy on other machines, not because of a firmware difference. Every SMC reports a key's type, size and flags (apple_smc_get_key_info()), and macsmc_hwmon_read_key() decodes only those two formats on every SoC, so a key that fails the check can only fail every read. The die sensor, thermal pressure and temperature discovery paths already apply the same check without a SoC gate. Apply it to every sensor node. On a node that is a thermal sensor provider (#thermal-sensor-cells, used today by the T600x MacBook Pro, T604x, T8112, T8122 and T8140 trees) a rejected temperature node keeps its hidden channel, so zone indices do not move; elsewhere the unusable channel is no longer registered. 2. The debugfs "keys" inventory, enabled on the same SoCs and T6050. It only walks the SMC key index and key info and reads readable 4-byte float T* and P* keys on demand, which every SMC supports. It is debugfs, root only, and reads nothing at probe. Create it on every machine. No SMC write and no probe-time key read is added on any SoC. The key check and the inventory were written by Chris Kearney for T6030. Fixes: c91c5f4c1f68 ("hwmon: macsmc: preserve the legacy sensor export policy") Fixes: 2604bb0c739b ("hwmon: macsmc: expose read-only SMC key inventory on T6050") Signed-off-by: Ryan Murray --- drivers/hwmon/macsmc-hwmon.c | 45 +++++++++++++++--------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c index c519c70755c00..87ad71b3984d3 100644 --- a/drivers/hwmon/macsmc-hwmon.c +++ b/drivers/hwmon/macsmc-hwmon.c @@ -58,15 +58,6 @@ module_param_unsafe(fan_control, bool, 0644); MODULE_PARM_DESC(fan_control, "Allow manual fan speeds on every fan with a mode key, also where the device tree does not (default: the device tree decides)"); -static bool macsmc_hwmon_is_m3(void) -{ - return of_machine_is_compatible("apple,t6030") || - of_machine_is_compatible("apple,t6031") || - of_machine_is_compatible("apple,t6032") || - of_machine_is_compatible("apple,t6034") || - of_machine_is_compatible("apple,t8122"); -} - struct macsmc_hwmon_sensor { struct apple_smc_key_info info; smc_key macsmc_key; @@ -863,22 +854,25 @@ static int macsmc_hwmon_create_sensor(struct device *dev, struct apple_smc *smc, if (ret) return ret; - if (macsmc_hwmon_is_m3()) { - if (!(sensor->info.flags & APPLE_SMC_READABLE)) - return -EACCES; + /* + * Admit a key only if its own metadata says it can be read in a + * format macsmc_hwmon_read_key() decodes. Any other key could only + * fail every read, whatever the SoC. + */ + if (!(sensor->info.flags & APPLE_SMC_READABLE)) + return -EACCES; - switch (sensor->info.type_code) { - case __SMC_KEY('f', 'l', 't', ' '): - if (sensor->info.size != sizeof(u32)) - return -EINVAL; - break; - case __SMC_KEY('i', 'o', 'f', 't'): - if (sensor->info.size != sizeof(u64)) - return -EINVAL; - break; - default: - return -EOPNOTSUPP; - } + switch (sensor->info.type_code) { + case __SMC_KEY('f', 'l', 't', ' '): + if (sensor->info.size != sizeof(u32)) + return -EINVAL; + break; + case __SMC_KEY('i', 'o', 'f', 't'): + if (sensor->info.size != sizeof(u64)) + return -EINVAL; + break; + default: + return -EOPNOTSUPP; } ret = of_property_read_string(sensor_node, "label", &label); @@ -1680,8 +1674,7 @@ static int macsmc_hwmon_probe(struct platform_device *pdev) return dev_err_probe(hwmon->dev, PTR_ERR(hwmon->hwmon_dev), "Probing SMC hwmon device failed\n"); - if (macsmc_hwmon_is_m3() || of_machine_is_compatible("apple,t6050")) - macsmc_hwmon_debugfs_init(hwmon); + macsmc_hwmon_debugfs_init(hwmon); ret = macsmc_hwmon_die_register(hwmon); if (ret)