]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: (lenovo-ec-sensors): Fix EC "MCHP" signature validation logic
authorKean Ren <rh_king@163.com>
Thu, 21 May 2026 03:52:28 +0000 (11:52 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Thu, 21 May 2026 13:48:19 +0000 (06:48 -0700)
The EC signature check uses && instead of || between the four
byte comparisons.  With &&, the condition is true only when ALL
four bytes fail to match simultaneously, meaning the driver
accepts a device as a valid Microchip EC if ANY single byte of
the 4-byte "MCHP" signature happens to match.

Due to short-circuit evaluation, if the first byte reads back as
'M' (0x4D, a very common register value), the remaining three
comparisons are skipped entirely and the device is accepted.

Change && to || so the check rejects devices that do not fully
match the expected EC signature, as originally intended.

Fixes: 70118f85e6538 ("hwmon: Add EC Chip driver for Lenovo ThinkStation motherboards")
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Kean Ren <rh_king@163.com>
Link: https://lore.kernel.org/r/20260521035228.533317-3-rh_king@163.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/lenovo-ec-sensors.c

index a16cc5e4053a22ed2fce4aa0c96396659b634c80..24a182abf9a3d4592590f0afce714545cfbe8b5e 100644 (file)
@@ -537,9 +537,9 @@ static int lenovo_ec_probe(struct platform_device *pdev)
        outw_p(MCHP_SING_IDX, MCHP_EMI0_EC_ADDRESS);
        mutex_unlock(&ec_data->mec_mutex);
 
-       if ((inb_p(MCHP_EMI0_EC_DATA_BYTE0) != 'M') &&
-           (inb_p(MCHP_EMI0_EC_DATA_BYTE1) != 'C') &&
-           (inb_p(MCHP_EMI0_EC_DATA_BYTE2) != 'H') &&
+       if ((inb_p(MCHP_EMI0_EC_DATA_BYTE0) != 'M') ||
+           (inb_p(MCHP_EMI0_EC_DATA_BYTE1) != 'C') ||
+           (inb_p(MCHP_EMI0_EC_DATA_BYTE2) != 'H') ||
            (inb_p(MCHP_EMI0_EC_DATA_BYTE3) != 'P'))
                return -ENODEV;