Skip to contentSkip to conversation

scsi: ufs: ufs-pci: Check hba->vops in system PM callbacks

PATCH Applied Stanley Jhu 3 participants 3 messages Nov 11 – Nov 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: ufs: ufs-pci: Check hba->vops in system PM callbacks

ufshcd_pci_tbl[] defines the Samsung 0xC00C and AMD 0x1B29 PCI IDs with .driver_data set to 0, so ufshcd_pci_probe() leaves hba->vops NULL. Both ufshcd_pci_suspend_prepare() and ufshcd_pci_resume_complete() dereference hba->vops->name without checking hba->vops:

1. System suspend on an AMD 0x1B29 or Samsung 0xC00C host enters the PM prepare phase and calls ufshcd_pci_suspend_prepare().
2. ufshcd_pci_suspend_prepare() evaluates strcmp(hba->vops->name, "intel-pci"), dereferences NULL, and triggers a kernel oops in the suspending task.

Check that hba->vops is non-NULL before reading hba->vops->name in both callbacks so hosts without variant operations use the generic ufshcd_suspend_prepare() and ufshcd_resume_complete() paths.

Fixes bb44826c3bdb ("scsi: ufs: ufs-pci: Fix S0ix/S3 for Intel controllers")
---
 drivers/ufs/host/ufshcd-pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ufs/host/ufshcd-pci.c +2 -2
index 668b57403e62..f9abbbc436f4 100644
@@ -644,7 +644,7 @@ static int ufshcd_pci_suspend_prepare(struct device *dev)
 {
 	struct ufs_hba *hba = dev_get_drvdata(dev);
 
-	if (!strcmp(hba->vops->name, "intel-pci"))
+	if (hba->vops && !strcmp(hba->vops->name, "intel-pci"))
 		return ufs_intel_suspend_prepare(dev);
 
 	return ufshcd_suspend_prepare(dev);
@@ -654,7 +654,7 @@ static void ufshcd_pci_resume_complete(struct device *dev)
 {
 	struct ufs_hba *hba = dev_get_drvdata(dev);
 
-	if (!strcmp(hba->vops->name, "intel-pci")) {
+	if (hba->vops && !strcmp(hba->vops->name, "intel-pci")) {
 		ufs_intel_resume_complete(dev);
 		return;
 	}
Signature · 1 line
2.56.0.506.g506a7eabc5-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Stanley Jhu

ufshcd_pci_tbl[] defines the Samsung 0xC00C and AMD 0x1B29 PCI IDs with .driver_data set to 0, so ufshcd_pci_probe() leaves hba->vops NULL. Both ufshcd_pci_suspend_prepare() and ufshcd_pci_resume_complete() dereference hba->vops->name without checking hba->vops:

1. System suspend on an AMD 0x1B29 or Samsung 0xC00C host enters the PM prepare phase and calls ufshcd_pci_suspend_prepare().
2. ufshcd_pci_suspend_prepare() evaluates strcmp(hba->vops->name, "intel-pci"), dereferences NULL, and triggers a kernel oops in the suspending task.

Quoted 7 lines

Check that hba->vops is non-NULL before reading hba->vops->name in both callbacks so hosts without variant operations use the generic ufshcd_suspend_prepare() and ufshcd_resume_complete() paths.

Fixes bb44826c3bdb ("scsi: ufs: ufs-pci: Fix S0ix/S3 for Intel controllers")
Quoted 26 lines
---
  drivers/ufs/host/ufshcd-pci.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ufs/host/ufshcd-pci.c +2 -2
index 668b57403e62..f9abbbc436f4 100644
@@ -644,7 +644,7 @@ static int ufshcd_pci_suspend_prepare(struct device *dev)
  {
  	struct ufs_hba *hba = dev_get_drvdata(dev);
 
-	if (!strcmp(hba->vops->name, "intel-pci"))
+	if (hba->vops && !strcmp(hba->vops->name, "intel-pci"))
  		return ufs_intel_suspend_prepare(dev);
 
  	return ufshcd_suspend_prepare(dev);
@@ -654,7 +654,7 @@ static void ufshcd_pci_resume_complete(struct device *dev)
  {
  	struct ufs_hba *hba = dev_get_drvdata(dev);
 
-	if (!strcmp(hba->vops->name, "intel-pci")) {
+	if (hba->vops && !strcmp(hba->vops->name, "intel-pci")) {
  		ufs_intel_resume_complete(dev);
  		return;
  	}
maintainer Applied
#2 lore raw
In reply to Stanley Jhu
Quoted 6 lines · Stanley Jhu

ufshcd_pci_tbl[] defines the Samsung 0xC00C and AMD 0x1B29 PCI IDs with .driver_data set to 0, so ufshcd_pci_probe() leaves hba->vops NULL. Both ufshcd_pci_suspend_prepare() and ufshcd_pci_resume_complete() dereference hba->vops->name without checking hba->vops:

Quoted 7 lines

1. System suspend on an AMD 0x1B29 or Samsung 0xC00C host enters the PM prepare phase and calls ufshcd_pci_suspend_prepare().
2. ufshcd_pci_suspend_prepare() evaluates strcmp(hba->vops->name, "intel-pci"), dereferences NULL, and triggers a kernel oops in the suspending task.

[...]

Applied to 7.4/scsi-fixes, thanks!

[1/1] scsi: ufs: ufs-pci: Check hba->vops in system PM callbacks

      https://git.kernel.org/mkp/scsi/c/947d8e9a4d1e
Signature · 1 line
Martin K. Petersen