From nobody Wed Sep 10 09:22:04 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 92CB5EE49A1 for ; Fri, 18 Aug 2023 20:41:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380025AbjHRUlW (ORCPT ); Fri, 18 Aug 2023 16:41:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380000AbjHRUlQ (ORCPT ); Fri, 18 Aug 2023 16:41:16 -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 939D53C3C; Fri, 18 Aug 2023 13:41:15 -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 28F9F617F0; Fri, 18 Aug 2023 20:41:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC6D2C433C8; Fri, 18 Aug 2023 20:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692391274; bh=GfHSC+os2/e/UBzVMi4/4e2UzAKpnFR59mGA7/NVZZs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HtOmfJzXmLIo2L+NzbkVznKbKi3xZ/uUJn1T5wLSc2QeJGsmU2c31EO5Cbzn+CV26 I/CE2lJio6gkwnbmeA4GSRwoMsZwBT2/YZ/sGCxwVCZSEn6rKP6QfcZysgMgI6XpIW +64hh2e8Z1VyNNPsbJHoBuOm8H0UnbRQKk1KSOsHB3pv3UVUwpnq0+IO7PhEJhWvFx 25H0rBp2uQzHTkmt1v5sUt+ss66+x/kSRFPajKixQIeVVQqkvT4buM+bS1VIvzRgKo HJq4BrurcqN19x86ZwibhposJEeQYDqW3/Fd29V2TcuTIHSjN3UPLNltONlIzdFqdM ei55UXTcGedRw== Received: (nullmailer pid 545140 invoked by uid 1000); Fri, 18 Aug 2023 20:41:06 -0000 From: Rob Herring Date: Fri, 18 Aug 2023 15:40:57 -0500 Subject: [PATCH v3 2/6] of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230801-dt-changeset-fixes-v3-2-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 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 Fix this by moving the printing in __of_changeset_entry_apply() outside the lock. As the only difference in the the multiple prints is the action name, use the existing "action_names" to refactor the prints into a single print. Fixes: a92eb7621b9fb2c2 ("lib/vsprintf: Make use of fwnode API to obtain no= de names and separators") Reported-by: Geert Uytterhoeven Signed-off-by: Rob Herring Reviewed-by: Geert Uytterhoeven --- v6 (v3 in this series): - Add check on 'action' bounds. As action is only set in of_changeset_action(), add the check there. - Drop printing the changeset entry pointer v5 (v2 in this series): - Move majority of refactoring to separate patch and minimize the fix to just moving the print out of the locked section. v4: - Add missing 'static' reported by 0-day v3: - Re-implement Geert's fix to move the prints rather than move the spinlock v1 and v2 from Geert simply moved the devtree_lock into each case statement: https://lore.kernel.org/all/c593d8389352c574b5be69d4ca4810da13326a50.169053= 3838.git.geert+renesas@glider.be/ --- drivers/of/dynamic.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index e311d406b170..4999636eaa92 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -63,15 +63,14 @@ int of_reconfig_notifier_unregister(struct notifier_blo= ck *nb) } EXPORT_SYMBOL_GPL(of_reconfig_notifier_unregister); =20 -#ifdef DEBUG -const char *action_names[] =3D { +static const char *action_names[] =3D { + [0] =3D "INVALID", [OF_RECONFIG_ATTACH_NODE] =3D "ATTACH_NODE", [OF_RECONFIG_DETACH_NODE] =3D "DETACH_NODE", [OF_RECONFIG_ADD_PROPERTY] =3D "ADD_PROPERTY", [OF_RECONFIG_REMOVE_PROPERTY] =3D "REMOVE_PROPERTY", [OF_RECONFIG_UPDATE_PROPERTY] =3D "UPDATE_PROPERTY", }; -#endif =20 int of_reconfig_notify(unsigned long action, struct of_reconfig_data *p) { @@ -620,21 +619,9 @@ static int __of_changeset_entry_apply(struct of_change= set_entry *ce) } =20 ret =3D __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 =3D __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; =20 case OF_RECONFIG_UPDATE_PROPERTY: @@ -648,20 +635,17 @@ static int __of_changeset_entry_apply(struct of_chang= eset_entry *ce) } =20 ret =3D __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 =3D -EINVAL; } raw_spin_unlock_irqrestore(&devtree_lock, flags); =20 - if (ret) + if (ret) { + pr_err("changeset: apply failed: %-15s %pOF:%s\n", + action_names[ce->action], ce->np, ce->prop->name); return ret; + } =20 switch (ce->action) { case OF_RECONFIG_ATTACH_NODE: @@ -947,6 +931,9 @@ int of_changeset_action(struct of_changeset *ocs, unsig= ned long action, if (!ce) return -ENOMEM; =20 + if (WARN_ON(action >=3D ARRAY_SIZE(action_names))) + return -EINVAL; + /* get a reference to the node */ ce->action =3D action; ce->np =3D of_node_get(np); --=20 2.40.1