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,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, 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 13ECEC4338F for ; Mon, 2 Aug 2021 19:29:06 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2FC9A60F51 for ; Mon, 2 Aug 2021 19:29:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2FC9A60F51 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2FB32833B8; Mon, 2 Aug 2021 21:29:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 960728342F; Mon, 2 Aug 2021 21:29:00 +0200 (CEST) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 34CC182D81 for ; Mon, 2 Aug 2021 21:28:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=wlozano@collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: wlozano) with ESMTPSA id A89401F42CA0 Subject: Re: [PATCH 1/3] dtoc: Rename is_wider_than() to reduce confusion To: Simon Glass Cc: U-Boot Mailing List , Tom Rini References: <20210729012311.1406847-1-sjg@chromium.org> <20210729012311.1406847-2-sjg@chromium.org> <6e2f5e0d-7d18-92d2-ca82-f4dbabe125d6@collabora.com> From: Walter Lozano Message-ID: <51e16888-b15b-b52d-7f0d-b53a17fe20f4@collabora.com> Date: Mon, 2 Aug 2021 16:28:49 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Hi Simon, On 8/1/21 11:50 PM, Simon Glass wrote: > Hi Walter, > > On Sun, 1 Aug 2021 at 20:45, Walter Lozano wrote: >> Hi Simon, >> >> Thanks for checking this bug, I'm glad that you were able to come with >> fix quickly. I have some questions, I hope that you find some time to >> help me understand. >> >> On 7/28/21 10:23 PM, Simon Glass wrote: >>> The current name is confusing because the logic is actually backwards from >>> what you might expect. Rename it to needs_widening() and update the >>> comments. >>> >>> Signed-off-by: Simon Glass >>> --- >>> >>> tools/dtoc/fdt.py | 15 +++++++++------ >>> 1 file changed, 9 insertions(+), 6 deletions(-) >>> >>> diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py >>> index 3996971e39c..9749966d5fb 100644 >>> --- a/tools/dtoc/fdt.py >>> +++ b/tools/dtoc/fdt.py >>> @@ -24,16 +24,19 @@ from patman import tools >>> >>> # A list of types we support >>> class Type(IntEnum): >>> + # Types in order from widest to narrowest >>> (BYTE, INT, STRING, BOOL, INT64) = range(5) >> Sorry but I don't understand why BYTE is wider than INT (or INT64) > I think perhaps we need a better name. A wider type is one that can > hold the values of a narrower one, plus more. > > In this case a 'bytes' type can hold anything (bytes, int, int64, > bool) so is the 'widest' there is. It is the lowest common denominator > in the devicetree. Thanks for taking the time to explain. I understand the idea behind your explanation but I still not sure if I follow you completely. In any case, let me add a few words in order to be more clear. It is my impression that when you say 'bytes' (and not BYTE like in the declaration) you are referring to a list. Is that the case? If not, BYTE (8 bit) seems to be narrower than INT (32 bits), isn't it? Also, another example is INT, BOOL and INT64. It is clear that INT is wider than BOOL, but why BOOL is wider than INT64? As reference I have been checking https://devicetree-specification.readthedocs.io/en/stable/devicetree-basics.html#property-values >>> - def is_wider_than(self, other): >>> - """Check if another type is 'wider' than this one >>> + def needs_widening(self, other): >>> + """Check if this type needs widening to hold a value from another type >>> >>> - A wider type is one that holds more information than an earlier one, >>> - similar to the concept of type-widening in C. >>> + A wider type is one that can hold a wider array of information than >>> + another one, or is less restrictive, so it can hold the information of >>> + another type as well as its own. This is similar to the concept of >>> + type-widening in C. >>> >>> This uses a simple arithmetic comparison, since type values are in order >>> - from narrowest (BYTE) to widest (INT64). >>> + from widest (BYTE) to narrowest (INT64). >>> >>> Args: >>> other: Other type to compare against >>> @@ -149,7 +152,7 @@ class Prop: >>> update the current property to be like the second, since it is less >>> specific. >>> """ >>> - if self.type.is_wider_than(newprop.type): >>> + if self.type.needs_widening(newprop.type): >>> if self.type == Type.INT and newprop.type == Type.BYTE: >>> if type(self.value) == list: >>> new_value = [] > Regards, > Simon Regards, Walter