asoc: tegra: fix Coverity issues
Deepak Nibade [Thu, 2 May 2013 09:01:58 +0000 (14:01 +0530)]
fix out-of-bounds access
Coverity id : 22954 22955 22956
fix negative array index read
Coverity id : 22957

Bug 1046331

Change-Id: I8266cc640d7f4d9ac783dce7ef3bcf9fd1e6abfd
Signed-off-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-on: http://git-master/r/224784
Reviewed-by: Vijay Mali <vmali@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Sachin Nikam <snikam@nvidia.com>

sound/soc/tegra/tegra30_dam.c

index 0b1c13f..d4206a9 100644 (file)
@@ -491,7 +491,7 @@ int tegra30_dam_allocate_channel(int ifc, int chid)
        struct tegra30_dam_context *dam = NULL;
 
        if ((ifc < 0) || (ifc >= TEGRA30_NR_DAM_IFC) ||
-               (chid < dam_ch_in0) || (chid >= dam_ch_maxnum))
+               (chid < dam_ch_in0) || (chid > dam_ch_in1))
                return -EINVAL;
 
        dam =  dams_cont_info[ifc];
@@ -509,7 +509,7 @@ int tegra30_dam_free_channel(int ifc, int chid)
        struct tegra30_dam_context *dam = NULL;
 
        if ((ifc < 0) || (ifc >= TEGRA30_NR_DAM_IFC) ||
-               (chid < dam_ch_in0) || (chid >= dam_ch_maxnum))
+               (chid < dam_ch_in0) || (chid > dam_ch_in1))
                return -EINVAL;
 
        dam =  dams_cont_info[ifc];
@@ -542,11 +542,13 @@ int tegra30_dam_free_controller(int ifc)
 
 void tegra30_dam_set_samplerate(int ifc, int chid, int samplerate)
 {
-       struct tegra30_dam_context *dam = dams_cont_info[ifc];
+       struct tegra30_dam_context *dam;
 
        if ((ifc < 0) || (ifc >= TEGRA30_NR_DAM_IFC))
                return;
 
+       dam = dams_cont_info[ifc];
+
        switch (chid) {
        case dam_ch_in0:
                tegra30_dam_set_input_samplerate(dam, samplerate);
@@ -935,7 +937,7 @@ void tegra30_dam_enable(int ifc, int on, int chid)
        struct tegra30_dam_context *dam;
 
        if ((ifc < 0) || (ifc >= TEGRA30_NR_DAM_IFC) ||
-           (chid < dam_ch_in0) || (chid >= dam_ch_maxnum))
+           (chid < dam_ch_in0) || (chid > dam_ch_in1))
                return;
 
        dam = dams_cont_info[ifc];