From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: [Sound-open-firmware] [PATCH v5 09/14] ASoC: SOF: Add firmware loader support Date: Thu, 04 Apr 2019 16:05:34 +0200 Message-ID: References: <20190321161016.26515-1-pierre-louis.bossart@linux.intel.com> <20190321161016.26515-10-pierre-louis.bossart@linux.intel.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: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" To: Pierre-Louis Bossart Cc: alsa-devel@alsa-project.org, sound-open-firmware@alsa-project.org, Daniel Baluta , liam.r.girdwood@linux.intel.com, vkoul@kernel.org, broonie@kernel.org, andriy.shevchenko@linux.intel.com, Alan Cox List-Id: alsa-devel@alsa-project.org On Thu, 04 Apr 2019 15:59:46 +0200, Pierre-Louis Bossart wrote: > > >> +/* generic module parser for mmaped DSPs */ > >> +int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev, > >> + struct snd_sof_mod_hdr *module) > >> +{ > >> + struct snd_sof_blk_hdr *block; > >> + int count; > >> + u32 offset; > >> + size_t remaining; > >> + > >> + dev_dbg(sdev->dev, "new module size 0x%x blocks 0x%x type 0x%x\n", > >> + module->size, module->num_blocks, module->type); > >> + > >> + block = (struct snd_sof_blk_hdr *)((u8 *)module + sizeof(*module)); > >> + > >> + /* module->size doesn't include header size */ > >> + remaining = module->size; > >> + for (count = 0; count < module->num_blocks; count++) { > >> + /* minus header size of block */ > >> + remaining -= sizeof(*block); > >> + if (remaining < block->size) { > >> + dev_err(sdev->dev, "error: not enough data remaining\n"); > >> + return -EINVAL; > >> + } > > > > remaining is unsigned, so a negative check doesn't work here. > > Hence you need the explicit underflow check. > > yes, probably need ssize_t here. Be careful. If block->size is unsigned, the comparison is also done as unsigned in the code above. Takashi