]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: asihpi: Simplify error handling in PCM substream setup
authorJihed Chaibi <jihed.chaibi.dev@gmail.com>
Sun, 14 Sep 2025 20:59:45 +0000 (22:59 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 15 Sep 2025 07:25:47 +0000 (09:25 +0200)
Refactor error handling in the PCM substream setup to combine redundant
checks and improve code readability. Free the dpcm structure and return
appropriate error codes (-EBUSY for HPI_ERROR_OBJ_ALREADY_OPEN, -EIO
for other errors) in a single block.

Signed-off-by: Jihed Chaibi <jihed.chaibi.dev@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/asihpi/asihpi.c

index 8419f2b6e5891e875d70bbe837deb45f81447fb9..fd0a67b772d1f05552ab2ee197d159db24e060da 100644 (file)
@@ -982,12 +982,12 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
        err = hpi_outstream_open(card->hpi->adapter->index,
                              substream->number, &dpcm->h_stream);
        hpi_handle_error(err);
-       if (err)
+       if (err) {
                kfree(dpcm);
-       if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
-               return -EBUSY;
-       if (err)
+               if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
+                       return -EBUSY;
                return -EIO;
+       }
 
        /*? also check ASI5000 samplerate source
            If external, only support external rate.
@@ -1156,12 +1156,12 @@ static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
        err = hpi_handle_error(
            hpi_instream_open(card->hpi->adapter->index,
                             substream->number, &dpcm->h_stream));
-       if (err)
+       if (err) {
                kfree(dpcm);
-       if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
-               return -EBUSY;
-       if (err)
+               if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
+                       return -EBUSY;
                return -EIO;
+       }
 
        timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
        dpcm->substream = substream;