ibmebus: fix device reference leaks in sysfs interface
PATCH 1/4 ibmebus: fix device reference leaks in sysfs interface
Make sure to drop any reference taken by bus_find_device() in the sysfs callbacks that are used to create and destroy devices based on device-tree entries.
--- arch/powerpc/kernel/ibmebus.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/kernel/ibmebus.c +6 -2
@@ -262,6 +262,7 @@ static ssize_t ibmebus_store_probe(struct bus_type *bus, const char *buf, size_t count) {struct device_node *dn =NULL ; +struct device *dev;char *path;ssize_t rc =0 ;
@@ -269,8 +270,10 @@ static ssize_t ibmebus_store_probe(struct bus_type *bus,if (!path)return -ENOMEM ; -if (bus_find_device (&ibmebus_bus_type,NULL , path, - ibmebus_match_path)) { + dev =bus_find_device (&ibmebus_bus_type,NULL , path, + ibmebus_match_path); +if (dev) { +put_device (dev);printk (KERN_WARNING "%s: %s has already been probed\n" , __func__, path); rc = -EEXIST ;
@@ -307,6 +310,7 @@ static ssize_t ibmebus_store_remove(struct bus_type *bus,if ((dev =bus_find_device (&ibmebus_bus_type,NULL , path, ibmebus_match_path))) {of_device_unregister (to_platform_device (dev)); +put_device (dev);kfree (path);return count;
Signature · 1 line
2.7.3
PATCH 2/4 ibmebus: fix further device reference leaks
Make sure to drop any reference taken by bus_find_device() when creating devices during init and driver registration.
--- arch/powerpc/kernel/ibmebus.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/kernel/ibmebus.c +6 -2
@@ -180,6 +180,7 @@ static int ibmebus_create_device(struct device_node *dn)static int ibmebus_create_devices (const struct of_device_id *matches) {struct device_node *root, *child; +struct device *dev;int ret =0 ; root =of_find_node_by_path ("/" );
@@ -188,9 +189,12 @@ static int ibmebus_create_devices(const struct of_device_id *matches)if (!of_match_node (matches, child))continue ; -if (bus_find_device (&ibmebus_bus_type,NULL , child, - ibmebus_match_node)) + dev =bus_find_device (&ibmebus_bus_type,NULL , child, + ibmebus_match_node); +if (dev) { +put_device (dev);continue ; + } ret =ibmebus_create_device (child);if (ret) {
Signature · 1 line
2.7.3
Michael Ellerman
AppliedRe: [2/4] ibmebus: fix further device reference leaks
Quoted 5 lines · Johan Hovold
Make sure to drop any reference taken by
bus_find_device()when creating devices during init and driver registration.Fixes 55347cc9962f ("[POWERPC] ibmebus: Add device creation...)Signed-off-by Johan Hovold <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/815a7141c4d1b11610dccb7fcbb386
cheers
PATCH 3/4 powerpc/vio: clarify vio_find_node reference counting
In reply to Johan HovoldAdd comment clarifying that vio_find_node() takes a reference to the embedded struct device which needs to be dropped after use.
--- arch/powerpc/kernel/vio.c | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/kernel/vio.c +3 -0
@@ -1648,6 +1648,9 @@ static struct vio_dev *vio_find_name(const char *name)/** * vio_find_node - find an already-registered vio_dev * @vnode: device_node of the virtual device we're looking for +* +* Takes a reference to the embedded struct device which needs to be dropped +* after use. */ struct vio_dev *vio_find_node (struct device_node *vnode) {
Signature · 1 line
2.7.3
Michael Ellerman
AppliedRe: [3/4] powerpc/vio: clarify vio_find_node reference counting
Quoted 4 lines · Johan Hovold
Add comment clarifying that
vio_find_node()takes a reference to the embedded struct device which needs to be dropped after use.Signed-off-by Johan Hovold <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/e8cfb7e7c3b2be8a4c2241b5da2ae6
cheers
PATCH 4/4 powerpc/pci: fix device reference leaks
In reply to Johan HovoldMake sure to drop any device reference taken by vio_find_node() when adding and removing virtual I/O slots.
--- drivers/pci/hotplug/rpadlpar_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/pci/hotplug/rpadlpar_core.c +9 -1
@@ -257,8 +257,13 @@ static int dlpar_add_phb(char *drc_name, struct device_node *dn)static int dlpar_add_vio_slot (char *drc_name,struct device_node *dn) { -if (vio_find_node (dn)) +struct vio_dev *vio_dev; + + vio_dev =vio_find_node (dn); +if (vio_dev) { +put_device (&vio_dev->dev);return -EINVAL ; + }if (!vio_register_device_node (dn)) { printk(KERN_ERR
@@ -334,6 +339,9 @@ static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn)return -EINVAL ;vio_unregister_device (vio_dev); + +put_device (&vio_dev->dev); +return 0 ; }
Signature · 1 line
2.7.3
Michael Ellerman
AppliedRe: [4/4] powerpc/pci: fix device reference leaks
Quoted 5 lines · Johan Hovold
Make sure to drop any device reference taken by
vio_find_node()when adding and removing virtual I/O slots.Fixes 5eeb8c63a38f ("[PATCH] PCI Hotplug: rpaphp: Move VIO...")Signed-off-by Johan Hovold <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/99e5cde5eae78bef95bfe7c16ccda8
cheers
Michael Ellerman
AppliedQuoted 6 lines · Johan Hovold
Make sure to drop any reference taken by
bus_find_device()in the sysfs callbacks that are used to create and destroy devices based on device-tree entries.Fixes 6bccf755ff53 ("[POWERPC] ibmebus: dynamic addition/removal...)Signed-off-by Johan Hovold <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/fe0f3168169f7c34c29b0cf0c489f1
cheers