From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796395734; b=DQ+kKyjqOHm4siPA3bXoDHVpmEWomOnuyUN+afaGEBD8hspvspeir3+ZJxmErA2hzTtS 7z59e3yGPMVOd4G+66c02EJ+ldvFa6O+5UmXiVV/0IxE02n8lazXkSh40wvveBnNziXhf bvGbOXodzOe1GlKeFw81aARgVzxpX+HwdqYVtj5D+Yj/xz/LvETykIYnjl7pGq6R7Y64+ P3MhFJQGFD33LkcKuz0MxG3MqqQ32ywZqThGsMm0CbyG1Z/dAvbn7p9YolDX5IhUbuRgZ B8L6fzxZvIu+l7Zn5TYZCtiNqan3zjHheCmvw2IAU+k28vAaXYjyGWIWbRR8FBRxsSA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796395734; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=mmkhS0OxqicR6Rkr3rzGuqZQMRfHXwnqDvb/+6pxyo4=; b=d35NU+UDVUhRAKdv4bWeiaNawLsn/qnzUtlQWUnRo+CNLltbxz++NU+X+V1AggJv53Rj PFEPJMGAoE5hpxMy5mz1h45sCt5cUEzrOlcxpZKad7ojMC0SXxUYXmT8jWVmd+L+efz/o 0q36R0oWtnXkMxAV5Np1cXVj5W3n7Ah/v/G8IDlZwKX9np2nitspnqxG7yeEAtySysbYG d/tPcYCL4jp3e8dHqJBZnxq5I2Uuw0Ij1h2TRrC+xAABVqlrh6twgkz+hDvWmQt4fXWFm pAlj78WhBRla8uqWjlZxsJL5wVFRtzv9o1+oAzv5jC64ku9w1QdgKBiJ9EBeeWcCclw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FOCHgqcc; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F18E606A32C; Fri, 4 Dec 2026 14:48:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FOCHgqcc Received: by smtp.kernel.org (Postfix) with ESMTPSA id 880501F000CE; Fri, 4 Dec 2026 14:48:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796395733; bh=mmkhS0OxqicR6Rkr3rzGuqZQMRfHXwnqDvb/+6pxyo4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=FOCHgqcc0wse4sVrtl21dsTqCjq/72EVepv+spu/YcpaCXHGnEUnsv34sJiLenxCq 67MW8smfcFQJEBa1SAEbSCQfYrLfvltMznnvXAOfl1ptoVs82OMxO/HVOc1aX5HwL7 l4qZ0m7u+7JX7mD517GZrwEeHKFM8wH5FkbHue7AQY04zQYGFUqJ2OhZFxq8wc6mTk sIDwqtp/3hzHSp3Q0PiOFpiEX7AP0dyLbL8XtKaoBETV+WT0xfp5DfYj6c/VKrJRum 4ZBdfS0ew/p/+UplIIKNGR+ElN1wQv9QbnQqgathFmM5BCIgqhJwH2DcKqUSTMtWiu aIextEEGwHxkQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Reply-To: sashiko-reviews@lists.linux.dev To: "Atharva Tiwari" Cc: "Ihor Odainyi" , "Antoine Sidem" , "Aditya Garg" , "Andre Eikmeyer" , "Bjorn Helgaas" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "H. Peter Anvin" , "Rafael J. Wysocki" , "Len Brown" , "Linus Walleij" , "Bartosz Golaszewski" , "Sven Peter" , "Janne Grunau" , "Neal Gompa" , "Guenter Roeck" , "Jonathan Cameron" , "David Lechner" , =?utf-8?b?TnVubyBTw6E=?= , "Andy Shevchenko" , "Lee Jones" , "Pavel Machek" , "Griffin Kroah-Hartman" , "Hans de Goede" , =?utf-8?b?SWxwbyBKw6RydmluZW4=?= , "Sebastian Reichel" , "Alexandre Belloni" , "Wim Van Sebroeck" , "Jarkko Sakkinen" , "Mimi Zohar" , "Roberto Sassu" , "Dmitry Kasatkin" , "Eric Snowberg" , "Paul Moore" , "James Morris" , "Serge E. Hallyn" , linux-pci@vger.kernel.org, linux-gpio@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, mfd@lists.linux.dev, linux-rtc@vger.kernel.org, linux-watchdog@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org In-Reply-To: <20261204131619.5059-14-atharvatiwarilinuxdev@gmail.com> References: <20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com> <20261204131619.5059-14-atharvatiwarilinuxdev@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:48:51 +0000 X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 11 potential issues to consider: - [High] hwmon: macsmc: NULL pointer dereference in DT sensor label handling - [High] hwmon: macsmc: redundant SMC probes cause multi-minute PIO probe stalls - [Medium] hwmon: macsmc: uninitialized count read in macsmc_hwmon_populate_sensors_acpi() - [Medium] hwmon: macsmc: heap OOB write in macsmc_hwmon_register_sensors_acpi() - [Medium] hwmon: macsmc: invalid sensor keys and missing key validation on ACPI - [Medium] hwmon: macsmc: unvalidated F%dID read and fatal optional fan key errors - [Medium] hwmon: macsmc: missing big-endian conversion for integer keys on ACPI - [Medium] hwmon: macsmc_hwmon_resume() skips FS! and target restore, uses legacy PM - [Low] hwmon: macsmc: outdated docs, MODULE_DESCRIPTION, and whitespace changes - [Low] hwmon: macsmc: u16/__be16 mismatch in macsmc_hwmon_write_old_fan_manual() - [Low] hwmon: macsmc-hwmon uses deprecated legacy platform_driver.resume callback -- commit cda7f94f03b9c07639e3fb001f94e54d739b4e68 Author: Atharva Tiwari hwmon: add support for x86 macs in macsmc-hwmon This commit extends macsmc-hwmon to support Intel Macs over ACPI by adding static sensor descriptor tables, ACPI sensor and fan discovery, legacy FS! manual fan control, and a resume callback. > diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c > index 14b68cf8c283e..d531eb4122f89 100644 > --- a/drivers/hwmon/macsmc-hwmon.c > +++ b/drivers/hwmon/macsmc-hwmon.c [ ... ] > @@ -47,7 +52,7 @@ MODULE_PARM_DESC(fan_control, > struct macsmc_hwmon_sensor { > struct apple_smc_key_info info; > smc_key macsmc_key; > - char label[MAX_LABEL_LENGTH]; > + char *label; > u32 attrs; > }; [Severity: High] Does changing label to a char * pointer cause a NULL pointer dereference on Apple Silicon Device Tree systems? macsmc_hwmon_populate_sensors() zero-allocates each sensor array with devm_kcalloc(), leaving sensor->label NULL. When a Device Tree sensor node has a label property, macsmc_hwmon_create_sensor() calls strscpy_pad(sensor->label, label, sizeof(sensor->label)), writing to NULL with a pointer size; when a node omits label, macsmc_hwmon_populate_sensors= () dereferences NULL via if (*sensor->label). Making label (and macsmc_sensor_desc.name) const char *, assigning the DT label pointer directly (or via devm_kstrdup_const()), and checking sensor->label && *sensor->label would avoid this. [ ... ] > @@ -599,6 +605,25 @@ static int macsmc_hwmon_read_fan(struct macsmc_hwmon= *hwmon, u32 attr, int chan, > } > } > =20 > +static int macsmc_hwmon_write_old_fan_manual(struct macsmc_hwmon *hwmon,= u8 val, int channel) > +{ > + int ret; > + u16 buf; > + > + ret =3D apple_smc_read_u16(hwmon->smc, __SMC_KEY('F', 'S', '!', ' '), &= buf); > + if (ret) > + return ret; > + > + buf =3D be16_to_cpu(buf); > + > + if (val) > + buf |=3D BIT(channel); > + else > + buf &=3D ~BIT(channel); > + > + return apple_smc_write_u16(hwmon->smc, __SMC_KEY('F', 'S', '!', ' '), c= pu_to_be16(buf)); > +} [Severity: Low] Will buf trigger sparse endianness warnings here? buf is declared as host-endian u16, passed directly to be16_to_cpu(), and then cpu_to_be16(buf) is passed to apple_smc_write_u16(), which takes a plain u16. Reading and writing a __be16 variable via apple_smc_read() and apple_smc_write() would keep endianness annotations consistent. [ ... ] > +static int macsmc_hwmon_create_sensor_acpi(struct apple_smc *smc, > + struct macsmc_hwmon_sensor *sensor, smc_key key, char *name, u32 attrs) > +{ > + int ret; > + > + ret =3D apple_smc_get_key_info(smc, key, &sensor->info); > + if (ret) > + return ret; > + > + sensor->macsmc_key =3D key; > + sensor->label =3D name; > + sensor->attrs =3D attrs; > + > + return 0; > +} [Severity: Medium] Can this register unreadable keys, unsupported SMC types, or non-sensor keys as hwmon attributes and thermal zones? macsmc_hwmon_create_sensor_acpi() never checks APPLE_SMC_READABLE or whether sensor->info.type_code is handled by macsmc_hwmon_read_key(), so keys with types such as flag, hex_, or ch8* fail every read with -EOPNOTSUPP or -EIO. The static tables also include non-sensor entries such as audio scratchpads (MST1, MST2), power limits and throttles (MSTc, MSTg, PZ0T..PZ5T), and non-temperature keys (TCFC, TMBS, TH0e) in temp_sensors[], which are exposed as kernel thermal zones because HWMON_C_REGISTER_TZ is set. [ ... ] > +static int macsmc_hwmon_create_fan_acpi(struct apple_smc *smc, > + struct macsmc_hwmon_fan *fan, int num) > +{ > + const char num_char =3D num + '0'; > + int ret; > + > + ret =3D macsmc_hwmon_create_sensor_acpi(smc, &fan->now, > + __SMC_KEY('F', num_char, 'A', 'c'), NULL, 0); > + if (ret) > + return ret; > + > + if (apple_smc_key_exists(smc, __SMC_KEY('F', num_char, 'I', 'D'))) { > + char buf[17]; > + > + ret =3D apple_smc_read(smc, __SMC_KEY('F', num_char, 'I', 'D'), buf, 1= 6); > + if (ret < 0) > + return ret; > + > + buf[16] =3D '\0'; > + snprintf(fan->label, sizeof(fan->label), "%s", buf + 4); > + } else > + snprintf(fan->label, sizeof(fan->label), "Fan %d", num); > + > + ret =3D macsmc_hwmon_create_sensor_acpi(smc, &fan->min, > + __SMC_KEY('F', num_char, 'M', 'n'), NULL, 0); > + if (ret) > + return ret; > + > + ret =3D macsmc_hwmon_create_sensor_acpi(smc, &fan->max, > + __SMC_KEY('F', num_char, 'M', 'x'), NULL, 0); > + if (ret) > + return ret; > + > + ret =3D macsmc_hwmon_create_sensor_acpi(smc, &fan->set, > + __SMC_KEY('F', num_char, 'T', 'g'), NULL, 0); > + if (ret) > + return ret; [Severity: Medium] Can a short or unreadable F%dID key copy stale MMIO bytes or abort the enti= re hwmon probe? apple_smc_key_exists() discards info.size, so apple_smc_read() requests 16 bytes without checking that F%dID is 16 bytes long; apple_smc_acpi_mmio_rea= d() copies len bytes unconditionally from SRAM, and PIO mode times out with -EI= O. On read failure, or if any of F%dMn, F%dMx, or F%dTg is absent, returning r= et aborts macsmc_hwmon_probe() completely instead of falling back to "Fan %d" = or treating those keys as optional like macsmc_hwmon_create_fan() does. [ ... ] > +static int macsmc_hwmon_register_sensors_acpi( > + struct macsmc_hwmon *hwmon, > + struct macsmc_hwmon_sensors *sensors, > + const struct macsmc_sensor_desc *descs, > + size_t num_descs, > + u32 attrs) > +{ > + size_t count =3D 0; > + size_t i; > + int ret; > + > + for (i =3D 0; i < num_descs; i++) { > + if (apple_smc_key_exists(hwmon->smc, descs[i].key)) > + count++; > + } > + > + if (!count) > + return 0; > + > + sensors->sensors =3D devm_kcalloc(hwmon->dev, count, > + sizeof(*sensors->sensors), > + GFP_KERNEL); > + if (!sensors->sensors) > + return -ENOMEM; > + > + sensors->count =3D 0; > + > + for (i =3D 0; i < num_descs; i++) { > + if (!apple_smc_key_exists(hwmon->smc, descs[i].key)) > + continue; > + > + ret =3D macsmc_hwmon_create_sensor_acpi(hwmon->smc, > + &sensors->sensors[sensors->count], > + descs[i].key, > + descs[i].name, > + attrs); > + if (ret) > + return ret; > + > + sensors->count++; > + } > + > + return 0; > +} [Severity: Medium] Can a transient SMC timeout cause a heap out-of-bounds write past sensors->sensors? apple_smc_key_exists() treats transient -EIO timeouts the same as missing keys. If a key query fails during the counting pass and succeeds during the second pass, sensors->count exceeds the allocated count without any bounds check, overflowing sensors->sensors. [Severity: High] Will probing all 558 static keys twice over live SMC hardware stall boot for minutes on PIO Intel Macs? This function queries every key twice via apple_smc_key_exists() and a third time in macsmc_hwmon_create_sensor_acpi() for present keys (macsmc_hwmon_create_fan_acpi() similarly double-queries F%dMd). On PIO Macs, apple_smc_acpi_port_read() detects nonexistent keys only by timing out for 1,000 ms in apple_smc_acpi_port_wait() and disabling SMC interrupts on the first miss, so probing hundreds of absent keys twice stalls probe for over 15 minutes. Enumerating or binary-searching the sorted SMC key table via apple_smc_get_key_by_index() (like applesmc.c does) would avoid probing missing keys. > +static int macsmc_hwmon_populate_sensors_acpi(struct macsmc_hwmon *hwmon) > +{ > + int ret, i; > + u8 count; > + > + ret =3D apple_smc_read_u8(hwmon->smc, SMC_KEY(FNum), &count); > + if (count && !ret) { [Severity: Medium] Does if (count && !ret) read uninitialized stack variable count when reading FNum fails? On error, both apple_smc_acpi_mmio_read() and apple_smc_acpi_port_read() return without writing to the output buffer, leaving count uninitialized on fanless Macs without FNum and triggering KMSAN uninit-value reports. Checking if (!ret && count) avoids this. [ ... ] > + if (hwmon->smc->is_acpi) > + ret =3D macsmc_hwmon_populate_sensors_acpi(hwmon); > + else > + ret =3D macsmc_hwmon_populate_sensors(hwmon, hwmon->dev->of_node); [Severity: Medium] Will Intel Mac sensors backed by ui16, si16, ui32, or si32 SMC keys return byte-swapped values? Multi-byte integer keys on Intel ACPI SMCs are big-endian (as handled for F= S! in macsmc_hwmon_write_old_fan_manual() and in macsmc-power.c), but macsmc_hwmon_read_key() reads them in host byte order without converting wh= en smc->is_acpi is true: drivers/hwmon/macsmc-hwmon.c:macsmc_hwmon_read_key() { ... case __SMC_KEY('u', 'i', '1', '6'): { u16 ui16 =3D 0; ret =3D apple_smc_read_u16(smc, sensor->macsmc_key, &ui16); if (ret) return ret; *val =3D (s64)ui16 * scale; break; } ... } The same applies to si16, ui32, and si32, so any ACPI sensor using those types reports garbage on little-endian x86 hosts. [ ... ] > +static int macsmc_hwmon_resume(struct platform_device *pdev) > +{ > + struct macsmc_hwmon *hwmon =3D dev_get_drvdata(&pdev->dev); > + > + if (hwmon->smc->is_acpi && !hwmon->fan.has_old_manual) { > + int idx; > + int ret; > + > + for (idx =3D 0; idx < hwmon->fan.count; idx++) > + if (hwmon->fan.fans[idx].manual) { > + ret =3D macsmc_hwmon_write_key(hwmon->smc, > + &hwmon->fan.fans[idx].mode, 1); > + if (ret < 0) { > + dev_warn(&pdev->dev, > + "Unable to reenable fan manual, disabling\n"); > + hwmon->fan.fans[idx].manual =3D false; > + } > + } > + > + } > + > + return 0; > +} [Severity: Medium] Does macsmc_hwmon_resume() leave fan control state desynchronized with the SMC after suspend or hibernation? Checking !hwmon->fan.has_old_manual skips older Intel Macs that use FS!, so fans[idx].manual stays true in memory after the SMC resets to automatic mode and later fanX_target writes will not re-set FS! until userspace writes 0 first. On newer Intel Macs, re-enabling manual mode (F%dMd =3D 1) without restoring the saved F%dTg target speed locks fans in manual mode at the SMC= 's post-sleep or post-boot default target. [ ... ] > static struct platform_driver macsmc_hwmon_driver =3D { > .probe =3D macsmc_hwmon_probe, > + .resume =3D macsmc_hwmon_resume, > .driver =3D { > .name =3D "macsmc-hwmon", > .of_match_table =3D macsmc_hwmon_of_table, [Severity: Low] Should this use DEFINE_SIMPLE_DEV_PM_OPS() with .driver.pm =3D pm_sleep_ptr= () instead of the deprecated legacy platform_driver.resume callback? Using dev_pm_ops matches the other macsmc drivers in this series and allows the compiler to drop macsmc_hwmon_resume() when CONFIG_PM_SLEEP is disabled. [ ... ] > MODULE_DESCRIPTION("Apple Silicon SMC hwmon driver"); > MODULE_AUTHOR("James Calligeros "); > MODULE_LICENSE("Dual MIT/GPL"); > +MODULE_ALIAS("platform:macsmc-hwmon"); [Severity: Low] This isn't a bug, but Documentation/hwmon/macsmc-hwmon.rst, MODULE_DESCRIPTION, and the file header comment still describe the driver as Apple Silicon only. The patch also includes unrelated whitespace changes in macsmc_hwmon_write_f32(), macsmc_hwmon_is_visible(), and macsmc_hwmon_populate_sensors() that misalign continuation lines away from the opening parenthesis. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204131619.5059= -1-atharvatiwarilinuxdev@gmail.com?part=3D13