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=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 F2563C4338F for ; Mon, 2 Aug 2021 02:50:54 +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 728FD61050 for ; Mon, 2 Aug 2021 02:50:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 728FD61050 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 CCE4983359; Mon, 2 Aug 2021 04:50:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="R1CbvaL1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A04BD83346; Mon, 2 Aug 2021 04:50:44 +0200 (CEST) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DA9948333F for ; Mon, 2 Aug 2021 04:50:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-wr1-x42f.google.com with SMTP id b13so8794571wrs.3 for ; Sun, 01 Aug 2021 19:50:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Qq5x+SO84ITgiyhxUrp4wcn9dpdd3NaCs+WjzhVzJY4=; b=R1CbvaL12vU+NErtNM5IhnwFeo7RQuExmhLJ/v6VFptja3XkInpgag/Qibq30AxZmE l9W24nE6HslXfc/mwJ9ugBpdYLf3EdOxI2p2q+2b7Fm01UAJSqV625U9dOCHjlOR0csh Z7aFFvmV4bzQvOGDD6d2PwtAq/qTEa58ijJRk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Qq5x+SO84ITgiyhxUrp4wcn9dpdd3NaCs+WjzhVzJY4=; b=e+yxqialzkCqx5P7oLz8hGcyDDpcoQRbtjjvZ9ht6rqSI7q7vw9HLsEDl044X0CPj+ cSmw1XIUkDoogC9IUUjwsOfBzkK15J//0aOzbYMthzwEaBoouKmnSySJ+oc0XLoRsOhB M1lSMn6DFG8M08OdR3iEuQXVpY2TLAHdRSvAhL7NkRBaeFmYVoMroxalt4hsKZKL5xyj /RxjAgP3MCdC5g532vHKDZZGP5ssq+am0uJX8k5wGxRLxaDK0z2FpmWdNOkcG+gjOWVm 9OegjwbZVsDJeJmQ7QTkZeKnfXwxO4030gx1zTYiFvSUs0kYTkenn2qfRbQWEKuPbx27 FcIQ== X-Gm-Message-State: AOAM530AfpqKL/4F7ZO5rWuNldHOTdUH9A5muB4vHKnnIq1YTI+XOe8O XkG0lkFXz+n5BiOvD4av2GtObdwHg5GPxElRKR4ceg== X-Google-Smtp-Source: ABdhPJyoS0LJFbc8EQvBfV66wobAXxjZqSfh18EyPdgEa7tx7HQyodAD8Q+owdVhanhzj7LFO3zGBO9DSt8Tl4EaGjQ= X-Received: by 2002:a5d:5644:: with SMTP id j4mr15729253wrw.66.1627872640170; Sun, 01 Aug 2021 19:50:40 -0700 (PDT) MIME-Version: 1.0 References: <20210729012311.1406847-1-sjg@chromium.org> <20210729012311.1406847-3-sjg@chromium.org> <7ee1414a-66c3-2de6-69e4-85687392e526@collabora.com> In-Reply-To: <7ee1414a-66c3-2de6-69e4-85687392e526@collabora.com> From: Simon Glass Date: Sun, 1 Aug 2021 20:50:28 -0600 Message-ID: Subject: Re: [PATCH 2/3] dtoc: Fix widening an int array to an int To: Walter Lozano Cc: U-Boot Mailing List , Tom Rini , Walter Lozano Content-Type: text/plain; charset="UTF-8" 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 Walter, On Sun, 1 Aug 2021 at 20:45, Walter Lozano wrote: > > Hi Simon, > > I know you already merged this one but I have some doubts I would like > to check with you. > > On 7/28/21 10:23 PM, Simon Glass wrote: > > An int array can hold a single int so we should not need to do anything > > in the widening operation. However due to a quirk in the code, an int[3] > > widened with an int produced an int[4]. Fix this and add a test. > > > > Fix a comment typo while we are here. > > > > Signed-off-by: Simon Glass > > Reported-by: Tom Rini > > --- > > > > test/dm/of_platdata.c | 4 +--- > > tools/dtoc/fdt.py | 15 ++++++++------- > > tools/dtoc/test_dtoc.py | 6 +++--- > > tools/dtoc/test_fdt.py | 11 ++++++++++- > > 4 files changed, 22 insertions(+), 14 deletions(-) > > > > diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c > > index 0f89c7a7da8..e3fa01afddf 100644 > > --- a/test/dm/of_platdata.c > > +++ b/test/dm/of_platdata.c > > @@ -35,11 +35,10 @@ static int dm_test_of_plat_props(struct unit_test_state *uts) > > plat = dev_get_plat(dev); > > ut_assert(plat->boolval); > > ut_asserteq(1, plat->intval); > > - ut_asserteq(4, ARRAY_SIZE(plat->intarray)); > > + ut_asserteq(3, ARRAY_SIZE(plat->intarray)); > > ut_asserteq(2, plat->intarray[0]); > > ut_asserteq(3, plat->intarray[1]); > > ut_asserteq(4, plat->intarray[2]); > > - ut_asserteq(0, plat->intarray[3]); > > ut_asserteq(5, plat->byteval); > > ut_asserteq(3, ARRAY_SIZE(plat->bytearray)); > > ut_asserteq(6, plat->bytearray[0]); > > @@ -61,7 +60,6 @@ static int dm_test_of_plat_props(struct unit_test_state *uts) > > ut_asserteq(5, plat->intarray[0]); > > ut_asserteq(0, plat->intarray[1]); > > ut_asserteq(0, plat->intarray[2]); > > - ut_asserteq(0, plat->intarray[3]); > > ut_asserteq(8, plat->byteval); > > ut_asserteq(3, ARRAY_SIZE(plat->bytearray)); > > ut_asserteq(1, plat->bytearray[0]); > > diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py > > index 9749966d5fb..429e95f9a96 100644 > > --- a/tools/dtoc/fdt.py > > +++ b/tools/dtoc/fdt.py > > @@ -163,13 +163,14 @@ class Prop: > > self.value = new_value > > self.type = newprop.type > > > > - if type(newprop.value) == list and type(self.value) != list: > > - self.value = [self.value] > > - > > - if type(self.value) == list and len(newprop.value) > len(self.value): > > - val = self.GetEmpty(self.type) > > - while len(self.value) < len(newprop.value): > > - self.value.append(val) > > + if type(newprop.value) == list: > > + if type(self.value) != list: > > + self.value = [self.value] > > + > > + if len(newprop.value) > len(self.value): > > + val = self.GetEmpty(self.type) > > + while len(self.value) < len(newprop.value): > > + self.value.append(val) > > > > @classmethod > > def GetEmpty(self, type): > > diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py > > index 863ede90b7a..44d5d0c354a 100755 > > --- a/tools/dtoc/test_dtoc.py > > +++ b/tools/dtoc/test_dtoc.py > > @@ -296,7 +296,7 @@ struct dtd_sandbox_spl_test { > > \tbool\t\tboolval; > > \tunsigned char\tbytearray[3]; > > \tunsigned char\tbyteval; > > -\tfdt32_t\t\tintarray[4]; > > +\tfdt32_t\t\tintarray[3]; > > \tfdt32_t\t\tintval; > > \tunsigned char\tlongbytearray[9]; > > \tunsigned char\tnotstring[5]; > > @@ -354,7 +354,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test = { > > \t.boolval\t\t= true, > > \t.bytearray\t\t= {0x6, 0x0, 0x0}, > > \t.byteval\t\t= 0x5, > > -\t.intarray\t\t= {0x2, 0x3, 0x4, 0x0}, > > +\t.intarray\t\t= {0x2, 0x3, 0x4}, > > \t.intval\t\t\t= 0x1, > > \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, > > \t\t0x11}, > > @@ -377,7 +377,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test2 = { > > \t.acpi_name\t\t= "\\\\_SB.GPO0", > > \t.bytearray\t\t= {0x1, 0x23, 0x34}, > > \t.byteval\t\t= 0x8, > > -\t.intarray\t\t= {0x5, 0x0, 0x0, 0x0}, > > +\t.intarray\t\t= {0x5, 0x0, 0x0}, > > \t.intval\t\t\t= 0x3, > > \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0x0, 0x0, 0x0, 0x0, > > \t\t0x0}, > > diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py > > index 856392b1bd9..857861c14ed 100755 > > --- a/tools/dtoc/test_fdt.py > > +++ b/tools/dtoc/test_fdt.py > > @@ -379,7 +379,7 @@ class TestProp(unittest.TestCase): > > self.assertEqual(Type.INT, prop.type) > > self.assertEqual(1, fdt32_to_cpu(prop.value)) > > > > - # Convert singla value to array > > + # Convert single value to array > > prop2 = self.node.props['intarray'] > > prop.Widen(prop2) > > self.assertEqual(Type.INT, prop.type) > > @@ -422,6 +422,15 @@ class TestProp(unittest.TestCase): > > self.assertTrue(isinstance(prop.value, list)) > > self.assertEqual(3, len(prop.value)) > > > > + # Widen an array of ints with an int (should do nothing) > > + prop = self.node.props['intarray'] > > + prop2 = node2.props['intarray'] > > I was expecting intval instead of intarray here. Yes that is a bug, thanks for spotting it. It isn't testing what it should be. I'll come up with a fix. > > > + self.assertEqual(Type.INT, prop.type) > > + self.assertEqual(3, len(prop.value)) > > + prop.Widen(prop2) > > + self.assertEqual(Type.INT, prop.type) > > + self.assertEqual(3, len(prop.value)) > > + > > def testAdd(self): > > """Test adding properties""" > > self.fdt.pack() > > Regards, Simon