From nobody Wed Sep 10 09:19:07 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8335CEE499E for ; Fri, 18 Aug 2023 20:41:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380020AbjHRUlV (ORCPT ); Fri, 18 Aug 2023 16:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379997AbjHRUlO (ORCPT ); Fri, 18 Aug 2023 16:41:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF4F13C3C; Fri, 18 Aug 2023 13:41:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 483D660201; Fri, 18 Aug 2023 20:41:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E166BC433C7; Fri, 18 Aug 2023 20:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692391270; bh=KNeygD7b0invSgMAHHcJ7ByINYFALCfTCNGcUBotyfg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Uvo5jm+e+1bUypvaZ2KvUMW6pAt2i+X3PNu+D7I7UI8o82GHQp0wyWTmqJbEQQh4c O5OeHT+LsZJHQfiimLj03Xu5/oE51yN2XgzgWpwnwq4d1EGnvKb+x6f8aU3uYxkxdW 9mArTFrP6EzhEkqVCQS+zY/i+OL3tTanDZDyYww1peZG3AQOZXpocfdOTOggD/UODN otnzzc/bujHK1y20xdiHP1umlC4f8487vgIMNfss4LpPxRrEQvya15t03d6XbJZlIk RQyKOgPgu4Xmkxg2HOA8VNofyBQ6hcDgGvan35mr2DvLkNdjpQ+k2BJoDcmvjHoF+9 MrG0v3tOtCTyQ== Received: (nullmailer pid 545146 invoked by uid 1000); Fri, 18 Aug 2023 20:41:06 -0000 From: Rob Herring Date: Fri, 18 Aug 2023 15:41:00 -0500 Subject: [PATCH v3 5/6] of: dynamic: Move dead property list check into property add/update functions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230801-dt-changeset-fixes-v3-5-5f0410e007dd@kernel.org> References: <20230801-dt-changeset-fixes-v3-0-5f0410e007dd@kernel.org> In-Reply-To: <20230801-dt-changeset-fixes-v3-0-5f0410e007dd@kernel.org> To: Frank Rowand , "Enrico Weigelt, metux IT consult" , "Rafael J. Wysocki" , Sakari Ailus , Petr Mladek , Andy Shevchenko , Geert Uytterhoeven Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.13-dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The changeset code checks for a property in the deadprops list when adding/updating a property, but of_add_property() and of_update_property() do not. As the users of these functions are pretty simple, they have not hit this scenario or else the property lists would get corrupted. With this there are 3 cases of removing a property from either deadprops or properties lists, so add a helper to find and remove a matching property. Signed-off-by: Rob Herring Reviewed-by: Geert Uytterhoeven --- v3: - Make the helper remove a property from either deadprops or properties lists - Keep existing style in deadprops loop v2: - Add helper to remove property from deadprops list --- drivers/of/base.c | 37 ++++++++++++++++++++++++------------- drivers/of/dynamic.c | 19 ------------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index e235f3a57ea8..3f9ddd18ff4b 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1530,6 +1530,20 @@ int of_count_phandle_with_args(const struct device_n= ode *np, const char *list_na } EXPORT_SYMBOL(of_count_phandle_with_args); =20 +static struct property *__of_remove_property_from_list(struct property **l= ist, struct property *prop) +{ + struct property **next; + + for (next =3D list; *next; next =3D &(*next)->next) { + if (*next =3D=3D prop) { + *next =3D prop->next; + prop->next =3D NULL; + return prop; + } + } + return NULL; +} + /** * __of_add_property - Add a property to a node without lock operations * @np: Caller's Device Node @@ -1539,6 +1553,8 @@ int __of_add_property(struct device_node *np, struct = property *prop) { struct property **next; =20 + __of_remove_property_from_list(&np->deadprops, prop); + prop->next =3D NULL; next =3D &np->properties; while (*next) { @@ -1583,21 +1599,14 @@ EXPORT_SYMBOL_GPL(of_add_property); =20 int __of_remove_property(struct device_node *np, struct property *prop) { - struct property **next; - - for (next =3D &np->properties; *next; next =3D &(*next)->next) { - if (*next =3D=3D prop) - break; + if (__of_remove_property_from_list(&np->properties, prop)) { + /* Found the property, add it to deadprops list */ + prop->next =3D np->deadprops; + np->deadprops =3D prop; + return 0; } - if (*next =3D=3D NULL) - return -ENODEV; - - /* found the node */ - *next =3D prop->next; - prop->next =3D np->deadprops; - np->deadprops =3D prop; =20 - return 0; + return -ENODEV; } =20 /** @@ -1641,6 +1650,8 @@ int __of_update_property(struct device_node *np, stru= ct property *newprop, { struct property **next, *oldprop; =20 + __of_remove_property_from_list(&np->deadprops, newprop); + for (next =3D &np->properties; *next; next =3D &(*next)->next) { if (of_prop_cmp((*next)->name, newprop->name) =3D=3D 0) break; diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 1876af5b01fc..d3ad970ad7b8 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -564,7 +564,6 @@ static int __of_changeset_entry_notify(struct of_change= set_entry *ce, =20 static int __of_changeset_entry_apply(struct of_changeset_entry *ce) { - struct property **propp; unsigned long flags; int ret =3D 0; =20 @@ -579,15 +578,6 @@ static int __of_changeset_entry_apply(struct of_change= set_entry *ce) __of_detach_node(ce->np); break; case OF_RECONFIG_ADD_PROPERTY: - /* If the property is in deadprops then it must be removed */ - for (propp =3D &ce->np->deadprops; *propp; propp =3D &(*propp)->next) { - if (*propp =3D=3D ce->prop) { - *propp =3D ce->prop->next; - ce->prop->next =3D NULL; - break; - } - } - ret =3D __of_add_property(ce->np, ce->prop); break; case OF_RECONFIG_REMOVE_PROPERTY: @@ -595,15 +585,6 @@ static int __of_changeset_entry_apply(struct of_change= set_entry *ce) break; =20 case OF_RECONFIG_UPDATE_PROPERTY: - /* If the property is in deadprops then it must be removed */ - for (propp =3D &ce->np->deadprops; *propp; propp =3D &(*propp)->next) { - if (*propp =3D=3D ce->prop) { - *propp =3D ce->prop->next; - ce->prop->next =3D NULL; - break; - } - } - ret =3D __of_update_property(ce->np, ce->prop, &ce->old_prop); break; default: --=20 2.40.1