Linux ACPI
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Cesar Cibrian <cesarcibrian.ai@gmail.com>,
	Lee Jones <lee@kernel.org>,
	 mfd@lists.linux.dev,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	 linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org,  Danilo Krummrich <dakr@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	 Johan Hovold <johan@kernel.org>
Subject: Re: [PATCH] mfd: core: Remove software node after unregistering platform device
Date: Fri, 4 Dec 2026 12:27:08 -0800	[thread overview]
Message-ID: <axMh5IiENa75aWem@google.com> (raw)
In-Reply-To: <axMgrE_z6sGNbMg2@ashevche-desk.local>

On Fri, Dec 04, 2026 at 10:21:00PM +0200, Andy Shevchenko wrote:
> On Fri, Dec 04, 2026 at 12:12:00PM -0800, Dmitry Torokhov wrote:
> > On Fri, Dec 04, 2026 at 09:47:14PM +0200, Andy Shevchenko wrote:
> > > On Fri, Dec 04, 2026 at 10:16:05AM -0800, Cesar Cibrian wrote:
> > > > mfd_add_device() attaches cell->swnode before calling
> > > > platform_device_add(), but mfd_remove_devices_fn() calls
> > > > device_remove_software_node() before platform_device_unregister().
> > > >
> > > > If the child driver propagates dev_fwnode() to a sub-device (for
> > > > example, i2c-designware sharing its fwnode with the i2c_adapter
> > > > device on Intel LPSS), removing the software node first clears
> > > > fwnode->secondary while the sub-device is still registered. When
> > > > platform_device_unregister() subsequently tears down the child,
> > > > software_node_notify_remove() sees dev_to_swnode() == NULL on the
> > > > sub-device and skips cleanup, leaking a swnode reference and
> > > > leaving a stale sysfs symlink that triggers a warning on rebind:
> > > >
> > > > sysfs: cannot create duplicate filename '/kernel/software_nodes/node0/i2c-0'
> > > >
> > > > Move device_remove_software_node() after platform_device_unregister()
> > > > (device_for_each_child_reverse() holds a reference on dev throughout
> > > > mfd_remove_devices_fn()). Because acpi_unbind_one() calls
> > > > set_primary_fwnode(dev, NULL), which skips clearing fn->secondary
> > > > when fn == dev->parent->fwnode, also clear the parent's secondary
> > > > fwnode when the child shared its parent's fwnode so rebinding does
> > > > not fail with -EBUSY.
> > >
> > > I believe it's a local hack against bigger issue which is discussed here
> > > https://lore.kernel.org/lkml/20261202-swnode-shared-primary-fix-v1-0-7ff23caaa1ed@gmail.com/
> > >
> > > I Cc'ed people from that thread. Meanwhile, can you test the proposed series
> > > and confirm if it fixes your issue or not?
> 
> Dmitry, thanks for chiming in!
> 
> > My series will not fix this on its own. We still need to reorder
> > software node removal so it stays intact while child devices are being
> > torn down.
> > 
> > What my series does fix is the shared_fwnode/set_secondary_fwnode()
> > workaround in this patch. Once device_del() unbinds the driver first and
> > tears down i2c_adapter while the secondary link is intact,
> > set_primary_fwnode(&pdev->dev, NULL) sees that pdev->dev attached the
> > secondary node, moves it onto pdev->dev.fwnode, and clears fn->secondary
> > automatically.
> > 
> > Also, on non-ACPI shared primary nodes where acpi_unbind_one() does not
> > run, clearing dev->parent's secondary fwnode before calling
> > device_remove_software_node(&pdev->dev) makes dev_to_swnode(&pdev->dev)
> > return NULL and actually leaks cell->swnode's reference.
> 
> Hmm... Does it mean that your series fixes the issue on non-ACPI cases as well?

I was trying to say that I think Cesar's patch introduces a leak on
non-ACPI systems...

> 
> Cesar, based on Dmitry's answer can you apply his series and develop the
> missing piece on top?
> 

Thanks.

-- 
Dmitry

  reply	other threads:[~2026-12-04 20:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:16 [PATCH] mfd: core: Remove software node after unregistering platform device Cesar Cibrian
2026-12-04 19:47 ` Andy Shevchenko
2026-12-04 20:12   ` Dmitry Torokhov
2026-12-04 20:21     ` Andy Shevchenko
2026-12-04 20:27       ` Dmitry Torokhov [this message]
2026-12-04 22:29         ` Julio Cesar Martinez Cibrian
2026-12-04 22:34           ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axMh5IiENa75aWem@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=brgl@kernel.org \
    --cc=cesarcibrian.ai@gmail.com \
    --cc=dakr@kernel.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=johan@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mfd@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox