lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2024120537-varying-chain-7d1e@gregkh>
Date: Thu, 5 Dec 2024 08:00:44 +0100
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: Bjorn Helgaas <helgaas@...nel.org>
Cc: Herve Codina <herve.codina@...tlin.com>,
	"Rafael J. Wysocki" <rafael@...nel.org>,
	Rob Herring <robh@...nel.org>,
	Saravana Kannan <saravanak@...gle.com>,
	Bjorn Helgaas <bhelgaas@...gle.com>, Lizhi Hou <lizhi.hou@....com>,
	linux-kernel@...r.kernel.org, devicetree@...r.kernel.org,
	linux-pci@...r.kernel.org,
	Allan Nielsen <allan.nielsen@...rochip.com>,
	Horatiu Vultur <horatiu.vultur@...rochip.com>,
	Steen Hegelund <steen.hegelund@...rochip.com>,
	Thomas Petazzoni <thomas.petazzoni@...tlin.com>
Subject: Re: [PATCH v4 1/6] driver core: Introduce
 device_{add,remove}_of_node()

On Wed, Dec 04, 2024 at 03:38:25PM -0600, Bjorn Helgaas wrote:
> [cc->to Greg, Rafael]
> 
> On Mon, Dec 02, 2024 at 02:15:13PM +0100, Herve Codina wrote:
> > An of_node can be set to a device using device_set_node().
> > This function cannot prevent any of_node and/or fwnode overwrites.
> > 
> > When adding an of_node on an already present device, the following
> > operations need to be done:
> > - Attach the of_node if no of_node were already attached
> > - Attach the of_node as a fwnode if no fwnode were already attached
> > 
> > This is the purpose of device_add_of_node().
> > device_remove_of_node() reverts the operations done by
> > device_add_of_node().
> > 
> > Signed-off-by: Herve Codina <herve.codina@...tlin.com>
> > ---
> >  drivers/base/core.c    | 52 ++++++++++++++++++++++++++++++++++++++++++
> >  include/linux/device.h |  2 ++
> 
> I suppose this series would go via the PCI tree since the bulk of the
> changes are there.  If so, I would look for an ack from the driver
> core folks (Greg, Rafael).
> 
> >  2 files changed, 54 insertions(+)
> > 
> > diff --git a/drivers/base/core.c b/drivers/base/core.c
> > index 8b056306f04e..3953c5ab7316 100644
> > --- a/drivers/base/core.c
> > +++ b/drivers/base/core.c
> > @@ -5216,6 +5216,58 @@ void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
> >  }
> >  EXPORT_SYMBOL_GPL(set_secondary_fwnode);
> >  
> > +/**
> > + * device_remove_of_node - Remove an of_node from a device
> > + * @dev: device whose device-tree node is being removed
> > + */
> > +void device_remove_of_node(struct device *dev)
> > +{
> > +	dev = get_device(dev);
> > +	if (!dev)
> > +		return;
> > +
> > +	if (!dev->of_node)
> > +		goto end;
> > +
> > +	if (dev->fwnode == of_fwnode_handle(dev->of_node))
> > +		dev->fwnode = NULL;
> > +
> > +	of_node_put(dev->of_node);
> > +	dev->of_node = NULL;
> > +
> > +end:
> > +	put_device(dev);
> > +}
> > +EXPORT_SYMBOL_GPL(device_remove_of_node);
> > +
> > +/**
> > + * device_add_of_node - Add an of_node to an existing device
> > + * @dev: device whose device-tree node is being added
> > + * @of_node: of_node to add
> > + */
> > +void device_add_of_node(struct device *dev, struct device_node *of_node)
> > +{
> > +	if (!of_node)
> > +		return;
> > +
> > +	dev = get_device(dev);
> > +	if (!dev)
> > +		return;
> > +
> > +	if (WARN(dev->of_node, "%s: Cannot replace node %pOF with %pOF\n",
> > +		 dev_name(dev), dev->of_node, of_node))
> > +		goto end;

Please do not reboot machines that have panic-on-warn for something that
you can properly handle and recover from (like this.)  Just print out a
message and continue on, or better yet, return an error if this didn't
work properly.

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ