Skip to content

Commit

Permalink
ALSA: asihpi: fix iounmap in error handler
Browse files Browse the repository at this point in the history
[ Upstream commit 472eb39 ]

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: 719f82d ("ALSA: Add support of AudioScience ASI boards")
Signed-off-by: Tom Rix <trix@redhat.com>
Link: https://lore.kernel.org/r/20200913165230.17166-1-trix@redhat.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Tom Rix authored and Greg Kroah-Hartman committed Oct 1, 2020
1 parent f78c0c1 commit 35c3ed7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sound/pci/asihpi/hpioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,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));

Expand Down Expand Up @@ -502,7 +502,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;
Expand Down

0 comments on commit 35c3ed7

Please sign in to comment.