From: Takashi Iwai Subject: Re: [PATCH] ALSA: hda/ca0132 - Avoid division by zero in dspxfr_one_seg() Date: Thu, 07 Mar 2013 09:18:20 +0100 Message-ID: References: <1362633231-21558-1-git-send-email-xi.wang@gmail.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 986492615EC for ; Thu, 7 Mar 2013 09:18:20 +0100 (CET) In-Reply-To: <1362633231-21558-1-git-send-email-xi.wang@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Xi Wang Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Thu, 7 Mar 2013 00:13:51 -0500, Xi Wang wrote: > > 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 Thanks, applied. Takashi > --- > sound/pci/hda/patch_ca0132.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c > index db02c1e..eefc456 100644 > --- a/sound/pci/hda/patch_ca0132.c > +++ b/sound/pci/hda/patch_ca0132.c > @@ -2298,6 +2298,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)); > @@ -2308,8 +2313,7 @@ static int dspxfr_one_seg(struct hda_codec *codec, > chip_addx, hda_frame_size_words, num_chans, > sample_rate_mul, sample_rate_div, buffer_size_words); > > - if ((buffer_addx == NULL) || (hda_frame_size_words == 0) || > - (buffer_size_words < hda_frame_size_words)) { > + if (buffer_size_words < hda_frame_size_words) { > snd_printdd(KERN_ERR "dspxfr_one_seg:failed\n"); > return -EINVAL; > } > -- > 1.7.10.4 >