Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1553809ybg; Thu, 4 Jun 2020 12:39:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnaOE0FxgGP8oInloKgnNrj0Sg4RyPe6AtIs0xnOhmnqo4DkP+lZaJkdIeMBqlVwi0sBEO X-Received: by 2002:aa7:cc19:: with SMTP id q25mr5096200edt.26.1591299592351; Thu, 04 Jun 2020 12:39:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591299592; cv=none; d=google.com; s=arc-20160816; b=uNSMqVqrR+pJIm2p1MU5YWELNY6G2ZxYOhaaa+9UiQQO9jXoXC9aZzNR6thkAOEL8A lUGeQSGhYynzgmsnIRaNTKR0V6IPlO+7sKPi4RfZd462QqOTP47C6cnsqR07YG0dcy8Y 57S0QTNOdsk7q1x9MEN4l7tf0I6xLqLfIG9w9iz+XD1oieNVRRtdzKJtIBGG5MlptwZm QAJEZa3xpVLU4kOsEMrmi0ZzlyQNjfo06L2HQaJSFZUfPl0seDwRGRZLNU6X3rNpK/S3 aDO8iR0DPUuryZsGrWPQ7B1+26kRPBZ4/54jLUqAQzch856b/Q34uwdz1X2S2mV5028e uvFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=Wj3IFzpGg4vQIux2KK5gfmytqMUrK5JDeB2oZyK7nZ0=; b=pGzwytobQ4dkV9SYU7Wcp4uAKvIMZJ0KVfkaXx9e7x491xuOKU4F9wamKf1WKLqmoL jdJoEKAimZ6ylsn9qe1kP1VuKRvJZeaaxnYP5zZ1106PcuGM2Vgo0MUTx87iS0blbt7g zckPGsRBow15cy+18po0YiuuHIPciimxQpOomjlO623J7mGxDa9ZLZhD9s8Dd7KBt/m3 P5nEECe4tXCatRux0l7bzXCnzdUzHvldMo0iSjOTcX7NZFDmQHqObYaK5qfAnH1qvv9E 6k1lgo1bXbh+zOBQip5g6IIdODI3hAnNxF+I8tp9kKdCHdcnMmE+idY/fUYh97YaJeDy A9gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ETG3c85b; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lh2si1794733ejb.400.2020.06.04.12.39.29; Thu, 04 Jun 2020 12:39:52 -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=@linux.microsoft.com header.s=default header.b=ETG3c85b; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729415AbgFDTgg (ORCPT + 99 others); Thu, 4 Jun 2020 15:36:36 -0400 Received: from linux.microsoft.com ([13.77.154.182]:37402 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728420AbgFDTgg (ORCPT ); Thu, 4 Jun 2020 15:36:36 -0400 Received: from jorhand-sb2.corp.microsoft.com (unknown [76.104.235.235]) by linux.microsoft.com (Postfix) with ESMTPSA id 4919820B7185; Thu, 4 Jun 2020 12:36:35 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4919820B7185 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1591299395; bh=Wj3IFzpGg4vQIux2KK5gfmytqMUrK5JDeB2oZyK7nZ0=; h=From:To:Cc:Subject:Date:From; b=ETG3c85b67XW691yPa3rhCXvFbCy28ekwVUI/3jsxQXpMF+RNf2bQlWPcPS7PflRy umsrgGkv6fO7SIpnQxXH+MFZLOmsh2WU6cIlJoq8XbRi7CsRcWGk6DsKBWGAlHI9rP xNU1On31vVlDKuYro63toACMcMZKqnP9a1S2mXWI= From: jorhand@linux.microsoft.com To: Heikki Krogerus , "Rafael J . Wysocki" Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-next@vger.kernel.org, Jordan Hand Subject: [PATCH] software node: recursively unregister child swnodes Date: Thu, 4 Jun 2020 12:36:23 -0700 Message-Id: <20200604193623.16946-1-jorhand@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jordan Hand If a child swnode is unregistered after it's parent, it can lead to undefined behavior. When a swnode is unregistered, recursively free it's children to avoid this condition. Signed-off-by: Jordan Hand --- drivers/base/swnode.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index e5eb27375416..e63093b1542b 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -619,6 +619,8 @@ static void software_node_release(struct kobject *kobj) property_entries_free(swnode->node->properties); kfree(swnode->node); } + + list_del(&kobj->entry); ida_destroy(&swnode->child_ids); kfree(swnode); } @@ -712,11 +714,6 @@ 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) { @@ -839,10 +836,16 @@ EXPORT_SYMBOL_GPL(fwnode_create_software_node); void fwnode_remove_software_node(struct fwnode_handle *fwnode) { struct swnode *swnode = to_swnode(fwnode); + struct swnode *child = NULL; if (!swnode) return; + while (!list_empty(&swnode->children)) { + child = list_first_entry_or_null(&swnode->children, struct swnode, entry); + fwnode_remove_software_node(&child->fwnode); + } + kobject_put(&swnode->kobj); } EXPORT_SYMBOL_GPL(fwnode_remove_software_node); -- 2.17.1