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=1796395027; b=N6Y+UMn66bweWU3zj48RAx2o/iTXSp++Me9wKBFiNBoZBUHQ0vFGOvHtLZPYoshEHxGT qaQ273U7ZhyC23oLvW+4IAJYT/tT4cxeQKBLPaSDUnM6UHuAnSGWMgUFbcd46iVubVolX g0I0/4kT6xKPm7uV60pgNL1zOWfcj9eK4r+piOAc2/dVSFsNv0W2Kq99vRQAqPJy+VppX P92MCLdjJGMgqLsI1tJ9ggAa/ulUghBY0hm1Jj7ivaUaQMC82MMMlYxNDKNkx1cwxXoHa A1T+9ahec6gefUDAH0qMoKdQiUB/M+Cj7iQ93sqRC7W89IwHEf5+3e2qeacuqBa+/hg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796395027; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=9uHWiiFPnKNYkVqnlJMj72+cPitZ9Zykll8M47A0aRM=; b=uYVayxgz3z+erypYb1K4UMi3Z6katwwqrS1mPWjDSgpSr8fs6XJKPoklMH04UAqwQVIc 1cK8PUl7uzrrZl96Iou+q1LyW0HRwPirt63ZWKBOV1cyQ2nHP063CEp94/S1EjNjZGYQh pjuNX7TTHdH53LOanBP5PsK9wBl32bEZWPJfOExXXBtKbRV31aIYc/IxFt6xcdxlllnhA xrVDf2hkIn+wI1J64IW81cC5w/y+b8PMyq66aMulZpMzNfKMuO3ghGTBv0igvZpFjzAeL bFex9IhCE17chv1mSpHqEMw57XAk4T5mu1Uk9Z7ziE1SHhSWYZXqXHmiLjKg41aWmLQ== 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=Tu1JDFfx; 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 B3A78606A338; Fri, 4 Dec 2026 14:37:07 +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=Tu1JDFfx Received: by smtp.kernel.org (Postfix) with ESMTPSA id 459C81F000C2; Fri, 4 Dec 2026 14:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796395027; bh=9uHWiiFPnKNYkVqnlJMj72+cPitZ9Zykll8M47A0aRM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Tu1JDFfxeCtnypkg3bqmi+XMs8OXntt+GS5e/1yiTUQGfapkHDpMNeikWrGgGf6tp rleMh8bliNLGWM6sK5fSWhU3zTpYdBDxGZkw7BuCPpHKNwJLSBVx7poLv9HPZ0kq4M dYAY2N1UFjyWU/KGSOdTGm11lgd8ERkVxpU4CJKKIEVSTP+vYcgvym14GkhJ9ZE/Wv xfkHdDMxeWJDsZbVNQ2VZ5Fxc1wUux2IcO26R3fS3yBTsj8MmIPmbaqh99gK3Ku+eI je6f8h6VSK505nrF7E5XXaI5Hj4ZiIypm2p47aNbHApRMLu2EHU/b+f2fGOH0UZ/YW KpuItsyolVRFA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 12/14] hwmon/macsmc: add more types Reply-To: sashiko-reviews@lists.linux.dev To: "Atharva Tiwari" Cc: "Ihor Odainyi" , "Antoine Sidem" , "Aditya Garg" , "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-13-atharvatiwarilinuxdev@gmail.com> References: <20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com> <20261204131619.5059-13-atharvatiwarilinuxdev@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:37:04 +0000 X-Mailing-List: linux-pci@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 5 potential issues to consider: - [High] hwmon: (macsmc) missing endian conversion in macsmc_hwmon_read_key() - [Medium] hwmon: (macsmc) unclamped s64 to long truncation in macsmc_hwmon_read_key() - [Low] hwmon: macsmc: sparse __be16 type mismatches on SMC fixed-point I/O - [Low] hwmon: macsmc: duplicate fixed-point decoding in macsmc_hwmon_read_key() - [Low] hwmon: missing range check for fpe2 write in macsmc_hwmon_write_key() -- commit fa0827d4a4896bab5a321d44d03d23f333c92b8e Author: Atharva Tiwari hwmon/macsmc: add more types This commit adds read support for common integer and fixed-point SMC key types in macsmc_hwmon_read_key() and write support for fpe2 fan speed keys in macsmc_hwmon_write_key(). > diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c > index 1500ec2cc9f83..14b68cf8c283e 100644 > --- a/drivers/hwmon/macsmc-hwmon.c > +++ b/drivers/hwmon/macsmc-hwmon.c > @@ -221,6 +221,313 @@ static int macsmc_hwmon_read_key(struct apple_smc *= smc, [ ... ] > + /* unsigned 16-bit integer */ > + 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; > + } [Severity: High] Do the ui16, si16, ui32, and si32 cases need endianness conversion? The ACPI SMC backend copies raw big-endian firmware bytes without swapping, as macsmc_battery_get_property() accounts for when smc->is_acpi is true. Using the raw values directly returns byte-swapped readings and corrupted signs on Intel ACPI Macs. Converting from big-endian when smc->is_acpi is true and from little-endian otherwise (sign-extending si16 and si32 afterward) would handle both Intel and Apple Silicon backends. [ ... ] > + /* unsigned 32-bit integer */ > + case __SMC_KEY('u', 'i', '3', '2'): { > + u32 ui32 =3D 0; > + > + ret =3D apple_smc_read_u32(smc, sensor->macsmc_key, &ui32); > + if (ret) > + return ret; > + > + *val =3D (s64)ui32 * scale; > + break; > + } [Severity: Medium] Can assigning the scaled s64 product directly to long *val truncate on 32-bit kernels? SENSORS_MACSMC_HWMON does not depend on 64BIT, and macsmc_hwmon_read() passes scale =3D 1000000 for power sensors. On 32-bit builds where long is 32 bits, scaled values for ui16, si16, ui32, si32, spc3, spd2, and spf0 can exceed [LONG_MIN, LONG_MAX] and silently wrap or invert sign. Clamping with clamp_t(s64, ..., LONG_MIN, LONG_MAX) before assigning to *val would match the saturation done for flt and ioft above. [ ... ] > + /* 2.14 unsigned fixed point decimal */ > + case __SMC_KEY('f', 'p', '2', 'e'): { > + u16 fp2e; > + > + ret =3D apple_smc_read_u16(smc, sensor->macsmc_key, &fp2e); > + if (ret) > + return ret; > + > + *val =3D mult_frac((s64)be16_to_cpu(fp2e), scale, BIT(14)); > + break; > + } [Severity: Low] Will sparse warn about __be16 type mismatches across the fixed-point cases? All 20 new fp* and sp* cases pass host-endian u16 or s16 variables to be16_to_cpu(), and the fpe2 case in macsmc_hwmon_write_key() passes cpu_to_be16() to apple_smc_write_u16(). Using __be16 buffers with apple_smc_read()/apple_smc_write() or dedicated __be16 helpers would eliminate these sparse warnings. > + > + /* 3.13 unsigned fixed point decimal */ > + case __SMC_KEY('f', 'p', '3', 'd'): { > + u16 fp3d; > + > + ret =3D apple_smc_read_u16(smc, sensor->macsmc_key, &fp3d); > + if (ret) > + return ret; > + > + *val =3D mult_frac((s64)be16_to_cpu(fp3d), scale, BIT(13)); > + break; > + } [Severity: Low] Can the 20 fp* and sp* cases be collapsed into a parameterized helper instead of repeating the read and scaling boilerplate? Aside from the repetition (and minor inconsistencies between BIT(n) and 1 << n divisors and variable initialization), similar fixed-point decoding also exists in macsmc_battery_acpi_read() in drivers/power/supply/macsmc-power.c and could potentially be shared. [ ... ] > @@ -263,6 +570,9 @@ static int macsmc_hwmon_write_key(struct apple_smc *s= mc, > /* unsigned 8-bit integer */ > case __SMC_KEY('u', 'i', '8', ' '): > return apple_smc_write_u8(smc, sensor->macsmc_key, val); > + /* 14.2 fixed point decimal */ > + case __SMC_KEY('f', 'p', 'e', '2'): > + return apple_smc_write_u16(smc, sensor->macsmc_key, cpu_to_be16(val <<= 2)); [Severity: Low] Should this check that val is within [0, 0x3fff] before shifting and narrowing to 16 bits? macsmc_hwmon_write_fan() only bounds val against fan->min and fan->max, which macsmc_hwmon_create_fan() parses independently without requiring them to be fpe2. If a negative value reaches this path, val << 2 is signed left-shift undefined behavior, and val >=3D 0x4000 silently wraps. Returning -EINVAL when val < 0 || val >=3D 0x4000, matching applesmc_hwmon_write() in drivers/hwmon/applesmc.c, would prevent both. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204131619.5059= -1-atharvatiwarilinuxdev@gmail.com?part=3D12