Commit f37ace9a authored by Tom Rix's avatar Tom Rix Committed by Greg Kroah-Hartman

ALSA: asihpi: fix iounmap in error handler

[ Upstream commit 472eb391 ]

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: 719f82d3 ("ALSA: Add support of AudioScience ASI boards")
Signed-off-by: default avatarTom Rix <trix@redhat.com>
Link: https://lore.kernel.org/r/20200913165230.17166-1-trix@redhat.comSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent e1a75e94
...@@ -350,7 +350,7 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev, ...@@ -350,7 +350,7 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
struct hpi_message hm; struct hpi_message hm;
struct hpi_response hr; struct hpi_response hr;
struct hpi_adapter adapter; struct hpi_adapter adapter;
struct hpi_pci pci; struct hpi_pci pci = { 0 };
memset(&adapter, 0, sizeof(adapter)); memset(&adapter, 0, sizeof(adapter));
...@@ -506,7 +506,7 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev, ...@@ -506,7 +506,7 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
return 0; return 0;
err: err:
for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; idx++) { while (--idx >= 0) {
if (pci.ap_mem_base[idx]) { if (pci.ap_mem_base[idx]) {
iounmap(pci.ap_mem_base[idx]); iounmap(pci.ap_mem_base[idx]);
pci.ap_mem_base[idx] = NULL; pci.ap_mem_base[idx] = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment