UPSTREAM: ALSA: hda/ca0132 - Avoid division by zero in dspxfr_one_seg()
authorXi Wang <xi.wang@gmail.com>
Thu, 7 Mar 2013 05:13:51 +0000 (00:13 -0500)
committerChromeBot <chrome-bot@google.com>
Fri, 8 Mar 2013 17:39:55 +0000 (09:39 -0800)
Move the zero check `hda_frame_size_words == 0' before the modulus
`buffer_size_words % hda_frame_size_words'.

Also remove the redundant null check `buffer_addx == NULL'.

Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Conflicts:
sound/pci/hda/patch_ca0132.c

BUG=chromium-os:39661
TEST=play audio on link.

Change-Id: I926b440ba3a5d2a7ccbba63b60a7d5f116b93766
Reviewed-on: https://gerrit.chromium.org/gerrit/44902
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
sound/pci/hda/patch_ca0132.c

index 1769256..5b2377e 100644 (file)
@@ -2231,6 +2231,11 @@ static int dspxfr_one_seg(struct hda_codec *codec,
        hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
                        (num_chans * sample_rate_mul / sample_rate_div));
 
+       if (hda_frame_size_words == 0) {
+               snd_printdd(KERN_ERR "frmsz zero\n");
+               return -EINVAL;
+       }
+
        buffer_size_words = min(buffer_size_words,
                                (unsigned int)(UC_RANGE(chip_addx, 1) ?
                                65536 : 32768));
@@ -2244,10 +2249,8 @@ static int dspxfr_one_seg(struct hda_codec *codec,
        CTASSERT(SUCCEEDED(status));
        CTASSERT(buffer_addx != NULL);
        CTASSERT(buffer_size_words >= hda_frame_size_words);
-       CTASSERT(hda_frame_size_words > 0);
 
-       if ((buffer_addx == NULL) || (hda_frame_size_words == 0) ||
-           (buffer_size_words < hda_frame_size_words)) {
+       if (buffer_addx == NULL || buffer_size_words < hda_frame_size_words) {
                status = FAIL_MSG(-1, "dspxfr_one_seg:failed");
        }