Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4683442iob; Sun, 8 May 2022 21:53:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjpdw4rvQOlpb74OZ58aP/PbeHxPeI1tCkBS6LtXl3xd8cHRxwc4/1KQ22spLDbNRD/Aj+ X-Received: by 2002:a17:90b:1b01:b0:1dc:46ed:90de with SMTP id nu1-20020a17090b1b0100b001dc46ed90demr24839612pjb.107.1652072012226; Sun, 08 May 2022 21:53:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652072012; cv=none; d=google.com; s=arc-20160816; b=EQ3Nfzp+voOkM/qKKFxETW+A6bBP8TDuHGoGTuXCk85+M2Tat9te0DbhBdx1zUWp8m tM+i9EUv9zHOK9Wwg1TSnzW1itqWivgabEXpYA+bqI3jnuC7V96h872X0H2LqEHrmSSb RGxbWs6D/wdLTcUfDDFM9tR9py1z1YZDkhSN4kTYU+58QXb1OmHzBaCECmm1r0cr4t81 kxOG6HTT/Ka1fiSNU5d5XRVQbg8MqoF89L6UEecf1dYWRcnSR77m3IJTEo810cePdxTQ npVqn0XMqUUDw4ch/PbKI+O/aNK8zTrD4iTDLoQI2uz+46qni62Iq82U5+4uGT/c0DrY 52QQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=mL7sWko/zEY1GKDqcFPw+UFI+rxOeH7QwJrlHZfz4xY=; b=T/WoWm5qJiFifsLt9yG3NMe6n/gtUEo8fLYaKun74XuEuQIfQc8j/4TxBazXRcj7VB bkqP9MdI40/TgpAclVvRL5j9Og0Ip1BpohBIqNNCWPLdM7RuoltbmQssrV93e2ZyAftD kZC/0iBVqyDBIAhSYLyIztzihPXQCJVQ+kL3fAjdRdNBHM69WE+ZR2+rokyGB+oknd3x JTO94myYB36ASouOWnJW5QK3vdmuJOLPsroMwQc4EizlgXoy4zAIWkHYz21ieLat6rpI OpVYceKc+HR5QC5Hd220nzKKLzDr4JlSZ1Oz8mEIF9YIgHgEtg3AqbbYICikPmDGwuJq wOSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="AK/nPydJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x21-20020a056a00189500b004fa3a8e0039si13277170pfh.240.2022.05.08.21.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 21:53:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="AK/nPydJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 60EE11339FD; Sun, 8 May 2022 21:52:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380193AbiEFHyX (ORCPT + 99 others); Fri, 6 May 2022 03:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389728AbiEFHyR (ORCPT ); Fri, 6 May 2022 03:54:17 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01ECB186F5; Fri, 6 May 2022 00:50:30 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 98185E000D; Fri, 6 May 2022 07:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1651823429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mL7sWko/zEY1GKDqcFPw+UFI+rxOeH7QwJrlHZfz4xY=; b=AK/nPydJipqNR7/LTq0Oh0NBKO5Xpwgy2vPit48NwT+fXefQVBBFNbZBGu4uzLX8zh+R8E l98COuBzajZ62Ma6Yr5qHS/RX4ZT8dZi/0iPa8gISwhl1IOLq0wDl7vPK5+S5tBrSfRS3S Vv2WvRTuOMcQTvHJypbz5lwne8EUK1namBL6Gs2g4GaZFwUhWTnlfdYmUIUcoflzQpL7cL khQVgoVMxc2hCLixlzDABxy8HT9C5JOVX6lPD9DPuYSjZBuRY034T15iZ/T3TDzEpc+dz8 rvQLkCKD31v8tVr0jpiVApbQ24Az7LAY0Df5s4RFgvRx4l6bBKQoM1j2DTRUfw== Date: Fri, 6 May 2022 09:49:05 +0200 From: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= To: Rob Herring Cc: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Frank Rowand , Nathan Lynch , Laurent Dufour , Daniel Henrique Barboza , David Gibson , Andrew Morton , David Hildenbrand , Ohhoon Kwon , "Aneesh Kumar K.V" , YueHaibing , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni Subject: Re: [PATCH 1/3] of: dynamic: add of_property_alloc() and of_property_free() Message-ID: <20220506094905.27bc99aa@fixe.home> In-Reply-To: References: <20220504154033.750511-1-clement.leger@bootlin.com> <20220504154033.750511-2-clement.leger@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: X-Mailing-List: linux-kernel@vger.kernel.org Le Thu, 5 May 2022 14:37:15 -0500, Rob Herring a =C3=A9crit : > > + > > +/** > > + * of_property_alloc - Allocate a property dynamically. > > + * @name: Name of the new property > > + * @value: Value that will be copied into the new property value > > + * @value_len: length of @value to be copied into the new property val= ue > > + * @len: Length of new property value, must be greater than @value_len= =20 >=20 > What's the usecase for the lengths being different? That doesn't seem=20 > like a common case, so perhaps handle it with a NULL value and=20 > non-zero length. Then the caller has to deal with populating=20 > prop->value. That was actually something used by powerpc code but agreed, letting the user recopy it's values seems fine to me and the usage will be more clear. > > /* > > - * NOTE: There is no check for zero length value. > > - * In case of a boolean property, this will allocate a value > > - * of zero bytes. We do this to work around the use > > - * of of_get_property() calls on boolean values. > > + * Even if the property has no value, it must be set to a > > + * non-null value since of_get_property() is used to check > > + * some values that might or not have a values (ranges for > > + * instance). Moreover, when the node is released, prop->value > > + * is kfreed so the memory must come from kmalloc. =20 >=20 > Allowing for NULL value didn't turn out well... >=20 > We know that we can do the kfree because OF_DYNAMIC is set IIRC... >=20 > If we do 1 allocation for prop and value, then we can test=20 > for "prop->value =3D=3D prop + 1" to determine if we need to free or not. Sounds like a good idea. --=20 Cl=C3=A9ment L=C3=A9ger, Embedded Linux and Kernel engineer at Bootlin https://bootlin.com