Skip to contentSkip to conversation

platform/x86: bitland-mifs-wmi: Fix NULL pointer dereference during suspend/resume

PATCH Superseded Mingyou Chen 3 participants 3 messages Jun 20 – Jul 1 x86 platform drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: bitland-mifs-wmi: Fix NULL pointer dereference during suspend/resume

The driver registers two distinct WMI devices: a control device (BITLAND_WMI_CONTROL) and an event device (BITLAND_WMI_EVENT). During the probe phase, the event device handling path returns early before initializing the platform profile device (data->pp_dev), leaving it NULL.

However, the PM sleep operations are registered globally for the WMI driver
and are triggered for both devices. When entering suspend, the event device
invokes bitland_mifs_wmi_suspend(), which passes the uninitialized data->pp_dev (NULL) into laptop_profile_get(). This leads to a NULL pointer
dereference inside dev_get_drvdata(), causing a kernel Oops and halting the
suspend sequence.

Fix this by adding a validity check for data->pp_dev in both the suspend and resume callbacks, safely skipping profile operations for the event device.

---
 drivers/platform/x86/bitland-mifs-wmi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/platform/x86/bitland-mifs-wmi.c +8 -0
index b0d06a80e89e..3a373184519d 100644
@@ -300,6 +300,10 @@ static int bitland_mifs_wmi_suspend(struct device *dev)
 	enum platform_profile_option profile;
 	int ret;
 
+	/* Skip event device */
+	if (!data->pp_dev)
+		return 0;
+
 	ret = laptop_profile_get(data->pp_dev, &profile);
 	if (ret == 0)
 		data->saved_profile = profile;
@@ -311,6 +315,10 @@ static int bitland_mifs_wmi_resume(struct device *dev)
 {
 	struct bitland_mifs_wmi_data *data = dev_get_drvdata(dev);
 
+	/* Skip event device */
+	if (!data->pp_dev)
+		return 0;
+
 	dev_dbg(dev, "Resuming, restoring profile %d\n", data->saved_profile);
 	return laptop_profile_set(dev, data->saved_profile);
 }

base-commit: 1a3746ccbb0a97bed3c06ccde6b880013b1dddc1

Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw

Am 20.06.26 um 10:18 schrieb Mingyou Chen:

Quoted 17 lines

The driver registers two distinct WMI devices: a control device (BITLAND_WMI_CONTROL) and an event device (BITLAND_WMI_EVENT). During the probe phase, the event device handling path returns early before initializing the platform profile device (data->pp_dev), leaving it NULL.

However, the PM sleep operations are registered globally for the WMI driver
and are triggered for both devices. When entering suspend, the event device
invokes bitland_mifs_wmi_suspend(), which passes the uninitialized data->pp_dev (NULL) into laptop_profile_get(). This leads to a NULL pointer
dereference inside dev_get_drvdata(), causing a kernel Oops and halting the
suspend sequence.

Quoted 3 lines

Fix this by adding a validity check for data->pp_dev in both the suspend and resume callbacks, safely skipping profile operations for the event device.

Hi,

very good catch, i totally missed this during the initial review xd.

Quoted 34 lines
---
  drivers/platform/x86/bitland-mifs-wmi.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/platform/x86/bitland-mifs-wmi.c +8 -0
index b0d06a80e89e..3a373184519d 100644
@@ -300,6 +300,10 @@ static int bitland_mifs_wmi_suspend(struct device *dev)
  	enum platform_profile_option profile;
  	int ret;
 
+	/* Skip event device */
+	if (!data->pp_dev)
+		return 0;
+
  	ret = laptop_profile_get(data->pp_dev, &profile);
  	if (ret == 0)
  		data->saved_profile = profile;
@@ -311,6 +315,10 @@ static int bitland_mifs_wmi_resume(struct device *dev)
  {
  	struct bitland_mifs_wmi_data *data = dev_get_drvdata(dev);
 
+	/* Skip event device */
+	if (!data->pp_dev)
+		return 0;
+
  	dev_dbg(dev, "Resuming, restoring profile %d\n", data->saved_profile);
  	return laptop_profile_set(dev, data->saved_profile);
  }

base-commit: 1a3746ccbb0a97bed3c06ccde6b880013b1dddc1

maintainer
#2 lore raw
In reply to Mingyou Chen
Quoted 17 lines · Mingyou Chen

The driver registers two distinct WMI devices: a control device (BITLAND_WMI_CONTROL) and an event device (BITLAND_WMI_EVENT). During the probe phase, the event device handling path returns early before initializing the platform profile device (data->pp_dev), leaving it NULL.

However, the PM sleep operations are registered globally for the WMI driver
and are triggered for both devices. When entering suspend, the event device
invokes bitland_mifs_wmi_suspend(), which passes the uninitialized data->pp_dev (NULL) into laptop_profile_get(). This leads to a NULL pointer
dereference inside dev_get_drvdata(), causing a kernel Oops and halting the
suspend sequence.

Quoted 5 lines

Fix this by adding a validity check for data->pp_dev in both the suspend and resume callbacks, safely skipping profile operations for the event device.

This seems to be missing a Fixes tag?

Quoted 33 lines
---
 drivers/platform/x86/bitland-mifs-wmi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/platform/x86/bitland-mifs-wmi.c +8 -0
index b0d06a80e89e..3a373184519d 100644
@@ -300,6 +300,10 @@ static int bitland_mifs_wmi_suspend(struct device *dev)
 	enum platform_profile_option profile;
 	int ret;
 
+	/* Skip event device */
+	if (!data->pp_dev)
+		return 0;
+
 	ret = laptop_profile_get(data->pp_dev, &profile);
 	if (ret == 0)
 		data->saved_profile = profile;
@@ -311,6 +315,10 @@ static int bitland_mifs_wmi_resume(struct device *dev)
 {
 	struct bitland_mifs_wmi_data *data = dev_get_drvdata(dev);
 
+	/* Skip event device */
+	if (!data->pp_dev)
+		return 0;
+
 	dev_dbg(dev, "Resuming, restoring profile %d\n", data->saved_profile);
 	return laptop_profile_set(dev, data->saved_profile);
 }

base-commit: 1a3746ccbb0a97bed3c06ccde6b880013b1dddc1

Signature · 1 line
 i.