Skip to content

Commit c8561c7

Browse files
committed
Merge tag 'driver-core-7.1-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core
Pull driver core fixes from Danilo Krummrich: - Remove the software node on platform device release(); without this, the software node remains registered after the device is gone and a subsequent platform_device_register_full() reusing the same node fails with -EBUSY - In sysfs_update_group(), do not remove a pre-existing directory when create_files() fails; the previous code would silently destroy a sysfs group that the caller did not create - Set fwnode->secondary to NULL in fwnode_init() to avoid dereferencing uninitialized memory (e.g. in dev_to_swnode()) when the firmware node is allocated on the stack or via a non-zeroing allocator * tag 'driver-core-7.1-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core: device property: set fwnode->secondary to NULL in fwnode_init() sysfs: don't remove existing directory on update failure driver core: platform: remove software node on release()
2 parents 3f26465 + 215c90e commit c8561c7

3 files changed

Lines changed: 17 additions & 2 deletions

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);

fs/sysfs/group.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static int internal_create_group(struct kobject *kobj, int update,
188188
kernfs_get(kn);
189189
error = create_files(kn, kobj, uid, gid, grp, update);
190190
if (error) {
191-
if (grp->name)
191+
if (grp->name && !update)
192192
kernfs_remove(kn);
193193
}
194194
kernfs_put(kn);

include/linux/fwnode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ struct fwnode_operations {
208208
static inline void fwnode_init(struct fwnode_handle *fwnode,
209209
const struct fwnode_operations *ops)
210210
{
211+
fwnode->secondary = NULL;
211212
fwnode->ops = ops;
212213
INIT_LIST_HEAD(&fwnode->consumers);
213214
INIT_LIST_HEAD(&fwnode->suppliers);

0 commit comments

Comments
 (0)