Skip to contentSkip to conversation

ALSA: lx6464es: add error handling for pci_ioremap_bar

PATCH Superseded Zhouyang Jia 2 participants 4 messages Jun 12, 2018 – Jun 14, 2018 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: lx6464es: add error handling for pci_ioremap_bar

When pci_ioremap_bar fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling pci_ioremap_bar.

---
 sound/pci/lx6464es/lx6464es.c | 4 ++++
 1 file changed, 4 insertions(+)
sound/pci/lx6464es/lx6464es.c +4 -0
index 9655b08..6157b6d 100644
@@ -1016,6 +1016,10 @@ static int snd_lx6464es_create(struct snd_card *card,
 
 	/* dsp port */
 	chip->port_dsp_bar = pci_ioremap_bar(pci, 2);
+	if (!chip->port_dsp_bar) {
+		dev_err(card->dev, "cannot remap PCI memory region\n");
+		goto request_irq_failed;
+	}
 
 	err = request_threaded_irq(pci->irq, lx_interrupt, lx_threaded_irq,
 				   IRQF_SHARED, KBUILD_MODNAME, chip);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 7 lines · Zhouyang Jia

When pci_ioremap_bar fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling pci_ioremap_bar.

This patch makes no sense, sorry. The whole lx6464es error handling there is buggy. We need to fix it more properly.

And, you must have noticed a bad smell in that change before submitting this. Basically, using the same goto label for the error handling of the next step is already fishy. In this case, you'd have to unmap at the error path after this point. If you can use the same label, it means that the unmap is missing -- already something wrong.

thanks,

Takashi

Quoted 23 lines
---
 sound/pci/lx6464es/lx6464es.c | 4 ++++
 1 file changed, 4 insertions(+)
sound/pci/lx6464es/lx6464es.c +4 -0
index 9655b08..6157b6d 100644
@@ -1016,6 +1016,10 @@ static int snd_lx6464es_create(struct snd_card *card,
 
 	/* dsp port */
 	chip->port_dsp_bar = pci_ioremap_bar(pci, 2);
+	if (!chip->port_dsp_bar) {
+		dev_err(card->dev, "cannot remap PCI memory region\n");
+		goto request_irq_failed;
+	}
 
 	err = request_threaded_irq(pci->irq, lx_interrupt, lx_threaded_irq,
 				   IRQF_SHARED, KBUILD_MODNAME, chip);
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 1/1 ALSA: lx6464es: add error handling for pci_ioremap_bar

In reply to Zhouyang Jia

When pci_ioremap_bar fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling pci_ioremap_bar.

---
v1->v2:
- Add new goto label.

---
 sound/pci/lx6464es/lx6464es.c | 7 +++++++
 1 file changed, 7 insertions(+)
sound/pci/lx6464es/lx6464es.c +7 -0
index 9655b08..6c85f13 100644
@@ -1016,6 +1016,10 @@ static int snd_lx6464es_create(struct snd_card *card,
 
 	/* dsp port */
 	chip->port_dsp_bar = pci_ioremap_bar(pci, 2);
+	if (!chip->port_dsp_bar) {
+		dev_err(card->dev, "cannot remap PCI memory region\n");
+		goto remap_pci_failed;
+	}
 
 	err = request_threaded_irq(pci->irq, lx_interrupt, lx_threaded_irq,
 				   IRQF_SHARED, KBUILD_MODNAME, chip);
@@ -1055,6 +1059,9 @@ static int snd_lx6464es_create(struct snd_card *card,
 	free_irq(pci->irq, chip);
 
 request_irq_failed:
+	iounmap(chip->port_dsp_bar);
+
+remap_pci_failed:
 	pci_release_regions(pci);
 
 request_regions_failed:
Signature · 1 line
2.7.4
Applied
#3 lore raw
Quoted 10 lines · Zhouyang Jia

When pci_ioremap_bar fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling pci_ioremap_bar.

---
v1->v2:
- Add new goto label.

Applied, thanks.

Takashi