mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-05-26 11:40:24 +02:00
hwmon: (lenovo-ec-sensors): Convert to devm_request_region()
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-use window in lenovo_ec_exit() where
release_region() was called before platform_device_unregister(),
leaving the hwmon device active with a released I/O region.
- Missing release_region() in lenovo_ec_probe() if
devm_hwmon_device_register_with_info() fails.
Remove all four manual release_region() calls that are now handled
automatically and replace request_region with
devm_request_region, use dev_err replace pr_err.
Also remove the now-unnecessary braces around the single-statement
if body.
Fixes: 70118f85e6 ("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-2-rh_king@163.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
@@ -519,8 +519,8 @@ static int lenovo_ec_probe(struct platform_device *pdev)
|
||||
if (!ec_data)
|
||||
return -ENOMEM;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -540,10 +540,8 @@ static int lenovo_ec_probe(struct platform_device *pdev)
|
||||
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')) {
|
||||
release_region(IO_REGION_START, IO_REGION_LENGTH);
|
||||
(inb_p(MCHP_EMI0_EC_DATA_BYTE3) != 'P'))
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
dmi_id = dmi_first_match(thinkstation_dmi_table);
|
||||
|
||||
@@ -577,7 +575,6 @@ static int lenovo_ec_probe(struct platform_device *pdev)
|
||||
lenovo_ec_chip_info.info = lenovo_ec_hwmon_info_p8;
|
||||
break;
|
||||
default:
|
||||
release_region(IO_REGION_START, IO_REGION_LENGTH);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
@@ -606,10 +603,8 @@ static int __init lenovo_ec_init(void)
|
||||
platform_create_bundle(&lenovo_ec_sensors_platform_driver,
|
||||
lenovo_ec_probe, NULL, 0, NULL, 0);
|
||||
|
||||
if (IS_ERR(lenovo_ec_sensors_platform_device)) {
|
||||
release_region(IO_REGION_START, IO_REGION_LENGTH);
|
||||
if (IS_ERR(lenovo_ec_sensors_platform_device))
|
||||
return PTR_ERR(lenovo_ec_sensors_platform_device);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -617,7 +612,6 @@ module_init(lenovo_ec_init);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user