From patchwork Tue Aug 1 21:54:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 1815649 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=i3lVzoPk; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RFpnV67c6z1yYC for ; Wed, 2 Aug 2023 07:55:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232750AbjHAVzZ (ORCPT ); Tue, 1 Aug 2023 17:55:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232764AbjHAVzX (ORCPT ); Tue, 1 Aug 2023 17:55:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1A121BE3; Tue, 1 Aug 2023 14:55:22 -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 6C60161717; Tue, 1 Aug 2023 21:55:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C9F1C433C7; Tue, 1 Aug 2023 21:55:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690926921; bh=B054y3pqR16hOaTgxhtMZYYzfM1FPP+fTzP45gff++8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=i3lVzoPkWKvatlAmGtmtZECfXTJmytvIw9nVWdr1PT0cPMUlXdaC4BrjgQUKrc/r1 HI8JWAgR+bsku8IV6iID66RJ6I4BEEQW0uvKLmlQBNTJnjr0WdA4Aj/3Mc6b+ebeHX bLul4tGlWmh8OP9DpwZ0xeRvTiK+0fV+6wSvGiP7pD16WgyKWyvo+A0ak/Iq4cppJw mWgtZsU5uBmSNS7/OoaDhUjRIpGoqWPAinj+/lh4hHuxssa+7HY5iofVwVEzcY0LJz mns8ArNf+IUHmlGwbWCt9HozXfTCtVPH/oNSDSVahcdLT6y0MJNcoGuqrwdkISq2Kh gmykdmkURTe3w== Received: (nullmailer pid 2469337 invoked by uid 1000); Tue, 01 Aug 2023 21:55:14 -0000 From: Rob Herring Date: Tue, 01 Aug 2023 15:54:44 -0600 Subject: [PATCH 1/5] of: unittest: Fix EXPECT for parse_phandle_with_args_map() test MIME-Version: 1.0 Message-Id: <20230801-dt-changeset-fixes-v1-1-b5203e3fc22f@kernel.org> References: <20230801-dt-changeset-fixes-v1-0-b5203e3fc22f@kernel.org> In-Reply-To: <20230801-dt-changeset-fixes-v1-0-b5203e3fc22f@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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: devicetree@vger.kernel.org Commit 12e17243d8a1 ("of: base: improve error msg in of_phandle_iterator_next()") added printing of the phandle value on error, but failed to update the unittest. Fixes: 12e17243d8a1 ("of: base: improve error msg in of_phandle_iterator_next()") Signed-off-by: Rob Herring --- drivers/of/unittest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index e5b0eea8011c..d943bf87c94d 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -664,12 +664,12 @@ static void __init of_unittest_parse_phandle_with_args_map(void) memset(&args, 0, sizeof(args)); EXPECT_BEGIN(KERN_INFO, - "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle"); + "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle 12345678"); rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle", "phandle", 0, &args); EXPECT_END(KERN_INFO, - "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle"); + "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle 12345678"); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); From patchwork Tue Aug 1 21:54:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 1815647 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=S4716JGH; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RFpnT2Fhvz1yYC for ; Wed, 2 Aug 2023 07:55:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232769AbjHAVzX (ORCPT ); Tue, 1 Aug 2023 17:55:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232749AbjHAVzW (ORCPT ); Tue, 1 Aug 2023 17:55:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66F6C212A; Tue, 1 Aug 2023 14:55:19 -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 DB8F361716; Tue, 1 Aug 2023 21:55:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88391C433C9; Tue, 1 Aug 2023 21:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690926918; bh=5XERczcs3rSSs3MOT5bfWrqodT+KqtbFCljGkj26Qso=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=S4716JGHvOW8JlVDLOk1uy46CUyveQNNd67rR7s0GcQ8PSL6Yyj7t6STWJUlIlu8J L+2GwmsI1jS1/wz0J4D6vtB67PpU2ARyd/cnVNf9B7mOvcNDPYNeMCRCkqd1OOAnw1 +rQ8rxsPCsGfKSy3bJeYKpajwu28+mshWysoT8lQgdCdurB13ziolzzT7ynKPqgNt3 5yNi0fxVJyBlf4gOqwnTzL0qs70rSx5ttXqr46+aV2b8eX8VUr+F6SIpCeqwDiFDPr 1KOtCkpQx85yENTQJlyxiPzqtVpMUqrKsGruAn9EejfmY2dmyNQDE3BrTj0NsjckoP dY4DuNcDjbo1g== Received: (nullmailer pid 2469339 invoked by uid 1000); Tue, 01 Aug 2023 21:55:14 -0000 From: Rob Herring Date: Tue, 01 Aug 2023 15:54:45 -0600 Subject: [PATCH 2/5] of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock MIME-Version: 1.0 Message-Id: <20230801-dt-changeset-fixes-v1-2-b5203e3fc22f@kernel.org> References: <20230801-dt-changeset-fixes-v1-0-b5203e3fc22f@kernel.org> In-Reply-To: <20230801-dt-changeset-fixes-v1-0-b5203e3fc22f@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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: devicetree@vger.kernel.org While originally it was fine to format strings using "%pOF" while holding devtree_lock, this now causes a deadlock. Lockdep reports: of_get_parent from of_fwnode_get_parent+0x18/0x24 ^^^^^^^^^^^^^ of_fwnode_get_parent from fwnode_count_parents+0xc/0x28 fwnode_count_parents from fwnode_full_name_string+0x18/0xac fwnode_full_name_string from device_node_string+0x1a0/0x404 device_node_string from pointer+0x3c0/0x534 pointer from vsnprintf+0x248/0x36c vsnprintf from vprintk_store+0x130/0x3b4 To fix this, move the printing in __of_changeset_entry_apply() outside the lock. As there's already similar printing of the same changeset actions, refactor all of them to use a common action print function. This has the side benefit of getting rid of some ifdefs. Fixes: a92eb7621b9fb2c2 ("lib/vsprintf: Make use of fwnode API to obtain node names and separators") Reported-by: Geert Uytterhoeven Signed-off-by: Rob Herring --- v3: - Add missing 'static' reported by 0-day v1 and v2 from Geert simply moved the devtree_lock into each case statement: https://lore.kernel.org/all/c593d8389352c574b5be69d4ca4810da13326a50.1690533838.git.geert+renesas@glider.be/ --- drivers/of/dynamic.c | 80 ++++++++++++---------------------------------------- 1 file changed, 18 insertions(+), 62 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index e311d406b170..aa3821836937 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -63,37 +63,31 @@ int of_reconfig_notifier_unregister(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(of_reconfig_notifier_unregister); -#ifdef DEBUG -const char *action_names[] = { +static const char *action_names[] = { [OF_RECONFIG_ATTACH_NODE] = "ATTACH_NODE", [OF_RECONFIG_DETACH_NODE] = "DETACH_NODE", [OF_RECONFIG_ADD_PROPERTY] = "ADD_PROPERTY", [OF_RECONFIG_REMOVE_PROPERTY] = "REMOVE_PROPERTY", [OF_RECONFIG_UPDATE_PROPERTY] = "UPDATE_PROPERTY", }; -#endif + +static void of_changeset_action_print(unsigned long action, struct device_node *np, + const char *prop_name) +{ + if (prop_name) + pr_cont("%-15s %pOF:%s\n", action_names[action], np, prop_name); + else + pr_cont("%-15s %pOF\n", action_names[action], np); +} int of_reconfig_notify(unsigned long action, struct of_reconfig_data *p) { int rc; -#ifdef DEBUG struct of_reconfig_data *pr = p; - switch (action) { - case OF_RECONFIG_ATTACH_NODE: - case OF_RECONFIG_DETACH_NODE: - pr_debug("notify %-15s %pOF\n", action_names[action], - pr->dn); - break; - case OF_RECONFIG_ADD_PROPERTY: - case OF_RECONFIG_REMOVE_PROPERTY: - case OF_RECONFIG_UPDATE_PROPERTY: - pr_debug("notify %-15s %pOF:%s\n", action_names[action], - pr->dn, pr->prop->name); - break; + if (pr_debug("notify ")) + of_changeset_action_print(action, pr->dn, pr->prop ? pr->prop->name : NULL); - } -#endif rc = blocking_notifier_call_chain(&of_reconfig_chain, action, p); return notifier_to_errno(rc); } @@ -504,30 +498,6 @@ static void __of_changeset_entry_destroy(struct of_changeset_entry *ce) kfree(ce); } -#ifdef DEBUG -static void __of_changeset_entry_dump(struct of_changeset_entry *ce) -{ - switch (ce->action) { - case OF_RECONFIG_ADD_PROPERTY: - case OF_RECONFIG_REMOVE_PROPERTY: - case OF_RECONFIG_UPDATE_PROPERTY: - pr_debug("cset<%p> %-15s %pOF/%s\n", ce, action_names[ce->action], - ce->np, ce->prop->name); - break; - case OF_RECONFIG_ATTACH_NODE: - case OF_RECONFIG_DETACH_NODE: - pr_debug("cset<%p> %-15s %pOF\n", ce, action_names[ce->action], - ce->np); - break; - } -} -#else -static inline void __of_changeset_entry_dump(struct of_changeset_entry *ce) -{ - /* empty */ -} -#endif - static void __of_changeset_entry_invert(struct of_changeset_entry *ce, struct of_changeset_entry *rce) { @@ -599,7 +569,8 @@ static int __of_changeset_entry_apply(struct of_changeset_entry *ce) unsigned long flags; int ret = 0; - __of_changeset_entry_dump(ce); + if (pr_debug("changeset: applying: cset<%p> ", ce)) + of_changeset_action_print(ce->action, ce->np, ce->prop ? ce->prop->name : NULL); raw_spin_lock_irqsave(&devtree_lock, flags); switch (ce->action) { @@ -620,21 +591,9 @@ static int __of_changeset_entry_apply(struct of_changeset_entry *ce) } ret = __of_add_property(ce->np, ce->prop); - if (ret) { - pr_err("changeset: add_property failed @%pOF/%s\n", - ce->np, - ce->prop->name); - break; - } break; case OF_RECONFIG_REMOVE_PROPERTY: ret = __of_remove_property(ce->np, ce->prop); - if (ret) { - pr_err("changeset: remove_property failed @%pOF/%s\n", - ce->np, - ce->prop->name); - break; - } break; case OF_RECONFIG_UPDATE_PROPERTY: @@ -648,20 +607,17 @@ static int __of_changeset_entry_apply(struct of_changeset_entry *ce) } ret = __of_update_property(ce->np, ce->prop, &old_prop); - if (ret) { - pr_err("changeset: update_property failed @%pOF/%s\n", - ce->np, - ce->prop->name); - break; - } break; default: ret = -EINVAL; } raw_spin_unlock_irqrestore(&devtree_lock, flags); - if (ret) + if (ret) { + pr_err("changeset: apply failed: cset<%p> ", ce); + of_changeset_action_print(ce->action, ce->np, ce->prop ? ce->prop->name : NULL); return ret; + } switch (ce->action) { case OF_RECONFIG_ATTACH_NODE: From patchwork Tue Aug 1 21:54:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 1815648 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=WRQx49Oe; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RFpnV05kLz1yYC for ; Wed, 2 Aug 2023 07:55:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232757AbjHAVzY (ORCPT ); Tue, 1 Aug 2023 17:55:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232755AbjHAVzW (ORCPT ); Tue, 1 Aug 2023 17:55:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FC842134; Tue, 1 Aug 2023 14:55:21 -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 88E0161750; Tue, 1 Aug 2023 21:55:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40AABC433C9; Tue, 1 Aug 2023 21:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690926920; bh=0701bJOBg95miRQteud7cUM6mXMgwl0E9IlK6sWteVY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WRQx49Oeiy26fg7ZSa6GSgPSjjD7/P8HOJH+OgvWj1VNuw7bW+FbfZfWfOiEb2NgO +v9txqQqn0H3ZMQQrXiglgUgOVAEi56waMkWb+fNANp6VKtLyBDs+cWkyngmSmtv9l Q5F6j7Tw0xFsjc0tiMjzI9vF8oXdpkkmIMbL8WH4QUGSJrib1HbIhqmR7OoUGDsckZ 1IJx0DamqpX/f7sbfP96y0yJS6Kcu3I39EJNhvvFWlou/FUk8rLpVm94VWFBO6yx9W SXT9Dy15dpeBs/R0QjBSEIP2r8NAIXKELcY/AUS3xhvDiCxbl2sFgp/TFFmQEsQOZO yZGU9VukGuFWQ== Received: (nullmailer pid 2469341 invoked by uid 1000); Tue, 01 Aug 2023 21:55:14 -0000 From: Rob Herring Date: Tue, 01 Aug 2023 15:54:46 -0600 Subject: [PATCH 3/5] of: dynamic: Fix race in getting old property when updating property MIME-Version: 1.0 Message-Id: <20230801-dt-changeset-fixes-v1-3-b5203e3fc22f@kernel.org> References: <20230801-dt-changeset-fixes-v1-0-b5203e3fc22f@kernel.org> In-Reply-To: <20230801-dt-changeset-fixes-v1-0-b5203e3fc22f@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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: devicetree@vger.kernel.org __of_update_property() returns the existing property if there is one, but that value is never added to the changeset. Updates work because the existing property is also retrieved in of_changeset_action(), but that is racy as of_changeset_action() doesn't hold any locks. The property could be changed before the changeset is applied. Signed-off-by: Rob Herring --- drivers/of/dynamic.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index aa3821836937..31603b5a4ffc 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -565,7 +565,7 @@ static int __of_changeset_entry_notify(struct of_changeset_entry *ce, static int __of_changeset_entry_apply(struct of_changeset_entry *ce) { - struct property *old_prop, **propp; + struct property **propp; unsigned long flags; int ret = 0; @@ -606,7 +606,7 @@ static int __of_changeset_entry_apply(struct of_changeset_entry *ce) } } - ret = __of_update_property(ce->np, ce->prop, &old_prop); + ret = __of_update_property(ce->np, ce->prop, &ce->old_prop); break; default: ret = -EINVAL; @@ -908,9 +908,6 @@ int of_changeset_action(struct of_changeset *ocs, unsigned long action, ce->np = of_node_get(np); ce->prop = prop; - if (action == OF_RECONFIG_UPDATE_PROPERTY && prop) - ce->old_prop = of_find_property(np, prop->name, NULL); - /* add it to the list */ list_add_tail(&ce->node, &ocs->entries); return 0; From patchwork Tue Aug 1 21:54:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 1815650 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=AkuLzquP; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RFpnb73zpz1yYC for ; Wed, 2 Aug 2023 07:55:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230514AbjHAVza (ORCPT ); Tue, 1 Aug 2023 17:55:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232762AbjHAVz0 (ORCPT ); Tue, 1 Aug 2023 17:55:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7A31268C; Tue, 1 Aug 2023 14:55:24 -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 1FF1A61717; Tue, 1 Aug 2023 21:55:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB8C2C433C8; Tue, 1 Aug 2023 21:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690926923; bh=j035GzdMWI78hJ6xt3QYyUQ7BSA2USCCzXpQCLzuaQQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AkuLzquPcKwKmyHz45oa81zSrNbECRKfvP510Ls5d6u95yQthyCw0+nJy4U+HnG0Q fx4TMGZSuMERk+kjrqYF3AxEmrFYD+znh+S6J0TkhfV8VE94pMCL7Lj0XQ5CHQckiB h4s0pjmx9Z/45Ui3QnKUrMG5l+BQSWLlO3AoPaXrjEmOEfavHiDxcOSdNAQ8vmL+3C WtLkbtWnJkErhCS6x/Z6PijlJQxJ58892rEB7EbA3RA8DocX022M31CUTHSjea5xhm /7h6N3w2M+EBg8Y/idCmfZ6wHQPyH+bqq4RVfyVhnUGvYi6MM41RfbURq5SoQxNg4v RrM+bIpWqdQig== Received: (nullmailer pid 2469343 invoked by uid 1000); Tue, 01 Aug 2023 21:55:14 -0000 From: Rob Herring Date: Tue, 01 Aug 2023 15:54:47 -0600 Subject: [PATCH 4/5] of: dynamic: Move dead property list check into property add/update functions MIME-Version: 1.0 Message-Id: <20230801-dt-changeset-fixes-v1-4-b5203e3fc22f@kernel.org> References: <20230801-dt-changeset-fixes-v1-0-b5203e3fc22f@kernel.org> In-Reply-To: <20230801-dt-changeset-fixes-v1-0-b5203e3fc22f@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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: devicetree@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. Signed-off-by: Rob Herring --- drivers/of/base.c | 17 +++++++++++++++++ drivers/of/dynamic.c | 19 ------------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 166fb7d75337..99c07f3cbf10 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1538,6 +1538,14 @@ int __of_add_property(struct device_node *np, struct property *prop) { struct property **next; + /* If the property is in deadprops then it must be removed */ + for (next = &np->deadprops; *next; next = &(*next)->next) { + if (*next == prop) { + *next = prop->next; + break; + } + } + prop->next = NULL; next = &np->properties; while (*next) { @@ -1640,6 +1648,15 @@ int __of_update_property(struct device_node *np, struct property *newprop, { struct property **next, *oldprop; + /* If the property is in deadprops then it must be removed */ + for (next = &np->deadprops; *next; next = &(*next)->next) { + if (*next == newprop) { + *next = newprop->next; + newprop->next = NULL; + break; + } + } + for (next = &np->properties; *next; next = &(*next)->next) { if (of_prop_cmp((*next)->name, newprop->name) == 0) break; diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 31603b5a4ffc..4fd3699691b6 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -565,7 +565,6 @@ static int __of_changeset_entry_notify(struct of_changeset_entry *ce, static int __of_changeset_entry_apply(struct of_changeset_entry *ce) { - struct property **propp; unsigned long flags; int ret = 0; @@ -581,15 +580,6 @@ static int __of_changeset_entry_apply(struct of_changeset_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 = &ce->np->deadprops; *propp; propp = &(*propp)->next) { - if (*propp == ce->prop) { - *propp = ce->prop->next; - ce->prop->next = NULL; - break; - } - } - ret = __of_add_property(ce->np, ce->prop); break; case OF_RECONFIG_REMOVE_PROPERTY: @@ -597,15 +587,6 @@ static int __of_changeset_entry_apply(struct of_changeset_entry *ce) break; case OF_RECONFIG_UPDATE_PROPERTY: - /* If the property is in deadprops then it must be removed */ - for (propp = &ce->np->deadprops; *propp; propp = &(*propp)->next) { - if (*propp == ce->prop) { - *propp = ce->prop->next; - ce->prop->next = NULL; - break; - } - } - ret = __of_update_property(ce->np, ce->prop, &ce->old_prop); break; default: From patchwork Tue Aug 1 21:54:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 1815652 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=X7bRXlm/; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RFpns656Mz1yYC for ; Wed, 2 Aug 2023 07:55:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbjHAVzo (ORCPT ); Tue, 1 Aug 2023 17:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231269AbjHAVza (ORCPT ); Tue, 1 Aug 2023 17:55:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 008B326A3; Tue, 1 Aug 2023 14:55:26 -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 03A5C61735; Tue, 1 Aug 2023 21:55:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF998C433C9; Tue, 1 Aug 2023 21:55:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690926925; bh=UWkbtTwArpfxA+PVVNq82HZpmdGnmNashPrlejXB09k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=X7bRXlm/M/np1MHpLVS4xJ8NWtnSZ1zJMJUGU6InEuIVydMCltMRWhqg40qL2vZ8x tIxthPtUvRMG5TcGyrcJIKIurni4ZTrTX1I4XftP/uDxf5P83kRQ4dKyTAtIcwiCX8 TSpPi9V3rNAE7cjy9THYUUts0CAN+igAC8Vi5LasuaXVcEpbQAgSoMHPQQ/LwyYtJn HUJUVa7CbMjpRatKFh8vsV9pcuP0ZwqbnYCvHt2tpof25Hh2samO9RiEPLVfU74GA1 9ixnza/pJAaJ5wk0tK1YG4qU008sUroHYkjoffXYCk+spnxnatcDHaGv9Su4gsUX9P k5gieFs26hIOA== Received: (nullmailer pid 2469345 invoked by uid 1000); Tue, 01 Aug 2023 21:55:14 -0000 From: Rob Herring Date: Tue, 01 Aug 2023 15:54:48 -0600 Subject: [PATCH 5/5] of: Refactor node and property manipulation function locking MIME-Version: 1.0 Message-Id: <20230801-dt-changeset-fixes-v1-5-b5203e3fc22f@kernel.org> References: <20230801-dt-changeset-fixes-v1-0-b5203e3fc22f@kernel.org> In-Reply-To: <20230801-dt-changeset-fixes-v1-0-b5203e3fc22f@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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: devicetree@vger.kernel.org All callers of __of_{add,remove,update}_property() and __of_{attach,detach}_node() wrap the call with the devtree_lock spinlock. Let's move the spinlock into the functions. This allows moving the sysfs update functions into those functions as well. Signed-off-by: Rob Herring --- drivers/of/base.c | 69 ++++++++++++++++++++++++++-------------------------- drivers/of/dynamic.c | 51 ++++++++++++-------------------------- 2 files changed, 50 insertions(+), 70 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 99c07f3cbf10..4ee050ace11e 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1536,8 +1536,12 @@ EXPORT_SYMBOL(of_count_phandle_with_args); */ int __of_add_property(struct device_node *np, struct property *prop) { + int rc = 0; + unsigned long flags; struct property **next; + raw_spin_lock_irqsave(&devtree_lock, flags); + /* If the property is in deadprops then it must be removed */ for (next = &np->deadprops; *next; next = &(*next)->next) { if (*next == prop) { @@ -1549,15 +1553,21 @@ int __of_add_property(struct device_node *np, struct property *prop) prop->next = NULL; next = &np->properties; while (*next) { - if (strcmp(prop->name, (*next)->name) == 0) + if (strcmp(prop->name, (*next)->name) == 0) { /* duplicate ! don't insert it */ - return -EEXIST; - + rc = -EEXIST; + goto out; + } next = &(*next)->next; } *next = prop; - return 0; +out: + raw_spin_unlock_irqrestore(&devtree_lock, flags); + if (!rc) + __of_add_property_sysfs(np, prop); + + return rc; } /** @@ -1567,23 +1577,12 @@ int __of_add_property(struct device_node *np, struct property *prop) */ int of_add_property(struct device_node *np, struct property *prop) { - unsigned long flags; int rc; mutex_lock(&of_mutex); - - raw_spin_lock_irqsave(&devtree_lock, flags); rc = __of_add_property(np, prop); - raw_spin_unlock_irqrestore(&devtree_lock, flags); - - if (!rc) - __of_add_property_sysfs(np, prop); - mutex_unlock(&of_mutex); - if (!rc) - of_property_notify(OF_RECONFIG_ADD_PROPERTY, np, prop, NULL); - return rc; } EXPORT_SYMBOL_GPL(of_add_property); @@ -1591,20 +1590,29 @@ EXPORT_SYMBOL_GPL(of_add_property); int __of_remove_property(struct device_node *np, struct property *prop) { struct property **next; + unsigned long flags; + int rc = 0; + + raw_spin_lock_irqsave(&devtree_lock, flags); for (next = &np->properties; *next; next = &(*next)->next) { if (*next == prop) break; } - if (*next == NULL) - return -ENODEV; - + if (*next == NULL) { + rc = -ENODEV; + goto out; + } /* found the node */ *next = prop->next; prop->next = np->deadprops; np->deadprops = prop; - return 0; +out: + raw_spin_unlock_irqrestore(&devtree_lock, flags); + if (!rc) + __of_remove_property_sysfs(np, prop); + return rc; } /** @@ -1619,21 +1627,13 @@ int __of_remove_property(struct device_node *np, struct property *prop) */ int of_remove_property(struct device_node *np, struct property *prop) { - unsigned long flags; int rc; if (!prop) return -ENODEV; mutex_lock(&of_mutex); - - raw_spin_lock_irqsave(&devtree_lock, flags); rc = __of_remove_property(np, prop); - raw_spin_unlock_irqrestore(&devtree_lock, flags); - - if (!rc) - __of_remove_property_sysfs(np, prop); - mutex_unlock(&of_mutex); if (!rc) @@ -1647,6 +1647,9 @@ int __of_update_property(struct device_node *np, struct property *newprop, struct property **oldpropp) { struct property **next, *oldprop; + unsigned long flags; + + raw_spin_lock_irqsave(&devtree_lock, flags); /* If the property is in deadprops then it must be removed */ for (next = &np->deadprops; *next; next = &(*next)->next) { @@ -1675,6 +1678,10 @@ int __of_update_property(struct device_node *np, struct property *newprop, *next = newprop; } + raw_spin_unlock_irqrestore(&devtree_lock, flags); + + __of_update_property_sysfs(np, newprop, oldprop); + return 0; } @@ -1690,21 +1697,13 @@ int __of_update_property(struct device_node *np, struct property *newprop, int of_update_property(struct device_node *np, struct property *newprop) { struct property *oldprop; - unsigned long flags; int rc; if (!newprop->name) return -EINVAL; mutex_lock(&of_mutex); - - raw_spin_lock_irqsave(&devtree_lock, flags); rc = __of_update_property(np, newprop, &oldprop); - raw_spin_unlock_irqrestore(&devtree_lock, flags); - - if (!rc) - __of_update_property_sysfs(np, newprop, oldprop); - mutex_unlock(&of_mutex); if (!rc) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 4fd3699691b6..c59f581792f1 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -199,6 +199,9 @@ static void __of_attach_node(struct device_node *np) { const __be32 *phandle; int sz; + unsigned long flags; + + raw_spin_lock_irqsave(&devtree_lock, flags); if (!of_node_check_flag(np, OF_OVERLAY)) { np->name = __of_get_property(np, "name", NULL); @@ -221,6 +224,10 @@ static void __of_attach_node(struct device_node *np) np->parent->child = np; of_node_clear_flag(np, OF_DETACHED); np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE; + + raw_spin_unlock_irqrestore(&devtree_lock, flags); + + __of_attach_node_sysfs(np); } /** @@ -230,17 +237,12 @@ static void __of_attach_node(struct device_node *np) int of_attach_node(struct device_node *np) { struct of_reconfig_data rd; - unsigned long flags; memset(&rd, 0, sizeof(rd)); rd.dn = np; mutex_lock(&of_mutex); - raw_spin_lock_irqsave(&devtree_lock, flags); __of_attach_node(np); - raw_spin_unlock_irqrestore(&devtree_lock, flags); - - __of_attach_node_sysfs(np); mutex_unlock(&of_mutex); of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, &rd); @@ -251,13 +253,15 @@ int of_attach_node(struct device_node *np) void __of_detach_node(struct device_node *np) { struct device_node *parent; + unsigned long flags; - if (WARN_ON(of_node_check_flag(np, OF_DETACHED))) - return; + raw_spin_lock_irqsave(&devtree_lock, flags); parent = np->parent; - if (WARN_ON(!parent)) + if (WARN_ON(of_node_check_flag(np, OF_DETACHED) || !parent)) { + raw_spin_unlock_irqrestore(&devtree_lock, flags); return; + } if (parent->child == np) parent->child = np->sibling; @@ -274,6 +278,10 @@ void __of_detach_node(struct device_node *np) /* race with of_find_node_by_phandle() prevented by devtree_lock */ __of_phandle_cache_inv_entry(np->phandle); + + raw_spin_unlock_irqrestore(&devtree_lock, flags); + + __of_detach_node_sysfs(np); } /** @@ -283,17 +291,12 @@ void __of_detach_node(struct device_node *np) int of_detach_node(struct device_node *np) { struct of_reconfig_data rd; - unsigned long flags; memset(&rd, 0, sizeof(rd)); rd.dn = np; mutex_lock(&of_mutex); - raw_spin_lock_irqsave(&devtree_lock, flags); __of_detach_node(np); - raw_spin_unlock_irqrestore(&devtree_lock, flags); - - __of_detach_node_sysfs(np); mutex_unlock(&of_mutex); of_reconfig_notify(OF_RECONFIG_DETACH_NODE, &rd); @@ -565,13 +568,11 @@ static int __of_changeset_entry_notify(struct of_changeset_entry *ce, static int __of_changeset_entry_apply(struct of_changeset_entry *ce) { - unsigned long flags; int ret = 0; if (pr_debug("changeset: applying: cset<%p> ", ce)) of_changeset_action_print(ce->action, ce->np, ce->prop ? ce->prop->name : NULL); - raw_spin_lock_irqsave(&devtree_lock, flags); switch (ce->action) { case OF_RECONFIG_ATTACH_NODE: __of_attach_node(ce->np); @@ -592,7 +593,6 @@ static int __of_changeset_entry_apply(struct of_changeset_entry *ce) default: ret = -EINVAL; } - raw_spin_unlock_irqrestore(&devtree_lock, flags); if (ret) { pr_err("changeset: apply failed: cset<%p> ", ce); @@ -600,25 +600,6 @@ static int __of_changeset_entry_apply(struct of_changeset_entry *ce) return ret; } - switch (ce->action) { - case OF_RECONFIG_ATTACH_NODE: - __of_attach_node_sysfs(ce->np); - break; - case OF_RECONFIG_DETACH_NODE: - __of_detach_node_sysfs(ce->np); - break; - case OF_RECONFIG_ADD_PROPERTY: - /* ignore duplicate names */ - __of_add_property_sysfs(ce->np, ce->prop); - break; - case OF_RECONFIG_REMOVE_PROPERTY: - __of_remove_property_sysfs(ce->np, ce->prop); - break; - case OF_RECONFIG_UPDATE_PROPERTY: - __of_update_property_sysfs(ce->np, ce->prop, ce->old_prop); - break; - } - return 0; }