From nobody Fri Jun 12 15:50:48 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 890882F25F5; Thu, 14 May 2026 01:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778721248; cv=none; b=a6YXejD/RBOxCtjdxP6lJFpV1ZFcfsZbnWlvjszr/G9EW/Lws1DoHm8FZlw6nzDcfE9qaqOSQ16SobgDAZuO+uBOwytJsPp4QgstlycMqUgD6BR+vBZrnt65vejd1rcIRsrHuc07lfu10dmncCvdeWltShqpwOQZPGJ2emCHwFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778721248; c=relaxed/simple; bh=cxkxUPrSJ2IeZnHBjVvjS3/dazhBnmCEAiSpsqJniQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T6O3Mztn2d+cUMRjahi6QCVDFYDfU3IHJeLN3QmvbBPEgyWLYja7CdDSMrxPZgMkie7B+3p31+HkkgmiHCcZp8E8j1jauB+FL7DC8Du7K7GBozYV28og6SrbtCHsebiBAKj5zBTmjLYXD+e8ItTx0RXTt4MhV/d1Md5+JgzhkXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Lvu6R2tn; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Lvu6R2tn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=oi W6fdFwZ2NFuNvVtpEYyeDMUl1I4VJ6D0S5xvaXkcQ=; b=Lvu6R2tn2AGTFpb9Bv 6Q+XRGKz5LrnR/0+JeBxbnzQUuZswGUlIkDf+9j6w06ooO9fgMJyWvlt7RHxX+9z ykwmgTIsS0oXKxUWohLl9y0RAX+3F33zqBb43btoPMFTbKilTj15x3nA5ouUJpYY hDmD1Bp1/O0CUFzEF4U4zhpTM= Received: from debian.lenovo.com (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wD3Hy+1IQVqnFYFBQ--.27803S3; Thu, 14 May 2026 09:13:36 +0800 (CST) From: Kean To: Guenter Roeck Cc: Mark Pearson , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Kean Subject: [PATCH 1/3] hwmon: lenovo-ec-sensors: Fix EC signature check logic in probe Date: Thu, 14 May 2026 09:14:09 +0800 Message-ID: <20260514011411.4167069-2-rh_king@163.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260514011411.4167069-1-rh_king@163.com> References: <20260514011411.4167069-1-rh_king@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3Hy+1IQVqnFYFBQ--.27803S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ary8WryUJryDAF4rCr13CFg_yoW8WFWDpr 4UJFWrCrZYgr9rWa47Aa409ayYqasYyrW0gFy5WanxuFnrGas2g34rCFnIga4DXF1rta4I vryFqrWa9F1DAF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zND7awUUUUU= X-CM-SenderInfo: 5ukbyxlqj6il2tof0z/xtbC3wBUA2oFIcD3CQAA34 Content-Type: text/plain; charset="utf-8" The probe function reads a 4-byte signature ("MCHP") from the EC to verify it is a Microchip EC before binding the driver. The condition uses && (AND) to check if each byte differs from the expected value: if ((byte0 !=3D 'M') && (byte1 !=3D 'C') && (byte2 !=3D 'H') && (byte3 != =3D 'P')) This rejects the device only if ALL four bytes are wrong simultaneously. A partially matching signature (e.g. "MXXX") would pass the check and cause the driver to bind to a non-Microchip EC, as long as at least one byte matches the expected value. Change && to || so the driver is rejected when ANY byte does not match the expected "MCHP" signature. Signed-off-by: Kean Reviewed-by: Mark Pearson Reviewed-by: Mark Pearson --- drivers/hwmon/lenovo-ec-sensors.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/lenovo-ec-sensors.c b/drivers/hwmon/lenovo-ec-se= nsors.c index 8681bbf6665b..a32b1f2c6a3a 100644 --- a/drivers/hwmon/lenovo-ec-sensors.c +++ b/drivers/hwmon/lenovo-ec-sensors.c @@ -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); =20 - if ((inb_p(MCHP_EMI0_EC_DATA_BYTE0) !=3D 'M') && - (inb_p(MCHP_EMI0_EC_DATA_BYTE1) !=3D 'C') && - (inb_p(MCHP_EMI0_EC_DATA_BYTE2) !=3D 'H') && + if ((inb_p(MCHP_EMI0_EC_DATA_BYTE0) !=3D 'M') ||=20 + (inb_p(MCHP_EMI0_EC_DATA_BYTE1) !=3D 'C') ||=20 + (inb_p(MCHP_EMI0_EC_DATA_BYTE2) !=3D 'H') || (inb_p(MCHP_EMI0_EC_DATA_BYTE3) !=3D 'P')) { release_region(IO_REGION_START, IO_REGION_LENGTH); return -ENODEV; --=20 2.47.3 From nobody Fri Jun 12 15:50:48 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6207C3019A9; Wed, 20 May 2026 02:32:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779244351; cv=none; b=LHwgyGhmUhkBvAGY+Lx0XWj10NvJtrAQwSSH04ZR4cXx6+KHj31hWsEmcTVL1V6ToMiYX9ZRJdh9bGMoy98DFLkVwY/+O6vsWp2DWDgPc0DUjZjvYT0XxDGbnO5ycsuQn9QnD7vC0yN3fV7fcojX0voE/7Q1JhbLjxMaefxkszo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779244351; c=relaxed/simple; bh=hbzNeDUA24AMI3s3KMnTEBw/siHRoQTe7D1NJinOdi0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CLJ6OglFNRXLrOWMpuTROjs3AFYtpjGZ55hkp8fnF0/NKR+tJ80BIEcmrZZos/UKnSODmMYeFjTtyicdSCsD6SpbcjyvY0qBfpnrCDmNw/Ms9T5oypmgVV9vOGe22SEryItysGrht10xMQrY/VI7InJpkFcIiJal3lLFFv9gcRw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=NFCHJfJL; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="NFCHJfJL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Fx ODPs4QJ6dM2BqVvq1lkUcrICYdhCr64tLgPY/ObnE=; b=NFCHJfJL3BNuGL6N1N JWJEjKFhR4JBiqBXiXU7g2hxWipXn+6QDWADGqOqvgSQ5Ut+6o3SXt1aWj294jL4 bnNr99Ws3MdhuN0d9ayXKLwiberfu9q0vvOnRFv5QK2Fl+45Qw6fbCuJMYY7mVJw ZeEHz/aCCscg6xVufY0Dye5DM= Received: from debian.lenovo.com (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wCXhxccHQ1qsLyhCQ--.43220S2; Wed, 20 May 2026 10:31:56 +0800 (CST) From: Kean Ren To: Guenter Roeck Cc: Mark Pearson , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Kean Ren Subject: [PATCH v2 2/2] hwmon: (lenovo-ec-sensors): Fix EC "MCHP" signature validation logic Date: Wed, 20 May 2026 10:32:22 +0800 Message-ID: <20260520023222.18321-1-rh_king@163.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260514011411.4167069-1-rh_king@163.com> References: <20260514011411.4167069-1-rh_king@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wCXhxccHQ1qsLyhCQ--.43220S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7AFWUCr1kWrWDJr4fuw45Jrb_yoW8Cr4Dpr 4UXFW8Crn5WryDWw17t347uFy5Ja4rt3y8Wry3Wan5CrnxWa97urWFkFyagas8ZFs5Ja4I yFy5trWY9F1DAF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRWv38UUUUU= X-CM-SenderInfo: 5ukbyxlqj6il2tof0z/xtbC-Bws2moNHRz6BgAA3M Content-Type: text/plain; charset="utf-8" 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. Also remove the now-unnecessary braces around the single-statement if body. Reviewed-by: Mark Pearson Signed-off-by: Kean Ren --- Changes in v2: No change, just correct the format. drivers/hwmon/lenovo-ec-sensors.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/lenovo-ec-sensors.c b/drivers/hwmon/lenovo-ec-se= nsors.c index 45db49e189d3..01138eed45e5 100644 --- a/drivers/hwmon/lenovo-ec-sensors.c +++ b/drivers/hwmon/lenovo-ec-sensors.c @@ -537,12 +537,11 @@ static int lenovo_ec_probe(struct platform_device *pd= ev) outw_p(MCHP_SING_IDX, MCHP_EMI0_EC_ADDRESS); mutex_unlock(&ec_data->mec_mutex); =20 - if ((inb_p(MCHP_EMI0_EC_DATA_BYTE0) !=3D 'M') && - (inb_p(MCHP_EMI0_EC_DATA_BYTE1) !=3D 'C') && - (inb_p(MCHP_EMI0_EC_DATA_BYTE2) !=3D 'H') && - (inb_p(MCHP_EMI0_EC_DATA_BYTE3) !=3D 'P')) { + if ((inb_p(MCHP_EMI0_EC_DATA_BYTE0) !=3D 'M') || + (inb_p(MCHP_EMI0_EC_DATA_BYTE1) !=3D 'C') || + (inb_p(MCHP_EMI0_EC_DATA_BYTE2) !=3D 'H') || + (inb_p(MCHP_EMI0_EC_DATA_BYTE3) !=3D 'P')) return -ENODEV; - } =20 dmi_id =3D dmi_first_match(thinkstation_dmi_table); =20 --=20 2.53.0 From nobody Fri Jun 12 15:50:48 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EB07308F0A; Thu, 14 May 2026 01:14:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778721252; cv=none; b=KFJigo8xXp9sl/z1pROzyQimgHcd13bQoKHApd8TZomqKpfam2FIzLwDqUXrfhqwjEbK3n7f6RmHwOLqrJnZ4b+pXRGPvDZKSAUNh7MSsHRxsyX769Z96sBtQd0V3PHx5wD0RPh9tbPek5FHVZkEV+uIbmA8B7U95SO3yafYGBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778721252; c=relaxed/simple; bh=sXLih5raIl33sSNlnOoF6ZEBSgpWgjRZfHKHN76USE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WMH9k9K1Fw7Mm5cTGK2ZgZZZm3s9JubauOnRN9KMN50Q6r6ORt5hsMjeosNlhBdILl9Rv/Y0kW6Ou6amg6/fPl77nG+XI4UWoE3I60AttzKT7MPucs9dwwWcMOnji3zY9UTpxJRekTrHztCbUgeWLXdIbv9iKnG42QKnajNuzH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Y9Vp3y4t; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Y9Vp3y4t" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Kc Drh3VbtdURX7weCLGXHiqFH5wBtE/xwYPo6+ozhNU=; b=Y9Vp3y4taV180X+Pxs rKAxYV4+hvWdk2uoFq9yeF64FZdMAh1V6FZf5pUr8lJ5Jr1Fc6UKDDLFD7C1C0RF zkjtAkxaYYA8skrGwaeFDBD57+OpQBOSjw6yk56RFpSkxcTXzTi0AF8XDKI5Sg5H ij7wPjAY77Q9zo5QU1WM4xd6Y= Received: from debian.lenovo.com (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wD3Hy+1IQVqnFYFBQ--.27803S4; Thu, 14 May 2026 09:13:40 +0800 (CST) From: Kean To: Guenter Roeck Cc: Mark Pearson , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Kean Subject: [PATCH 2/3] hwmon: lenovo-ec-sensors: Fix NULL pointer dereference when DMI match fails Date: Thu, 14 May 2026 09:14:10 +0800 Message-ID: <20260514011411.4167069-3-rh_king@163.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260514011411.4167069-1-rh_king@163.com> References: <20260514011411.4167069-1-rh_king@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3Hy+1IQVqnFYFBQ--.27803S4 X-Coremail-Antispam: 1Uf129KBjvdXoWrtF45Xw13Jw1fJF1UZFWUurg_yoWDWrc_ur 1Uur97XryYywn0yr4vvF4S9F90kFWq9rykZr1Iy3yfAw18XFs5WFWkZrs0v3WfurWUAFZ8 A395AF93uw4fAjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRpHqxUUUUUU== X-CM-SenderInfo: 5ukbyxlqj6il2tof0z/xtbC3wRVBGoFIcT3RAAA3z Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Mark Pearson --- 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-se= nsors.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) } =20 dmi_id =3D dmi_first_match(thinkstation_dmi_table); + if (!dmi_id) + return -ENODEV; =20 switch ((long)dmi_id->driver_data) { case 0: --=20 2.47.3 From nobody Fri Jun 12 15:50:48 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C2E33093DF; Thu, 14 May 2026 01:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778721250; cv=none; b=FERJJ9FMe4lxwRuN7r9CEm39lrmCnHUmpRm1TbqtaRyTD4OXajwtkAu8NWK83ayHiA6kXRfZp77agxTvdRAU3XvVWsStPPmlhmKdGS539hC6P8GfOISJHQ2E6sKSOpVGiqe7W4HqEz1LAX7txYsgprtAXtESOcNVgNvYxdshmBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778721250; c=relaxed/simple; bh=206ZJi52YVqCPsmcE8rNx3mGgWx0LmTRdSIDdbqLAr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tO6bl+aJB7C/11Ogq0QXsXVdnk9eISJXJl9DBwvJjOsz2hCwyg/I/H3YCHcLzf+NDgf4YYYlIxEX1fOJxIkPRE9ErN8kD0IMii4viMBsGPkLqZH0osWQAt+AiHauxxNg/GKvEZ9xljtnVz3BcjwxcvVJDjbf3kvZlbAn1vyL7mA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=HizGYsDb; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="HizGYsDb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=x+ tjZgJ/1ED50GWoMRrtTY0DZaXuGmFDlBwH0MLLdtk=; b=HizGYsDbzQZFhJITTa 4ssHc8Yv1QQTyaSAI2XVgUV1taCfNtz5OOwrnbrIgbM+aI5Pvg95d2x4e2PdaQn4 Klgxv/kAoVdxvI/LTwJKDJ4aljjtCaxnES3q27iBB2+k8fBxdrunKK/mk/YFX5nk 9eX/CewRoVJPgNAonDinA2srw= Received: from debian.lenovo.com (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wD3Hy+1IQVqnFYFBQ--.27803S5; Thu, 14 May 2026 09:13:42 +0800 (CST) From: Kean To: Guenter Roeck Cc: Mark Pearson , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Kean Subject: [PATCH 3/3] hwmon: lenovo-ec-sensors: Use devm_request_region for automatic cleanup Date: Thu, 14 May 2026 09:14:11 +0800 Message-ID: <20260514011411.4167069-4-rh_king@163.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260514011411.4167069-1-rh_king@163.com> References: <20260514011411.4167069-1-rh_king@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3Hy+1IQVqnFYFBQ--.27803S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFy5Kr48JFW3uFy3ur45Wrg_yoW5AF4kp3 yrJFW5Wr95GFyj934kA3Z7ZFn3Aws3taySkry5Kwn3u3ZrJr98GrZ5A3Z29FW2yFW8J3Wf Xw15trWS9F4DXrUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UPfHbUUUUU= X-CM-SenderInfo: 5ukbyxlqj6il2tof0z/xtbC+wZVBGoFIcYMDQAA3l Content-Type: text/plain; charset="utf-8" Replace manual request_region()/release_region() with devm_request_region(). This lets the device-managed framework handle I/O region lifetime automatically and fixes: - A double release_region() when probe fails after acquiring the I/O region: the probe error path releases it, and then lenovo_ec_init() releases it again on the same error path. - A release-after-free in lenovo_ec_exit() where release_region() was called after platform_device_unregister(), which has already released the I/O region via the platform device removal path. - Missing release_region() in lenovo_ec_probe() on the DMI match failure path, which leaked the I/O region. Remove all manual release_region() calls that are now handled automatically by the devm framework. Signed-off-by: Kean Reviewed-by: Mark Pearson --- drivers/hwmon/lenovo-ec-sensors.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/lenovo-ec-sensors.c b/drivers/hwmon/lenovo-ec-se= nsors.c index b0f2a04ce679..ea74bddbad5a 100644 --- a/drivers/hwmon/lenovo-ec-sensors.c +++ b/drivers/hwmon/lenovo-ec-sensors.c @@ -519,8 +519,8 @@ static int lenovo_ec_probe(struct platform_device *pdev) if (!ec_data) return -ENOMEM; =20 - if (!request_region(IO_REGION_START, IO_REGION_LENGTH, "LNV-WKS")) { - pr_err(":request fail\n"); + if (!devm_request_region(dev, IO_REGION_START, IO_REGION_LENGTH, "LNV-WKS= ")) { + dev_err(dev, "Failed to request I/O region.\n"); return -EIO; } =20 @@ -541,7 +541,6 @@ static int lenovo_ec_probe(struct platform_device *pdev) (inb_p(MCHP_EMI0_EC_DATA_BYTE1) !=3D 'C') ||=20 (inb_p(MCHP_EMI0_EC_DATA_BYTE2) !=3D 'H') || (inb_p(MCHP_EMI0_EC_DATA_BYTE3) !=3D 'P')) { - release_region(IO_REGION_START, IO_REGION_LENGTH); return -ENODEV; } =20 @@ -579,7 +578,8 @@ static int lenovo_ec_probe(struct platform_device *pdev) lenovo_ec_chip_info.info =3D lenovo_ec_hwmon_info_p8; break; default: - release_region(IO_REGION_START, IO_REGION_LENGTH); + dev_err(dev, "Unsupported platform type %ld\n", + (long)dmi_id->driver_data); return -ENODEV; } =20 @@ -608,10 +608,8 @@ static int __init lenovo_ec_init(void) platform_create_bundle(&lenovo_ec_sensors_platform_driver, lenovo_ec_probe, NULL, 0, NULL, 0); =20 - if (IS_ERR(lenovo_ec_sensors_platform_device)) { - release_region(IO_REGION_START, IO_REGION_LENGTH); + if (IS_ERR(lenovo_ec_sensors_platform_device))=20 return PTR_ERR(lenovo_ec_sensors_platform_device); - } =20 return 0; } @@ -619,7 +617,6 @@ module_init(lenovo_ec_init); =20 static void __exit lenovo_ec_exit(void) { - release_region(IO_REGION_START, IO_REGION_LENGTH); platform_device_unregister(lenovo_ec_sensors_platform_device); platform_driver_unregister(&lenovo_ec_sensors_platform_driver); } --=20 2.47.3