From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752830AbcDZSxs (ORCPT ); Tue, 26 Apr 2016 14:53:48 -0400 Received: from down.free-electrons.com ([37.187.137.238]:55135 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752753AbcDZSxr convert rfc822-to-8bit (ORCPT ); Tue, 26 Apr 2016 14:53:47 -0400 Date: Tue, 26 Apr 2016 20:53:44 +0200 From: Boris Brezillon To: =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= Cc: linux-mtd@lists.infradead.org, Richard Weinberger , David Woodhouse , Brian Norris , linux-kernel@vger.kernel.org (open list) Subject: Re: [PATCH] mtd: nand: fix NULL pointer dereference in of_get_nand_ecc_algo Message-ID: <20160426205344.17ab81cb@bbrezillon> In-Reply-To: <1461695776-29740-1-git-send-email-zajec5@gmail.com> References: <1461695776-29740-1-git-send-email-zajec5@gmail.com> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 Apr 2016 20:36:16 +0200 Rafał Miłecki wrote: > Our array nand_ecc_algos doesn't specify mappings for all available > enum nand_ecc_algo values. The one missing there is NAND_ECC_UNKNOWN > as this value is reserved for algorithm not being specified at all. > It means we have to be careful when iterating this array and handle > NULL values. > > Signed-off-by: Rafał Miłecki > --- > Hi Boris, > > Sorry for this crash in nand subsystem :( If you think it's OK you may > pick this patch as a fixup for > c6e002a7ca9f ("mtd: nand: add support for "nand-ecc-algo" DT property") > --- > drivers/mtd/nand/nand_base.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c > index a5417a0..0eaa9dc 100644 > --- a/drivers/mtd/nand/nand_base.c > +++ b/drivers/mtd/nand/nand_base.c > @@ -4016,6 +4016,8 @@ static int of_get_nand_ecc_algo(struct device_node *np) > err = of_property_read_string(np, "nand-ecc-algo", &pm); > if (!err) { > for (i = 0; i < ARRAY_SIZE(nand_ecc_algos); i++) > + if (!nand_ecc_algos[i]) > + continue; Can we add an "unknown" entry, or start iterating at NAND_ECC_HAMMING or NAND_ECC_UNKNOWN + 1 instead of adding this extra test? BTW, since the original commit has been applied recently I'll squash the changes into the previous commit and rebase my branch instead of adding a new patch (I hate breaking bisectability). -- Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com