Skip to content

Commit 50030d6

Browse files
brglDanilo Krummrich
authored andcommitted
driver core: platform: remove software node on release()
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 fail with -EBUSY. Provide a wrapper around the existing platform_device_release() that additionally calls device_remove_software_node() and use it to replace the former if we end up adding a software node. While at it: check all three possible situations in which two software nodes for a single platform device can be created/assigned in platform_device_register_full() and bail-out early. Fixes: 0fc434b ("driver core: platform: allow attaching software nodes when creating devices") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> Link: https://patch.msgid.link/20260513-swnode-remove-on-dev-unreg-v6-1-f9c58939df27@oss.qualcomm.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent 254f496 commit 50030d6

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

drivers/base/platform.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,12 @@ static void platform_device_release(struct device *dev)
606606
kfree(pa);
607607
}
608608

609+
static void platform_device_release_full(struct device *dev)
610+
{
611+
device_remove_software_node(dev);
612+
platform_device_release(dev);
613+
}
614+
609615
/**
610616
* platform_device_alloc - create a platform device
611617
* @name: base name of the device we're adding
@@ -848,7 +854,13 @@ struct platform_device *platform_device_register_full(const struct platform_devi
848854
int ret;
849855
struct platform_device *pdev;
850856

851-
if (pdevinfo->swnode && pdevinfo->properties)
857+
/*
858+
* Only one software node per device is allowed. Make sure we don't
859+
* accept or create two.
860+
*/
861+
if ((pdevinfo->swnode && pdevinfo->properties) ||
862+
(pdevinfo->swnode && is_software_node(pdevinfo->fwnode)) ||
863+
(pdevinfo->properties && is_software_node(pdevinfo->fwnode)))
852864
return ERR_PTR(-EINVAL);
853865

854866
pdev = platform_device_alloc(pdevinfo->name, pdevinfo->id);
@@ -878,6 +890,8 @@ struct platform_device *platform_device_register_full(const struct platform_devi
878890
ret = device_add_software_node(&pdev->dev, pdevinfo->swnode);
879891
if (ret)
880892
goto err;
893+
894+
pdev->dev.release = platform_device_release_full;
881895
} else if (pdevinfo->properties) {
882896
ret = device_create_managed_software_node(&pdev->dev,
883897
pdevinfo->properties, NULL);

0 commit comments

Comments
 (0)