Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp395403ybs; Sun, 24 May 2020 08:35:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSLVTJ8qlHBi4zioDwpLm5/+Utze7ZvGOMBoFG1qPL4g5YFPciFARwev+dJ81W9yCiTjPT X-Received: by 2002:a17:906:b4e:: with SMTP id v14mr15423959ejg.302.1590334500230; Sun, 24 May 2020 08:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590334500; cv=none; d=google.com; s=arc-20160816; b=H5Fd4cBA1GJU0vpORnuq7phyJiqvhA+i6EP7Uv2CKv2mlnzndwGX95mlwI4/ZuE41E 1a3KzJmJSEIS4bYsk371Vmwfd+EfJkdTjaZTx1tkhGaUmB79ZoqKOIQCyhfNuW515k6R B7u6rPPh4uwEfDhUYm58o2Cge1lgMv0ANT+KqZOjKz6id+ZgidD7I0TgtzrnsRe0QuzN ENgenjvu7yrrdUSr7CeXA3x3wJWzAHV2dbn4P47NE+upucLkDziutdeGi6WZpu6pXSWc h8GLqZQfwo24iiu+NokJRwJeKYCyfat9KwlAnUP5b6YQNTN0DdPf0ao3veHRGlv5v7qW Obmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Ws6EB7crasL0/5W0Hkjx6ggZ2WUtwNTCzJhPC/muKdo=; b=IrfTGva6Wygx+OR82eIvaJZs9v7ohR0G7qcODZLtTiC/l3RogHWGVFv7pEcCpljmRY t+tYS/GHiwtJjoZ8dDX2dTsOomFHx+QDvRGr2Eg3fxlQmIAt1RvYnYuxP0UYRZSr9bY2 0zziCmzHO7VwrMsM65s0m9Nt3NmsuOBXpTDB36/+g6GsQ6uXxSMVCTENQyu5CckJSdQw z9u+jQ0A7B3iKIhTAE3OgUob5lpdHb9qA3ld/w8tsN6gAT8vmAeviJRFV0ap8/C8RQLy x0R2t8mfrKhjr0etOW8OqM3MxDLOYFKuUJQKSLWDmS0GYNPNjGEbGb0gRqU7rjCpJ7z0 eVxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AQGnc8Wz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mj15si7921398ejb.404.2020.05.24.08.34.37; Sun, 24 May 2020 08:35:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AQGnc8Wz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387726AbgEXPa6 (ORCPT + 99 others); Sun, 24 May 2020 11:30:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:37690 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728879AbgEXPa5 (ORCPT ); Sun, 24 May 2020 11:30:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1BE5C207CB; Sun, 24 May 2020 15:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590334257; bh=T5XlMX19GYR/KRA5wWejsFAh7tRi9SxxgN01sDGq38w=; h=From:To:Cc:Subject:Date:From; b=AQGnc8WzdNAZCZUBt1N6mXsUUB0Xa3DRtU9ywegGDWbbJtFw6RGpylHJCeKHyJVLx BvIauU1I3urxFD0qcQWlLbyLUM9pbkULux7dFUdstLo7mjCjVhwrTfhSHwEzTFyYJL joO1xS4t0I0VMYMKJuGg70KZPueQSYQIxIDDPkd0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: linux@roeck-us.net, Greg Kroah-Hartman , Naresh Kamboju , kernel test robot , stable , Andy Shevchenko , Brendan Higgins , Dmitry Torokhov , Heikki Krogerus , Petr Mladek , "Rafael J . Wysocki" , Randy Dunlap , Rasmus Villemoes , Sakari Ailus , Sergey Senozhatsky , Steven Rostedt Subject: [PATCH 1/2] software node: implement software_node_unregister() Date: Sun, 24 May 2020 17:30:40 +0200 Message-Id: <20200524153041.2361-1-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes it is better to unregister individual nodes instead of trying to do them all at once with software_node_unregister_nodes(), so create software_node_unregister() so that you can unregister them one at a time. This is especially important when creating nodes in a hierarchy, with parent -> children representations. Children always need to be removed before a parent is, as the swnode logic assumes this is going to be the case. Fix up the lib/test_printf.c fwnode_pointer() test which to use this new function as it had the problem of tearing things down in the backwards order. Fixes: f1ce39df508d ("lib/test_printf: Add tests for %pfw printk modifier") Reported-by: Naresh Kamboju Reported-by: kernel test robot Cc: stable Cc: Andy Shevchenko Cc: Brendan Higgins Cc: Dmitry Torokhov Cc: Heikki Krogerus Cc: Petr Mladek Cc: Rafael J. Wysocki Cc: Randy Dunlap Cc: Rasmus Villemoes Cc: Sakari Ailus Cc: Sergey Senozhatsky Cc: Steven Rostedt Signed-off-by: Greg Kroah-Hartman --- drivers/base/swnode.c | 27 +++++++++++++++++++++------ include/linux/property.h | 1 + lib/test_printf.c | 4 +++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index de8d3543e8fe..770b1f47a625 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -712,17 +712,18 @@ EXPORT_SYMBOL_GPL(software_node_register_nodes); * @nodes: Zero terminated array of software nodes to be unregistered * * Unregister multiple software nodes at once. + * + * NOTE: Be careful using this call if the nodes had parent pointers set up in + * them before registering. If so, it is wiser to remove the nodes + * individually, in the correct order (child before parent) instead of relying + * on the sequential order of the list of nodes in the array. */ void software_node_unregister_nodes(const struct software_node *nodes) { - struct swnode *swnode; int i; - for (i = 0; nodes[i].name; i++) { - swnode = software_node_to_swnode(&nodes[i]); - if (swnode) - fwnode_remove_software_node(&swnode->fwnode); - } + for (i = 0; nodes[i].name; i++) + software_node_unregister(&nodes[i]); } EXPORT_SYMBOL_GPL(software_node_unregister_nodes); @@ -741,6 +742,20 @@ int software_node_register(const struct software_node *node) } EXPORT_SYMBOL_GPL(software_node_register); +/** + * software_node_unregister - Unregister static software node + * @node: The software node to be unregistered + */ +void software_node_unregister(const struct software_node *node) +{ + struct swnode *swnode; + + swnode = software_node_to_swnode(node); + if (swnode) + fwnode_remove_software_node(&swnode->fwnode); +} +EXPORT_SYMBOL_GPL(software_node_unregister); + struct fwnode_handle * fwnode_create_software_node(const struct property_entry *properties, const struct fwnode_handle *parent) diff --git a/include/linux/property.h b/include/linux/property.h index d86de017c689..0d4099b4ce1f 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -441,6 +441,7 @@ int software_node_register_nodes(const struct software_node *nodes); void software_node_unregister_nodes(const struct software_node *nodes); int software_node_register(const struct software_node *node); +void software_node_unregister(const struct software_node *node); int software_node_notify(struct device *dev, unsigned long action); diff --git a/lib/test_printf.c b/lib/test_printf.c index 6b1622f4d7c2..fc63b8959d42 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -637,7 +637,9 @@ static void __init fwnode_pointer(void) test(second_name, "%pfwP", software_node_fwnode(&softnodes[1])); test(third_name, "%pfwP", software_node_fwnode(&softnodes[2])); - software_node_unregister_nodes(softnodes); + software_node_unregister(&softnodes[2]); + software_node_unregister(&softnodes[1]); + software_node_unregister(&softnodes[0]); } static void __init -- 2.26.2