Message ID | 20231005155907.2701706-3-miquel.raynal@bootlin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp413245vqb; Thu, 5 Oct 2023 09:21:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHH0aRHikMdi6F74m4eHI/vHJixEoTXIhSxpkovlwXqHnVTqwZtVzaqK0b8vP7I7eSiP8Wc X-Received: by 2002:a05:6a00:1790:b0:68f:c057:b567 with SMTP id s16-20020a056a00179000b0068fc057b567mr6490827pfg.26.1696522859923; Thu, 05 Oct 2023 09:20:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696522859; cv=none; d=google.com; s=arc-20160816; b=mZ19h8LCChzEI49fQAfXF7LWfOCGh9FTeAW7yXCUXkUA/BF1MQ71XWFDeC/7dxj0qR d/Wsiu48OmAKd8IPLF7+3M7CTvflTAIQTKHxa0UfAZnV/E5DHIJPsqVlGNu6sOL4Pqgk c94iyiPf3AvhxJwUJ03MRM1noBIt5IhLou+jIFWWi5odHeIPNgP6okWUn+QRcZRoRhpF zdlK9QdevIAmMe8t1gzN9qxhqEwnMLFFCgTLWGGSZT7UonYvDCNz12OmNscyUScyphFM X58bGTtiRdiQCDqSu1Bz8Z9C4b1d8htMjX46ruRh4ZgmgpEgdRKueS0xuWm3TxCHgptv iIQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ozTgRpH7t0hBveOF8yXGnBl2vT15HtovIkhQFtR9B74=; fh=XQzgxiPMj/Cqsom9sWl23DkvcXkGD6r/vx0NuuBn5R0=; b=RNTdnfVQ4H7LtA9NOJwZVY/ap3UKde8fYrt3+jXaqS+poLVXHPwx1Loi4xZzF04RYW WqCCGxlRh3vgjG7pPp7X0EAIfp3RPGyCdlVxLviadBxfrHs22FgBbOV03dTUNBY1yazf vP/7yBmloOcI1SD5gPa07vGTu2jvRm4V6PLMabUC0U7eIvbOKGKncd2YwKRtjfkdsJM9 /XKi5oCdbiayGLAFuTZy12498fbc8f/1FFYUjBwpLCP6bzkmkf5boCqzli/9R1R3cO66 ANwfu9dNZ1ckBC5yMCehi2rjhrbwTgJ+d9oEAtZnuirHaKNHfmkttYpqgD7zsvhc6Ysl vAPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Ck3ZN1IJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id cq8-20020a056a00330800b00690bf904bb6si1646837pfb.307.2023.10.05.09.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:20:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Ck3ZN1IJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 570DB80A9AA9; Thu, 5 Oct 2023 09:20:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242678AbjJEQSp (ORCPT <rfc822;ezelljr.billy@gmail.com> + 19 others); Thu, 5 Oct 2023 12:18:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242025AbjJEQPD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 5 Oct 2023 12:15:03 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99AEE7285; Thu, 5 Oct 2023 08:59:16 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 838311BF213; Thu, 5 Oct 2023 15:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696521554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ozTgRpH7t0hBveOF8yXGnBl2vT15HtovIkhQFtR9B74=; b=Ck3ZN1IJji2OY+dMnjA+DdC2x6VAfE4ZZp7r6kuL50L/U58uuF4Frsm3crOYTr2Xr6QRD0 +2km3T173WAQtA58ghw76qM5qNQ+nteaRCDHz1tugcKisNuWXIpTq8+UDJ1G8xw6o/VNT6 CzzExtKtwXEV5OrA0fYuK9Hjz/MY2F9mGltJW1omwlUgWWk3MUpjiZdlF3IOY4yGTFdMik 9M1Yp7SfHZwOfk4rh9oJaJdvXJUj6rEg6HvBo6kKScUGUobTXOrdG3JH3y3h2LsBM5yL0Z 4+V8yieOVFLwOKkYmxKjHHkXDeL7yw0rt57oMPF6CufiaU2NdAxEhjAINHjiKQ== From: Miquel Raynal <miquel.raynal@bootlin.com> To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Michael Walle <michael@walle.cc>, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= <rafal@milecki.pl>, Rob Herring <robh+dt@kernel.org>, Frank Rowand <frowand.list@gmail.com>, devicetree@vger.kernel.org, <linux-kernel@vger.kernel.org>, Robert Marko <robert.marko@sartura.hr>, Thomas Petazzoni <thomas.petazzoni@bootlin.com>, Luka Perkov <luka.perkov@sartura.hr>, Randy Dunlap <rdunlap@infradead.org>, Chen-Yu Tsai <wenst@chromium.org>, Daniel Golle <daniel@makrotopia.org>, Miquel Raynal <miquel.raynal@bootlin.com> Subject: [PATCH v12 2/7] nvmem: Clarify the situation when there is no DT node available Date: Thu, 5 Oct 2023 17:59:02 +0200 Message-Id: <20231005155907.2701706-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005155907.2701706-1-miquel.raynal@bootlin.com> References: <20231005155907.2701706-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 05 Oct 2023 09:20:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778933153970393477 X-GMAIL-MSGID: 1778933153970393477 |
Series |
NVMEM cells in sysfs
|
|
Commit Message
Miquel Raynal
Oct. 5, 2023, 3:59 p.m. UTC
At a first look it might seem that the presence of the of_node pointer
in the nvmem device does not matter much, but in practice, after looking
deep into the DT core, nvmem_add_cells_from_dt() will simply and always
return NULL if this field is not provided. As most mtd devices don't
populate this field (this could evolve later), it means none of their
children cells will be populated unless no_of_node is explicitly set to
false. In order to clarify the logic, let's add clear check at the
beginning of this helper.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/nvmem/core.c | 3 +++
1 file changed, 3 insertions(+)
Comments
On 2023-10-05 17:59, Miquel Raynal wrote: > At a first look it might seem that the presence of the of_node pointer > in the nvmem device does not matter much, but in practice, after > looking > deep into the DT core, nvmem_add_cells_from_dt() will simply and always > return NULL if this field is not provided. As most mtd devices don't > populate this field (this could evolve later), it means none of their > children cells will be populated unless no_of_node is explicitly set to > false. In order to clarify the logic, let's add clear check at the > beginning of this helper. I'm somehow confused by above explanation and code too. I read it carefully 5 times but I can't see what exactly this change helps with. At first look at nvmem_add_cells_from_legacy_of() I can see it uses "of_node" so I don't really agree with "it might seem that the presence of the of_node pointer in the nvmem device does not matter much". You really don't need to look deep into DT core (actually you don't have to look into it at all) to understand that nvmem_add_cells_from_dt() will return 0 (nitpicking: not NULL) for a NULL pointer. It's all made of for_each_child_of_node(). Obviously it does nothing if there is nothing to loop over. Given that for_each_child_of_node() is NULL-safe I think code from this patch is redundant. Later you mention "no_of_node" which I agree to be a very non-intuitive config option. As pointed in another thread I already sent: [PATCH] Revert "nvmem: add new config option" https://lore.kernel.org/lkml/ba3c419a-6511-480a-b5f2-6c418f9c02e7@gmail.com/t/ Maybe with above patch finally things will get more clear and we don't need this PATCH after all? > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> > --- > drivers/nvmem/core.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > index eaf6a3fe8ca6..286efd3f5a31 100644 > --- a/drivers/nvmem/core.c > +++ b/drivers/nvmem/core.c > @@ -743,6 +743,9 @@ static int nvmem_add_cells_from_dt(struct > nvmem_device *nvmem, struct device_nod > > static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem) > { > + if (!nvmem->dev.of_node) > + return 0; > + > return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node); > }
Hi Rafał, rafal@milecki.pl wrote on Fri, 06 Oct 2023 13:41:52 +0200: > On 2023-10-05 17:59, Miquel Raynal wrote: > > At a first look it might seem that the presence of the of_node pointer > > in the nvmem device does not matter much, but in practice, after > looking > > deep into the DT core, nvmem_add_cells_from_dt() will simply and always > > return NULL if this field is not provided. As most mtd devices don't > > populate this field (this could evolve later), it means none of their > > children cells will be populated unless no_of_node is explicitly set to > > false. In order to clarify the logic, let's add clear check at the > > beginning of this helper. > > I'm somehow confused by above explanation and code too. I read it > carefully 5 times but I can't see what exactly this change helps with. > > At first look at nvmem_add_cells_from_legacy_of() I can see it uses > "of_node" so I don't really agree with "it might seem that the presence > of the of_node pointer in the nvmem device does not matter much". > > You really don't need to look deep into DT core (actually you don't have > to look into it at all) to understand that nvmem_add_cells_from_dt() > will return 0 (nitpicking: not NULL) for a NULL pointer. It's all made > of for_each_child_of_node(). Obviously it does nothing if there is > nothing to loop over. That was not obvious to me as I thought it would start from /, which I think some other function do when you don't provide a start node. > Given that for_each_child_of_node() is NULL-safe I think code from this > patch is redundant. I didn't say it was not safe, just not explicit. > Later you mention "no_of_node" which I agree to be a very non-intuitive > config option. As pointed in another thread I already sent: > [PATCH] Revert "nvmem: add new config option" > https://lore.kernel.org/lkml/ba3c419a-6511-480a-b5f2-6c418f9c02e7@gmail.com/t/ I actually wanted to find again that patch and could not get my hands on it, but it is probably a much better fix than my other mtd patch, I agree with you. > Maybe with above patch finally things will get more clear and we don't > need this PATCH after all? Yes. Srinivas, what are your plans for the above patch? Thanks, Miquèl
One comment below On 2023-10-06 18:32, Miquel Raynal wrote: > rafal@milecki.pl wrote on Fri, 06 Oct 2023 13:41:52 +0200: > >> On 2023-10-05 17:59, Miquel Raynal wrote: >> > At a first look it might seem that the presence of the of_node pointer >> > in the nvmem device does not matter much, but in practice, after > looking >> > deep into the DT core, nvmem_add_cells_from_dt() will simply and always >> > return NULL if this field is not provided. As most mtd devices don't >> > populate this field (this could evolve later), it means none of their >> > children cells will be populated unless no_of_node is explicitly set to >> > false. In order to clarify the logic, let's add clear check at the >> > beginning of this helper. >> >> I'm somehow confused by above explanation and code too. I read it >> carefully 5 times but I can't see what exactly this change helps with. >> >> At first look at nvmem_add_cells_from_legacy_of() I can see it uses >> "of_node" so I don't really agree with "it might seem that the >> presence >> of the of_node pointer in the nvmem device does not matter much". >> >> You really don't need to look deep into DT core (actually you don't >> have >> to look into it at all) to understand that nvmem_add_cells_from_dt() >> will return 0 (nitpicking: not NULL) for a NULL pointer. It's all made >> of for_each_child_of_node(). Obviously it does nothing if there is >> nothing to loop over. > > That was not obvious to me as I thought it would start from /, which I > think some other function do when you don't provide a start node. What about documenting that function instead of adding redundant code? >> Given that for_each_child_of_node() is NULL-safe I think code from >> this >> patch is redundant. > > I didn't say it was not safe, just not explicit.
Hi Rafał, rafal@milecki.pl wrote on Sat, 07 Oct 2023 18:09:06 +0200: > One comment below > > On 2023-10-06 18:32, Miquel Raynal wrote: > > rafal@milecki.pl wrote on Fri, 06 Oct 2023 13:41:52 +0200: > > > >> On 2023-10-05 17:59, Miquel Raynal wrote: > >> > At a first look it might seem that the presence of the of_node pointer > >> > in the nvmem device does not matter much, but in practice, after > looking > >> > deep into the DT core, nvmem_add_cells_from_dt() will simply and always > >> > return NULL if this field is not provided. As most mtd devices don't > >> > populate this field (this could evolve later), it means none of their > >> > children cells will be populated unless no_of_node is explicitly set to > >> > false. In order to clarify the logic, let's add clear check at the > >> > beginning of this helper. > >> >> I'm somehow confused by above explanation and code too. I read it > >> carefully 5 times but I can't see what exactly this change helps with. > >> >> At first look at nvmem_add_cells_from_legacy_of() I can see it uses > >> "of_node" so I don't really agree with "it might seem that the >> presence > >> of the of_node pointer in the nvmem device does not matter much". > >> >> You really don't need to look deep into DT core (actually you don't >> have > >> to look into it at all) to understand that nvmem_add_cells_from_dt() > >> will return 0 (nitpicking: not NULL) for a NULL pointer. It's all made > >> of for_each_child_of_node(). Obviously it does nothing if there is > >> nothing to loop over. > > > > That was not obvious to me as I thought it would start from /, which I > > think some other function do when you don't provide a start node. > > What about documenting that function instead of adding redundant code? Yeah would work as well. But I will just get rid of this, with your other patch that solves the fact that of_node will be there with mtd devices, it's no longer relevant. Thanks, Miquèl
On 06/10/2023 17:32, Miquel Raynal wrote: > Hi Rafał, > > rafal@milecki.pl wrote on Fri, 06 Oct 2023 13:41:52 +0200: > >> On 2023-10-05 17:59, Miquel Raynal wrote: >>> At a first look it might seem that the presence of the of_node pointer >>> in the nvmem device does not matter much, but in practice, after > looking >>> deep into the DT core, nvmem_add_cells_from_dt() will simply and always >>> return NULL if this field is not provided. As most mtd devices don't >>> populate this field (this could evolve later), it means none of their >>> children cells will be populated unless no_of_node is explicitly set to >>> false. In order to clarify the logic, let's add clear check at the >>> beginning of this helper. >> >> I'm somehow confused by above explanation and code too. I read it >> carefully 5 times but I can't see what exactly this change helps with. >> >> At first look at nvmem_add_cells_from_legacy_of() I can see it uses >> "of_node" so I don't really agree with "it might seem that the presence >> of the of_node pointer in the nvmem device does not matter much". >> >> You really don't need to look deep into DT core (actually you don't have >> to look into it at all) to understand that nvmem_add_cells_from_dt() >> will return 0 (nitpicking: not NULL) for a NULL pointer. It's all made >> of for_each_child_of_node(). Obviously it does nothing if there is >> nothing to loop over. > > That was not obvious to me as I thought it would start from /, which I > think some other function do when you don't provide a start node. > >> Given that for_each_child_of_node() is NULL-safe I think code from this >> patch is redundant. > > I didn't say it was not safe, just not explicit. > >> Later you mention "no_of_node" which I agree to be a very non-intuitive >> config option. As pointed in another thread I already sent: >> [PATCH] Revert "nvmem: add new config option" >> https://lore.kernel.org/lkml/ba3c419a-6511-480a-b5f2-6c418f9c02e7@gmail.com/t/ > > I actually wanted to find again that patch and could not get my hands on > it, but it is probably a much better fix than my other mtd patch, I > agree with you. > >> Maybe with above patch finally things will get more clear and we don't >> need this PATCH after all? > > Yes. Srinivas, what are your plans for the above patch? for_each_child_of_node is null safe, so this patch is really not adding much value TBH. --srini > > Thanks, > Miquèl
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index eaf6a3fe8ca6..286efd3f5a31 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -743,6 +743,9 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem) { + if (!nvmem->dev.of_node) + return 0; + return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node); }