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: <20250519163935.3e47ec04@bootlin.com>
Date: Mon, 19 May 2025 16:39:35 +0200
From: Herve Codina <herve.codina@...tlin.com>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Andrew Lunn <andrew@...n.ch>, Greg Kroah-Hartman
 <gregkh@...uxfoundation.org>, "Rafael J. Wysocki" <rafael@...nel.org>,
 Danilo Krummrich <dakr@...nel.org>, Shawn Guo <shawnguo@...nel.org>, Sascha
 Hauer <s.hauer@...gutronix.de>, Pengutronix Kernel Team
 <kernel@...gutronix.de>, Fabio Estevam <festevam@...il.com>, Michael
 Turquette <mturquette@...libre.com>, Stephen Boyd <sboyd@...nel.org>, Andi
 Shyti <andi.shyti@...nel.org>, Wolfram Sang
 <wsa+renesas@...g-engineering.com>, Peter Rosin <peda@...ntia.se>, Derek
 Kiernan <derek.kiernan@....com>, Dragan Cvetic <dragan.cvetic@....com>,
 Arnd Bergmann <arnd@...db.de>, Rob Herring <robh@...nel.org>, Saravana
 Kannan <saravanak@...gle.com>, Bjorn Helgaas <bhelgaas@...gle.com>, Mark
 Brown <broonie@...nel.org>, Len Brown <lenb@...nel.org>, Daniel Scally
 <djrscally@...il.com>, Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
 Sakari Ailus <sakari.ailus@...ux.intel.com>, Wolfram Sang <wsa@...nel.org>,
 Geert Uytterhoeven <geert+renesas@...der.be>, linux-kernel@...r.kernel.org,
 imx@...ts.linux.dev, linux-arm-kernel@...ts.infradead.org,
 linux-clk@...r.kernel.org, linux-i2c@...r.kernel.org,
 devicetree@...r.kernel.org, linux-pci@...r.kernel.org,
 linux-spi@...r.kernel.org, linux-acpi@...r.kernel.org, Allan Nielsen
 <allan.nielsen@...rochip.com>, Horatiu Vultur
 <horatiu.vultur@...rochip.com>, Steen Hegelund
 <steen.hegelund@...rochip.com>, Luca Ceresoli <luca.ceresoli@...tlin.com>,
 Thomas Petazzoni <thomas.petazzoni@...tlin.com>
Subject: Re: [PATCH v2 16/26] i2c: mux: Create missing devlink between mux
 and adapter physical device

Hi Andy,

On Thu, 8 May 2025 22:15:31 +0300
Andy Shevchenko <andriy.shevchenko@...ux.intel.com> wrote:

> On Wed, May 07, 2025 at 09:12:58AM +0200, Herve Codina wrote:
> > When removing an i2c controller device handling an i2c bus where an i2c
> > mux is connected to, the removal process hangs and is stuck in the
> > wait_completion() call done in i2c_del_adapter().
> > 
> > The i2c_del_adapter() tries to removed the i2c adapter related to the
> > i2c controller device and the wait_completion() is waiting for the i2c
> > adapter device release. This release is performed when the device is no
> > more used (i.e. refcount reaches zero).
> > 
> > When an i2c mux is involved in an i2c path, the struct dev topology is
> > the following:
> >     +----------------+                +-------------------+
> >     | i2c controller |                |      i2c mux      |
> >     |     device     |                |      device       |
> >     |       ^        |                |                   |
> >     |       |        |                |                   |
> >     |  dev's parent  |                |                   |
> >     |       |        |                |                   |
> >     |   i2c adapter  |                | i2c adapter chanX |
> >     |     device  <---- dev's parent ------  device       |
> >     |   (no driver)  |                |    (no driver)    |
> >     +----------------+                +-------------------+
> > 
> > When an i2c mux device creates an i2c adapter for its downstream
> > channel, a reference is taken to its adapter dev's parent. This parent
> > is the i2c mux upstream adapter device.
> > 
> > No relationship exists between the i2c mux device itself and the i2c
> > controller device (physical device) in order to have the i2c mux device
> > calling i2c_del_adapter() to remove its downtream adapters and so,
> > release references taken to the upstream adapter.
> > 
> > This consumer/supplier relationship is typically a devlink relationship.
> > 
> > Also, i2c muxes can be chained and so, the upstream adapter can be
> > supplied by either an i2c controller device or an other i2c mux device.
> > 
> > In order to get the physical device of the adapter a mux is connected
> > to, rely on the newly introduced i2c_adapter_get_physdev() and create
> > the missing devlink between the i2c mux device and the physical
> > device of the adapter the mux is connected to.
> > 
> > With that done, the i2c mux device is removed before the device
> > handling the upstream i2c adapter (i2c controller device or i2c mux
> > device). All references are released and the i2c_del_adapter() call
> > performed by driver handling the upstream adapter device is not blocking
> > anymore.  
> 
> ...
> 
> > +	/*
> > +	 * There is no relationship set between the mux device and the physical
> > +	 * device handling the parent adapter. Create this missing relationship
> > +	 * in order to remove the i2c mux device (consumer) and so the dowstream
> > +	 * channel adapters before removing the physical device (supplier) which
> > +	 * handles the i2c mux upstream adapter.
> > +	 */
> > +	parent_physdev = i2c_get_adapter_physdev(parent);
> > +	dl = device_link_add(muxc->dev, parent_physdev, DL_FLAG_AUTOREMOVE_CONSUMER);
> > +	if (!dl) {
> > +		dev_err(muxc->dev, "failed to create device link to %s\n",
> > +			dev_name(parent_physdev));
> > +		put_device(parent_physdev);
> > +		ret = -EINVAL;
> > +		goto err_free_priv;
> > +	}
> > +	put_device(parent_physdev);  
> 
> Since you are not checking parent_physdev for NULL, the dev_name() can print a
> "(null)" string. Is this by design?

It is worse than that. If parent_physdev is NULL, dev_name() can crash.

I will fix that and check parent_physdev for NULL in the next iteration.

Best regards,
Hervé

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ