Skip to content

Commit 7b98c1c

Browse files
kuu-rtij-intel
authored andcommitted
platform/x86: thinkpad_acpi: Fix NULL pointer dereferences while probing
Some subdrivers make use of the global reference tpacpi_pdev during initialization, which is called from the platform driver's probe. However, after the commit 38b9ab8 ("platform/x86: thinkpad_acpi: Move subdriver initialization to tpacpi_pdriver's probe.") this variable is only properly initialized *after* probing and this can result in a NULL pointer dereference. In order to fix this without reverting the commit, register the platform bundle in two steps, first create and initialize tpacpi_pdev, then register the driver synchronously with platform_driver_probe(). This way the benefits of commit 38b9ab8 are preserved. Additionally, the commit 43fc63a ("platform/x86: thinkpad_acpi: Move HWMON initialization to tpacpi_hwmon_pdriver's probe") introduced a similar problem, however tpacpi_sensors_pdev is only used once inside the probe, so replace the global reference with the one given by the probe. Reported-by: Damian Tometzki <damian@riscv-rocks.de> Closes: https://lore.kernel.org/r/CAL=B37kdL1orSQZD2A3skDOevRXBzF__cJJgY_GFh9LZO3FMsw@mail.gmail.com/ Fixes: 38b9ab8 ("platform/x86: thinkpad_acpi: Move subdriver initialization to tpacpi_pdriver's probe.") Fixes: 43fc63a ("platform/x86: thinkpad_acpi: Move HWMON initialization to tpacpi_hwmon_pdriver's probe") Tested-by: Damian Tometzki <damian@riscv-rocks.de> Tested-by: Gene C <arch@sapience.com> Signed-off-by: Kurt Borja <kuurtb@gmail.com> Link: https://lore.kernel.org/r/20250330-thinkpad-fix-v1-1-4906b3fe6b74@gmail.com Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 0873308 commit 7b98c1c

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

drivers/platform/x86/thinkpad_acpi.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ static struct {
367367
u32 beep_needs_two_args:1;
368368
u32 mixer_no_level_control:1;
369369
u32 battery_force_primary:1;
370+
u32 platform_drv_registered:1;
370371
u32 hotkey_poll_active:1;
371372
u32 has_adaptive_kbd:1;
372373
u32 kbd_lang:1;
@@ -11820,10 +11821,10 @@ static void thinkpad_acpi_module_exit(void)
1182011821
platform_device_unregister(tpacpi_sensors_pdev);
1182111822
}
1182211823

11823-
if (tpacpi_pdev) {
11824+
if (tp_features.platform_drv_registered)
1182411825
platform_driver_unregister(&tpacpi_pdriver);
11826+
if (tpacpi_pdev)
1182511827
platform_device_unregister(tpacpi_pdev);
11826-
}
1182711828

1182811829
if (proc_dir)
1182911830
remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir);
@@ -11893,9 +11894,8 @@ static int __init tpacpi_pdriver_probe(struct platform_device *pdev)
1189311894

1189411895
static int __init tpacpi_hwmon_pdriver_probe(struct platform_device *pdev)
1189511896
{
11896-
tpacpi_hwmon = devm_hwmon_device_register_with_groups(
11897-
&tpacpi_sensors_pdev->dev, TPACPI_NAME, NULL, tpacpi_hwmon_groups);
11898-
11897+
tpacpi_hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, TPACPI_NAME,
11898+
NULL, tpacpi_hwmon_groups);
1189911899
if (IS_ERR(tpacpi_hwmon))
1190011900
pr_err("unable to register hwmon device\n");
1190111901

@@ -11965,15 +11965,23 @@ static int __init thinkpad_acpi_module_init(void)
1196511965
tp_features.quirks = dmi_id->driver_data;
1196611966

1196711967
/* Device initialization */
11968-
tpacpi_pdev = platform_create_bundle(&tpacpi_pdriver, tpacpi_pdriver_probe,
11969-
NULL, 0, NULL, 0);
11968+
tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, PLATFORM_DEVID_NONE,
11969+
NULL, 0);
1197011970
if (IS_ERR(tpacpi_pdev)) {
1197111971
ret = PTR_ERR(tpacpi_pdev);
1197211972
tpacpi_pdev = NULL;
11973-
pr_err("unable to register platform device/driver bundle\n");
11973+
pr_err("unable to register platform device\n");
11974+
thinkpad_acpi_module_exit();
11975+
return ret;
11976+
}
11977+
11978+
ret = platform_driver_probe(&tpacpi_pdriver, tpacpi_pdriver_probe);
11979+
if (ret) {
11980+
pr_err("unable to register main platform driver\n");
1197411981
thinkpad_acpi_module_exit();
1197511982
return ret;
1197611983
}
11984+
tp_features.platform_drv_registered = 1;
1197711985

1197811986
tpacpi_sensors_pdev = platform_create_bundle(&tpacpi_hwmon_pdriver,
1197911987
tpacpi_hwmon_pdriver_probe,

0 commit comments

Comments
 (0)