ALSA: Compress - add codec parameter checks
authorVinod Koul <vinod.koul@linux.intel.com>
Mon, 17 Sep 2012 06:21:26 +0000 (11:51 +0530)
committerTakashi Iwai <tiwai@suse.de>
Mon, 17 Sep 2012 07:54:50 +0000 (09:54 +0200)
Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/compress_params.h
sound/core/compress_offload.c

index da4a456de032fb24dd75132f033f8c104b1b710a..602dc6c45d1a091fb548ac586c69813f25f4f508 100644 (file)
@@ -72,6 +72,7 @@
 #define SND_AUDIOCODEC_IEC61937              ((__u32) 0x0000000B)
 #define SND_AUDIOCODEC_G723_1                ((__u32) 0x0000000C)
 #define SND_AUDIOCODEC_G729                  ((__u32) 0x0000000D)
+#define SND_AUDIOCODEC_MAX                   SND_AUDIOCODEC_G729
 
 /*
  * Profile and modes are listed with bit masks. This allows for a
index bd7f28e8925404d03b9e9f83d16f20aa09269e8b..c40ae573346dd140031af773c532dd4f32f32240 100644 (file)
@@ -432,6 +432,16 @@ static int snd_compress_check_input(struct snd_compr_params *params)
                        params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
                return -EINVAL;
 
+       /* now codec parameters */
+       if (params->codec.id == 0 || params->codec.id > SND_AUDIOCODEC_MAX)
+               return -EINVAL;
+
+       if (params->codec.ch_in == 0 || params->codec.ch_out == 0)
+               return -EINVAL;
+
+       if (!(params->codec.sample_rate & SNDRV_PCM_RATE_8000_192000))
+               return -EINVAL;
+
        return 0;
 }