]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm_file: coverity fixes (including double locking)
authorJaroslav Kysela <perex@perex.cz>
Mon, 27 May 2019 11:57:12 +0000 (13:57 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 27 May 2019 12:04:52 +0000 (14:04 +0200)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/pcm/pcm_file.c

index 99db3754fa320f6dc710bd1c3fa2a5f3890a41f8..54142a3d16efb07bf7d22b9c627e71f8f3f419ee 100644 (file)
@@ -296,7 +296,10 @@ static int snd_pcm_file_areas_read_infile(snd_pcm_t *pcm,
                return -ENOMEM;
        }
 
-       bytes = read(file->ifd, file->rbuf, snd_pcm_frames_to_bytes(pcm, frames));
+       bytes = snd_pcm_frames_to_bytes(pcm, frames);
+       if (bytes < 0)
+               return bytes;
+       bytes = read(file->ifd, file->rbuf, bytes);
        if (bytes < 0) {
                SYSERR("read from file failed, error: %d", bytes);
                return bytes;
@@ -589,18 +592,14 @@ static snd_pcm_sframes_t snd_pcm_file_readi(snd_pcm_t *pcm, void *buffer, snd_pc
        snd_pcm_channel_area_t areas[pcm->channels];
        snd_pcm_sframes_t frames;
 
-       __snd_pcm_lock(pcm);
-
        frames = _snd_pcm_readi(file->gen.slave, buffer, size);
-       if (frames <= 0) {
-               __snd_pcm_unlock(pcm);
+       if (frames <= 0)
                return frames;
-       }
 
        snd_pcm_areas_from_buf(pcm, areas, buffer);
        snd_pcm_file_areas_read_infile(pcm, areas, 0, frames);
+       __snd_pcm_lock(pcm);
        snd_pcm_file_add_frames(pcm, areas, 0, frames);
-
        __snd_pcm_unlock(pcm);
 
        return frames;
@@ -654,9 +653,6 @@ static int snd_pcm_file_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t
        snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
 {
        snd_pcm_file_t *file = pcm->private_data;
-       snd_pcm_channel_area_t areas_if[pcm->channels];
-       snd_pcm_uframes_t frames_if;
-       void *buffer = NULL;
        int result;
 
        result = snd_pcm_mmap_begin(file->gen.slave, areas, offset, frames);