From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFCC8C432BE for ; Tue, 27 Jul 2021 16:13:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BABC961B73 for ; Tue, 27 Jul 2021 16:13:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229936AbhG0QNm (ORCPT ); Tue, 27 Jul 2021 12:13:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229851AbhG0QNh (ORCPT ); Tue, 27 Jul 2021 12:13:37 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D89DC061757 for ; Tue, 27 Jul 2021 09:13:36 -0700 (PDT) Received: from martin by viti.kaiser.cx with local (Exim 4.89) (envelope-from ) id 1m8Phv-0007rV-0H; Tue, 27 Jul 2021 18:13:27 +0200 Date: Tue, 27 Jul 2021 18:13:26 +0200 From: Martin Kaiser To: Manivannan Sadhasivam Cc: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, boris.brezillon@collabora.com, tudor.ambarus@microchip.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, dan.carpenter@oracle.com Subject: Re: [PATCH] mtd: rawnand: Fix probe failure due to of_get_nand_secure_regions() Message-ID: <20210727161326.wozj23a3sblibwpk@viti.kaiser.cx> References: <20210727062813.32619-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210727062813.32619-1-manivannan.sadhasivam@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: Martin Kaiser Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mani and all, Thus wrote Manivannan Sadhasivam (manivannan.sadhasivam@linaro.org): > Due to 14f97f0b8e2b, the rawnand platforms without "secure-regions" > property defined in DT fails to probe. The issue is, > of_get_nand_secure_regions() errors out if > of_property_count_elems_of_size() returns a negative error code. > If the "secure-regions" property is not present in DT, then also we'll > get -EINVAL from of_property_count_elems_of_size() but it should not > be treated as an error for platforms not declaring "secure-regions" > in DT. > So fix this behaviour by checking for the existence of that property in > DT and return 0 if it is not present. > Fixes: 14f97f0b8e2b ("mtd: rawnand: Add a check in of_get_nand_secure_regions()") > Reported-by: Martin Kaiser > Signed-off-by: Manivannan Sadhasivam > --- > drivers/mtd/nand/raw/nand_base.c | 6 ++++++ > 1 file changed, 6 insertions(+) > diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c > index cbba46432e39..3d6c6e880520 100644 > --- a/drivers/mtd/nand/raw/nand_base.c > +++ b/drivers/mtd/nand/raw/nand_base.c > @@ -5228,8 +5228,14 @@ static bool of_get_nand_on_flash_bbt(struct device_node *np) > static int of_get_nand_secure_regions(struct nand_chip *chip) > { > struct device_node *dn = nand_get_flash_node(chip); > + struct property *prop; > int nr_elem, i, j; > + /* Only proceed if the "secure-regions" property is present in DT */ > + prop = of_find_property(dn, "secure-regions", NULL); > + if (!prop) > + return 0; > + > nr_elem = of_property_count_elems_of_size(dn, "secure-regions", sizeof(u64)); > if (nr_elem <= 0) > return nr_elem; > -- > 2.25.1 not surprisingly, this fixes the issue for me. Reviewed-by: Martin Kaiser Tested-by: Martin Kaiser Still, I was wondering if the behaviour of of_property_count_elems_of_size makes sense. Without a prior check, there's no chance for the caller to distinguish between "property is absent" and "property is malformed". Thanks, Martin