lkml.org 
[lkml]   [2017]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] mtd: spi-nor: Check for spi_nor_hwcaps_read2cmd() return value
On Sun, 17 Sep 2017 11:57:50 +0200
Richard Weinberger <richard@nod.at> 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 <richard@nod.at>
> ---
> 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 = &params->reads[cmd];
> half = bfpt.dwords[rd->settings_dword] >> rd->settings_shift;
> spi_nor_set_read_settings_from_bfpt(read, half, rd->proto);

\
 
 \ /
  Last update: 2017-09-18 11:40    [W:0.131 / U:0.640 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site