Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932291AbdIRJj6 (ORCPT ); Mon, 18 Sep 2017 05:39:58 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:59179 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755334AbdIRJj4 (ORCPT ); Mon, 18 Sep 2017 05:39:56 -0400 Date: Mon, 18 Sep 2017 11:39:45 +0200 From: Boris Brezillon To: Richard Weinberger Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, marek.vasut@gmail.com, cyrille.pitchen@wedev4u.fr, computersforpeace@gmail.com, dwmw2@infradead.org Subject: Re: [PATCH] mtd: spi-nor: Check for spi_nor_hwcaps_read2cmd() return value Message-ID: <20170918113945.1549571f@bbrezillon> In-Reply-To: <20170917095750.14059-1-richard@nod.at> References: <20170917095750.14059-1-richard@nod.at> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1152 Lines: 34 On Sun, 17 Sep 2017 11:57:50 +0200 Richard Weinberger wrote: > The function can return a negativ value in case of errors, > don't use it blindly as array index. > > Detected by CoverityScan CID#1418067 ("Memory - illegal accesses") > Fixes: f384b352cbf0 ("mtd: spi-nor: parse Serial Flash Discoverable > Parameters (SFDP) tables") Hm, not sure but I think "Fixes:" should not be wrapped. > Signed-off-by: Richard Weinberger > --- > drivers/mtd/spi-nor/spi-nor.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c > index cf1d4a15e10a..d71765739a93 100644 > --- a/drivers/mtd/spi-nor/spi-nor.c > +++ b/drivers/mtd/spi-nor/spi-nor.c > @@ -2145,6 +2145,9 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, > > params->hwcaps.mask |= rd->hwcaps; > cmd = spi_nor_hwcaps_read2cmd(rd->hwcaps); > + if (cmd < 0) > + return -EINVAL; Why not returning cmd directly? > + > read = ¶ms->reads[cmd]; > half = bfpt.dwords[rd->settings_dword] >> rd->settings_shift; > spi_nor_set_read_settings_from_bfpt(read, half, rd->proto);