Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: aloop: Avoid pointer dereference before null-check

Static analysis tools (cppcheck and PVS Studio) report an error
in loopback_snd_timer_period_elapsed() regarding dpcm_play pointer
dereference earlier than its null-check. And although this is a result
of a formal check, and the pointer correctness is also protected
by having a corresponding bit set in the "running" mask, re-ordering
of the lines can imake the code even formally correct and eliminate
those static analysis error reports.

Fixes: 26c53379f98d ("ALSA: aloop: Support selection of snd_timer instead of jiffies")
Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
Link: https://lore.kernel.org/r/20191127110622.26105-1-andrew_gabbasov@mentor.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Andrew Gabbasov and committed by
Takashi Iwai
5061bb70 8218df93

+4 -4
+4 -4
sound/drivers/aloop.c
··· 727 727 728 728 dpcm_play = cable->streams[SNDRV_PCM_STREAM_PLAYBACK]; 729 729 dpcm_capt = cable->streams[SNDRV_PCM_STREAM_CAPTURE]; 730 - substream_play = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? 731 - dpcm_play->substream : NULL; 732 - substream_capt = (running & (1 << SNDRV_PCM_STREAM_CAPTURE)) ? 733 - dpcm_capt->substream : NULL; 734 730 735 731 if (event == SNDRV_TIMER_EVENT_MSTOP) { 736 732 if (!dpcm_play || ··· 737 741 } 738 742 } 739 743 744 + substream_play = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? 745 + dpcm_play->substream : NULL; 746 + substream_capt = (running & (1 << SNDRV_PCM_STREAM_CAPTURE)) ? 747 + dpcm_capt->substream : NULL; 740 748 valid_runtime = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? 741 749 dpcm_play->substream->runtime : 742 750 dpcm_capt->substream->runtime;