Re: [PATCH 1/2] driver core: platform: remove software node on release()

From: Bartosz Golaszewski

Date: Tue Apr 21 2026 - 04:45:36 EST


On Mon, Apr 13, 2026 at 5:56 AM Dmitry Torokhov
<dmitry.torokhov@xxxxxxxxx> wrote:
>
> Hi Bartosz,
>
> On Fri, Apr 10, 2026 at 01:50:45PM +0200, Bartosz Golaszewski wrote:
> > If we pass a software node to a newly created device using struct
> > platform_device_info, it will not be removed when the device is
> > released. This may happen when a module creating the device is removed
> > or on failure in platform_device_add().
> >
> > When we try to reuse that software node in a subsequent call to
> > platform_device_register_full(), it will fails with -EBUSY. Add the
> > missing call to device_remove_software_node() in release path.
>
> Thank you for spotting this, but I do not believe the patch is correct
> as it stands. We need to differentiate between nodes registered by
> platform devices vs nodes that already registered where we simply use
> them.
>

We already do: platform_device_release() is only set for devices
dynamically allocated with platform_device_alloc() which is what
happens in platform_device_register_full(). platform_device_alloc()
already imposes limitations on the caller - like having to provide
platform data that can be shallow-copied as platform_device_release()
calls kfree() on it unconditionally. Even if the user adds the
software node manually, it needs to be removed.

> I think we need to mark nodes that platform_device_register_full()
> registers form swnodes as "managed = true" so that they are cleaned up
> properly.
>
> See also sashiko feedback.
>
> https://sashiko.dev/#/patchset/20260410-swnode-remove-on-dev-unreg-v1-0-cd7d305f3db2%40oss.qualcomm.com
>

I'll see about reproducing it and possibly adding a kunit test-case as well.

Bart