Skip to contentSkip to conversation

ALSA: asihpi: fix iounmap in error handler

PATCH Applied [email protected] 2 participants 2 messages Sep 13, 2020 – Sep 21, 2020 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: asihpi: fix iounmap in error handler

From: Tom Rix <[email protected]>

clang static analysis flags this problem hpioctl.c:513:7: warning: Branch condition evaluates to
a garbage value

                if (pci.ap_mem_base[idx]) {
                    ^~~~~~~~~~~~~~~~~~~~

If there is a failure in the middle of the memory space loop, only some of the memory spaces need to be cleaned up.

At the error handler, idx holds the number of successful memory spaces mapped. So rework the handler loop to use the old idx.

There is a second problem, the memory space loop conditionally iomaps()/sets the mem_base so it is necessay to initize pci.

Fixes 719f82d3987a ("ALSA: Add support of AudioScience ASI boards")
---
 sound/pci/asihpi/hpioctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/pci/asihpi/hpioctl.c +2 -2
index 6cc2b6964bb5..bb31b7fe867d 100644
@@ -352,7 +352,7 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
 	struct hpi_message hm;
 	struct hpi_response hr;
 	struct hpi_adapter adapter;
-	struct hpi_pci pci;
+	struct hpi_pci pci = { 0 };
 
 	memset(&adapter, 0, sizeof(adapter));
 
@@ -509,7 +509,7 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
 	return 0;
 
 err:
-	for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; idx++) {
+	while (--idx >= 0) {
 		if (pci.ap_mem_base[idx]) {
 			iounmap(pci.ap_mem_base[idx]);
 			pci.ap_mem_base[idx] = NULL;
Signature · 1 line
2.18.1
Applied
#1 lore raw
Quoted 16 lines · On Sun, 13 Sep 2020 18:52:30 +0200, [email protected] wrote:

From: Tom Rix <[email protected]>

clang static analysis flags this problem hpioctl.c:513:7: warning: Branch condition evaluates to
a garbage value

                if (pci.ap_mem_base[idx]) {
                    ^~~~~~~~~~~~~~~~~~~~

If there is a failure in the middle of the memory space loop, only some of the memory spaces need to be cleaned up.

At the error handler, idx holds the number of successful memory spaces mapped. So rework the handler loop to use the old idx.

Quoted 5 lines

There is a second problem, the memory space loop conditionally iomaps()/sets the mem_base so it is necessay to initize pci.

Fixes 719f82d3987a ("ALSA: Add support of AudioScience ASI boards")

Thanks, applied.

Takashi