Skip to contentSkip to conversation

ALSA: ymfpci: Handle return NULL error from ioremap_nocache

PATCH In review Arvind Yadav 2 participants 2 messages Jan 24, 2017 – Jan 25, 2017 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ALSA: ymfpci: Handle return NULL error from ioremap_nocache

Here, If ioremap_nocache will fail. It will return NULL. Kernel can run into a NULL-pointer dereference. This error check will avoid NULL pointer dereference.

---
 sound/pci/ymfpci/ymfpci_main.c | 4 ++++
 1 file changed, 4 insertions(+)
sound/pci/ymfpci/ymfpci_main.c +4 -0
index ffee284..8be1f07 100644
@@ -2392,6 +2392,10 @@ int snd_ymfpci_create(struct snd_card *card,
 	chip->rev = pci->revision;
 	chip->reg_area_phys = pci_resource_start(pci, 0);
 	chip->reg_area_virt = ioremap_nocache(chip->reg_area_phys, 0x8000);
+	if (!chip->reg_area_virt) {
+		snd_ymfpci_free(chip);
+		return -ENOMEM;
+	}
 	pci_set_master(pci);
 	chip->src441_used = -1;
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 15 lines · Arvind Yadav

Here, If ioremap_nocache will fail. It will return NULL. Kernel can run into a NULL-pointer dereference. This error check will avoid NULL pointer dereference.

---
 sound/pci/ymfpci/ymfpci_main.c | 4 ++++
 1 file changed, 4 insertions(+)
sound/pci/ymfpci/ymfpci_main.c +0 -0
index ffee284..8be1f07 100644

sound/pci/ymfpci/ymfpci_main.c int snd_ymfpci_create(struct snd_card *card, · line 2396

Quoted 5 lines
sound/pci/ymfpci/ymfpci_main.c +2 -0
@@ -2392,6 +2392,10 @@ int snd_ymfpci_create(struct snd_card *card,
 	chip->rev = pci->revision;
 	chip->reg_area_phys = pci_resource_start(pci, 0);
 	chip->reg_area_virt = ioremap_nocache(chip->reg_area_phys, 0x8000);
+	if (!chip->reg_area_virt) {
+		snd_ymfpci_free(chip);

The function calls iounmap() unconditionally, so it's not appropriate to call as is. You need to fix snd_ymfpci_free() as well to check NULL before iounmap(). Or, call here kfree() and pci_disable_device() explicitly instead of a full destructor.

thanks,

Takashi