Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4545810imm; Sat, 21 Jul 2018 23:31:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfGRa4rAsgt9wlFaZ5vxeomDZ6fmzy8681bW/578jd8W0a8QiDkuG4D+g4jXmBlW1kY5OEp X-Received: by 2002:a62:fc4b:: with SMTP id e72-v6mr8486112pfh.168.1532241098333; Sat, 21 Jul 2018 23:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532241098; cv=none; d=google.com; s=arc-20160816; b=bPxjLvYxawF2FhrY5bCVSWpF1coc4DdyXudse8YsKe89KHnylrX3CP8jaYGX9YK8+C vjAtNPO4SbchQAp9lNuFrh3mwI5MZvynqp83LrnA777rULsGWvjsekxnBB5wTB5l1o6d BqIcrS5OFwTCMiUGKgLrnmwSLldvwIZxmcOL3fsE4SZIPWuWoYlmXRH5jpg6ij5gVC96 eJfLuOtrcH3K+drRXvNeB7VLDLOpa0YkVwMOFrWcx+D5h/5U/DX4sEGrSkfCvxLuvVZ8 FiKo/1OEYtOylwoYzXuspEfrFAS5odp2Aw4ZPXhqhwb/NQ5NCs7pDc5nn5ZqoasPLPRm F5Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=tjO2ZGfmhrlF8p4vY2+oHomp1SxVY8zKFXrfyrjJxpk=; b=NPqIDxsG8Euu9hwV0nd+hwW04+hnZ4VPDLObd8+AGMGK9ljUNiDig6fqq1SkeO//e1 oPe/gO6SPj09IM2iu8byL8damteJuPFsJiXcyesryER73YxY+XkcAMM+lvXz6txcPJL1 P8SJASPRwIi+Jq3KkilVVBUuE8hM+2bY00j/ZyAIUY3pzVeM2UwZKCRwdSLXkrASz9Gj xqg89Fs+FusPgoK5qwCb9b1RaxIbs3qGvQzS+5uBYGH81yJeGRsbcCpxAJNJXWrCQExw 5QbERZMk5dWQh3dg+DdYPuSICBAR3M9A4Xg7rNbLH8XHItQW3wwWvZNmPi2cJnnPXfjb tB7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2-v6si5973570pgs.142.2018.07.21.23.31.13; Sat, 21 Jul 2018 23:31:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727981AbeGVHZ2 convert rfc822-to-8bit (ORCPT + 99 others); Sun, 22 Jul 2018 03:25:28 -0400 Received: from mail.bootlin.com ([62.4.15.54]:57805 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727764AbeGVHZ1 (ORCPT ); Sun, 22 Jul 2018 03:25:27 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id B54D2207B4; Sun, 22 Jul 2018 08:29:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (unknown [37.173.105.99]) by mail.bootlin.com (Postfix) with ESMTPSA id 034B02072F; Sun, 22 Jul 2018 08:29:40 +0200 (CEST) Date: Sun, 22 Jul 2018 08:29:39 +0200 From: Boris Brezillon To: Randy Dunlap Cc: Anders Roxell , miquel.raynal@bootlin.com, linux-kernel@vger.kernel.org, Arnd Bergmann , Rob Herring , devicetree@vger.kernel.org Subject: Re: [PATCH] drivers/memory/Kconfig: Add CONFIG_OF dependency Message-ID: <20180722082939.2de739f1@bbrezillon> In-Reply-To: References: <20180721200049.7553-1-anders.roxell@linaro.org> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +Arnd, Rob and the DT ML. On Sat, 21 Jul 2018 14:53:47 -0700 Randy Dunlap wrote: > On 07/21/2018 01:00 PM, Anders Roxell wrote: > > JZ4780_NEMC doesn't depend on OF, and if OF isn't enabled we get this > > error: > > drivers/memory/jz4780-nemc.c: In function ‘jz4780_nemc_num_banks’: > > drivers/memory/jz4780-nemc.c:72:10: error: implicit declaration of > > function ‘of_read_number’; did you mean ‘down_read_nested’? > > [-Werror=implicit-function-declaration] > > bank = of_read_number(prop, 1); > > ^~~~~~~~~~~~~~ > > down_read_nested Looks like of.h defines stubs so that people can compile-test without CONFIG_OF selected. Maybe we should move of_read_number() and of_read_ulong() out of the #ifdef CONFIG_OF section. Alternatively, we could patch jz4780-nemc.c to not use of_read_number and instead rely on of_read_property_u32_index() + of_property_count_elems_of_size() + of_n_{addr,size}_cells(): --->8--- diff --git a/drivers/memory/jz4780-nemc.c b/drivers/memory/jz4780-nemc.c index bcf06adefc96..9ad7abc6983a 100644 --- a/drivers/memory/jz4780-nemc.c +++ b/drivers/memory/jz4780-nemc.c @@ -63,14 +63,21 @@ struct jz4780_nemc { */ unsigned int jz4780_nemc_num_banks(struct device *dev) { - const __be32 *prop; - unsigned int bank, count = 0; unsigned long referenced = 0; - int i = 0; - - while ((prop = of_get_address(dev->of_node, i++, NULL, NULL))) { - bank = of_read_number(prop, 1); - if (!(referenced & BIT(bank))) { + int nelems, elemsize, i = 0; + unsigned int count = 0; + + /* #address-cells = 2 and #size-cells = 1, hence */ + elemsize = of_n_addr_cells(dev->of_node) + + of_n_size_cells(dev->of_node); + nelems = of_property_count_elems_of_size(dev->of_node, "reg", elemsize); + for (i = 0; i < nelems; i++) { + u32 bank; + + if (!of_property_read_u32_index(dev->of_node, "reg", + i * elemsize, &bank) && + bank >= 1 && bank < JZ4780_NEMC_NUM_BANKS && + !(referenced & BIT(bank))) { referenced |= BIT(bank); count++; } @@ -269,10 +276,9 @@ static int jz4780_nemc_probe(struct platform_device *pdev) struct jz4780_nemc *nemc; struct resource *res; struct device_node *child; - const __be32 *prop; - unsigned int bank; unsigned long referenced; int i, ret; + u32 bank; nemc = devm_kzalloc(dev, sizeof(*nemc), GFP_KERNEL); if (!nemc) @@ -316,10 +322,27 @@ static int jz4780_nemc_probe(struct platform_device *pdev) * registered for it. */ for_each_child_of_node(nemc->dev->of_node, child) { + int nelems, elemsize; + referenced = 0; i = 0; - while ((prop = of_get_address(child, i++, NULL, NULL))) { - bank = of_read_number(prop, 1); + elemsize = of_n_addr_cells(dev->of_node) + + of_n_size_cells(dev->of_node); + nelems = of_property_count_elems_of_size(dev->of_node, "reg", + elemsize); + for (i = 0; i < nelems; i++) { + u32 bank; + + ret = of_property_read_u32_index(dev->of_node, "reg", + i * elemsize, &bank); + if (ret) { + dev_err(nemc->dev, + "failed to read bank %d of %pOF (err = %d)\n", + i, child, ret); + referenced = 0; + break; + } + if (bank < 1 || bank >= JZ4780_NEMC_NUM_BANKS) { dev_err(nemc->dev, "%pOF requests invalid bank %u\n",