Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1576445ybg; Thu, 4 Jun 2020 13:21:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxp3t8zTM9ib8F9aDLxsoaptFMqiSb+naJW0SQ/2cgikuh3gvn2TnkB+bq25HdL1RTvZ26t X-Received: by 2002:a17:907:b03:: with SMTP id h3mr5773601ejl.367.1591302061284; Thu, 04 Jun 2020 13:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591302061; cv=none; d=google.com; s=arc-20160816; b=zXxTp1sRkGznzJd4fOOgfWHcMfp2SEMmKNctNLBlmB0Orax36kITI57y74a/P88a8S 3VL4GDqDL95DV3LQpsbNyzfMcWXnA1d4UUEWs3rLl8hwzYo23M369CZt464moOgdg/8Q HhLn0F/ZHXKMk6K9ghstGC4SS6381trfjfqn8tlhWqMtquBAdOKjkr+bclq3CC21k/b5 ZZb3vB0V2iXATOGoQqwBOJ/3i8hk7pAr8EzY2AjsEf8xirsC0D6rSjkqrEaFwhk+lHVn CFsvyMmyMI0WOJy5FrHaZPmf7vUGYLz6I5RBOrdlLj7BR7ZebuJM8vhe1kkXTarzlNDZ va+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=hY+Rqxopw6ZRBCfHGfBhIQ0E6DE7gEuD+EjCBWGQnMk=; b=Beky88R2k8xz1lWZ01OeAMqA0m0he07QvZplx2Map/pc+zlMYNpY8cZVilRFOlEWOf XAZFXwfIukT8CliqDVKEWUzvMtQrDGzSDAhTQQ0yeNiyVhxCxuyVM/Z0rfAompBP5rpJ k3zq5bZzd2O9cQUc7MDdVyA8K2LQN461+qKZAmyAARaPUa8K0jy7QmvpgT3h85qVZtt5 y3/KxfgV9OwlsoShiqjRdr7wQsjexPLCt40clRGYSbt6fMrpSTa1iUXoRKcuNfi5COp3 jin32TN/tphH92m7HacO2q+KOCPMjPlDvLimQUTdZJ/KEAUgk9/cKVbNSjwNSizX/QAP /fNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L0sRYQaM; 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 v1si2382912ejd.588.2020.06.04.13.20.38; Thu, 04 Jun 2020 13:21:01 -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=L0sRYQaM; 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 S1728800AbgFDUP1 (ORCPT + 99 others); Thu, 4 Jun 2020 16:15:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:59570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726666AbgFDUP0 (ORCPT ); Thu, 4 Jun 2020 16:15:26 -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 8086B2067B; Thu, 4 Jun 2020 20:15:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591301726; bh=nh6iqP7pKii9WtoysGEakHtXlKm8WZrihRzKio25mpw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=L0sRYQaMkF8MApvnQWJxq7PThTjN3ACXwLABb5mU8JIeqeXPe4Vt33AYljlyvHvZ9 BG0V+j+461wfVDLQNa1wln1Z3bGbIKL2SYzB9tYQ5gNPVLLvdo5pn1qIJ5CAncYGTD ZgRKqJ+Gva8WlhVQiBZe/Jm/iK1SCVekAgwqcDmI= Date: Thu, 4 Jun 2020 22:15:23 +0200 From: Greg Kroah-Hartman To: jorhand@linux.microsoft.com Cc: Heikki Krogerus , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-next@vger.kernel.org Subject: Re: [PATCH] software node: recursively unregister child swnodes Message-ID: <20200604201523.GA1308830@kroah.com> References: <20200604193623.16946-1-jorhand@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200604193623.16946-1-jorhand@linux.microsoft.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 04, 2020 at 12:36:23PM -0700, jorhand@linux.microsoft.com wrote: > From: Jordan Hand > > If a child swnode is unregistered after it's parent, it can lead to > undefined behavior. Crashing the system is not really "undefined" :) > When a swnode is unregistered, recursively free it's children to avoid > this condition. Are you sure? Why would you be unregistering a child after it's parent? Why not just do not do that? > > 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); You should document that you just changed the behaivor here, as you are now really doing fwnode_remove_software_node_and_all_children(). but again, why? Who wants to unregister a child before a parent? thanks, greg k-h