sh: dma-sysfs: add missing put_device call
Subsystems (22)
PATCH 1/38 sh: dma-sysfs: add missing put_device call
This is required so that we give up the last reference to the device.
--- arch/sh/drivers/dma/dma-sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/sh/drivers/dma/dma-sysfs.c +3 -1
@@ -131,8 +131,10 @@ int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info) dev->bus = &dma_subsys; ret =device_register (dev); -if (ret) +if (ret) { +put_device (dev);return ret; + } ret |=device_create_file (dev, &dev_attr_dev_id); ret |=device_create_file (dev, &dev_attr_count);
Signature · 1 line
1.8.3.1
PATCH 2/38 powerpc: qe_lib: add missing put_device call
This is required so that we give up the last reference to the device.
--- arch/powerpc/sysdev/qe_lib/qe_ic.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/sysdev/qe_lib/qe_ic.c +1 -0
@@ -493,6 +493,7 @@ static int __init init_qe_ic_sysfs(void) rc =device_register (&device_qe_ic);if (rc) {printk (KERN_ERR "Failed registering qe_ic sys device\n" ); +put_device (&device_qe_ic);return -ENODEV ; }return 0 ;
Signature · 1 line
1.8.3.1
PATCH 3/38 powerpc: cell: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- arch/powerpc/platforms/cell/spu_base.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/platforms/cell/spu_base.c +1 -0
@@ -597,6 +597,7 @@ static int spu_create_dev(struct spu *spu)if (ret) {printk (KERN_ERR "Can't register SPU %d with sysfs\n" , spu->number); +put_device (&spu->dev);return ret; }
Signature · 1 line
1.8.3.1
PATCH 4/38 powerpc: kernel: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- arch/powerpc/kernel/vio.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/kernel/vio.c +1 -0
@@ -1494,6 +1494,7 @@ static int __init vio_bus_init(void)if (err) {printk (KERN_WARNING "%s: device_register returned %i\n" , __func__, err); +put_device (&vio_bus_device.dev);return err; }
Signature · 1 line
1.8.3.1
PATCH 5/38 sparc: kernel: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device. The kfree() has been removed because put_device will set the underlying kref's reference count to zero and hence vio_dev_release will get called resulting in kfreeing the structure.
--- arch/sparc/kernel/vio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/kernel/vio.c +1 -1
@@ -307,7 +307,7 @@ static struct vio_dev *vio_create_one(struct mdesc_handle *hp, u64 mp,if (err) {printk (KERN_ERR "VIO: Could not register device %s, err=%d\n" ,dev_name (&vdev->dev), err); -kfree (vdev); +put_device (&vdev->dev);return NULL ; }if (vdev->dp)
Signature · 1 line
1.8.3.1
David Miller
maintainerRe: [PATCH 05/38] sparc: kernel: add missing put_device call
From: Levente Kurusa <[email protected]>
Date: Thu, 19 Dec 2013 16:03:16 +0100
Quoted 6 lines
This is required so that we give up the last reference to the device. The
kfree()has been removed becauseput_devicewill set the underlying kref's reference count to zero and hencevio_dev_releasewill get called resulting in kfreeing the structure.Signed-off-by Levente Kurusa <[email protected]>
There is no reference held to vdev->dev at this point, that's why we should directly kfree() it and put_device() is not appropriate.
Pretty much all of your patches have this problem.
PATCH 6/38 arm: mach-s3c64: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- arch/arm/mach-s3c64xx/dma.c | 1 + 1 file changed, 1 insertion(+)
arch/arm/mach-s3c64xx/dma.c +1 -0
@@ -663,6 +663,7 @@ static int s3c64xx_dma_init1(int chno, enum dma_ch chbase, err =device_register (&dmac->dev);if (err) {printk (KERN_ERR "%s: failed to register device\n" , __func__); +put_device (&dmac->dev); goto err_alloc; }
Signature · 1 line
1.8.3.1
PATCH 7/38 arm: locomo: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
Also, rework error path to remove the out label by return -ENOMEM explicitly if kzalloc fails.
--- arch/arm/common/locomo.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
arch/arm/common/locomo.c +3 -6
@@ -224,10 +224,8 @@ locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)int ret; dev =kzalloc (sizeof (struct locomo_dev ),GFP_KERNEL ); -if (!dev) { - ret = -ENOMEM ; - goto out; - } +if (!dev) +return -ENOMEM ;/* * If the parent device has a DMA mask associated with it,
@@ -256,8 +254,7 @@ locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info) ret =device_register (&dev->dev);if (ret) { - out: -kfree (dev); +put_device (&dev->dev); }return ret; }
Signature · 1 line
1.8.3.1
PATCH 8/38 arm: mach-rpc: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- arch/arm/mach-rpc/ecard.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/mach-rpc/ecard.c +3 -1
@@ -961,8 +961,10 @@ static int __init ecard_probe(int slot, unsigned irq, card_type_t type) slot_to_expcard[slot] = ec; rc =device_register (&ec->dev); -if (rc) +if (rc) { +put_device (&ec->dev); goto nodev; + }return 0 ;
Signature · 1 line
1.8.3.1
PATCH 9/38 arm: mach-imx: add missing put_device calls
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- arch/arm/mach-imx/devices/devices.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/arm/mach-imx/devices/devices.c +5 -2
@@ -37,11 +37,14 @@ int __init mxc_device_init(void)int ret; ret =device_register (&mxc_aips_bus); -if (ret <0 ) +if (ret <0 ) { +put_device (&mxc_aips_bus); goto done; + } ret =device_register (&mxc_ahb_bus); - +if (ret <0 ) +put_device (&mxc_ahb_bus); done:return ret; }
Signature · 1 line
1.8.3.1
PATCH 10/38 arm: exynos: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- arch/arm/mach-exynos/common.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm/mach-exynos/common.c +7 -1
@@ -407,7 +407,13 @@ early_initcall(exynos4_l2x0_cache_init);static int __init exynos_init (void ) { +int rc =0 ; +printk (KERN_INFO "EXYNOS: Initializing architecture\n" ); -return device_register (&exynos4_dev); + rc =device_register (&exynos4_dev); +if (rc) +put_device (&exynos4_dev); + +return rc; }
Signature · 1 line
1.8.3.1
PATCH 11/38 arm: mach-integrator: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device. Calling put_device on the failed device will allow lm_device_release to be called which will kfree() the struct lm_device.
--- arch/arm/mach-integrator/lm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/mach-integrator/lm.c +3 -1
@@ -89,8 +89,10 @@ int lm_device_register(struct lm_device *dev) ret =request_resource (&iomem_resource, &dev->resource);if (ret ==0 ) { ret =device_register (&dev->dev); -if (ret) +if (ret) {release_resource (&dev->resource); +put_device (&dev->dev); + } }return ret; }
Signature · 1 line
1.8.3.1
PATCH 12/38 arm: s5pv210: add missing put_device call
In reply to Levente KurusaThis is required so that give up the last reference to the device.
--- arch/arm/mach-s5pv210/common.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm/mach-s5pv210/common.c +7 -1
@@ -267,8 +267,14 @@ core_initcall(s5pv210_core_init);int __init s5pv210_init (void ) { +int rc =0 ; +printk (KERN_INFO "S5PV210: Initializing architecture\n" ); -return device_register (&s5pv210_dev); + rc =device_register (&s5pv210_dev); +if (rc) +put_device (&s5pv210_dev); + +return rc; }/* uart registration process */
Signature · 1 line
1.8.3.1
PATCH 13/38 arm: s390: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- arch/s390/kernel/time.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/s390/kernel/time.c +3 -1
@@ -1351,8 +1351,10 @@ static int __init etr_register_port(struct device *dev)int rc; rc =device_register (dev); -if (rc) +if (rc) { +put_device (dev); goto out; + }for (attr = etr_port_attributes; *attr; attr++) { rc =device_create_file (dev, *attr);if (rc)
Signature · 1 line
1.8.3.1
PATCH 14/38 mips: txx9: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
Also, rework error path so that it is easier to read.
--- arch/mips/txx9/generic/setup.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
arch/mips/txx9/generic/setup.c +17 -10
@@ -937,6 +937,12 @@ static ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj,return size; } +void txx9_device_release (struct device *dev) { +struct txx9_sramc_dev *sramc_dev; + txx9_sramc_dev = container_of(dev, struct txx9_sramc_dev, dev); +kfree (txx9_sramc_dev); +} +void __init txx9_sramc_init (struct resource *r) {struct txx9_sramc_dev *dev;
@@ -951,8 +957,11 @@ void __init txx9_sramc_init(struct resource *r)return ; size =resource_size (r); dev->base =ioremap (r->start, size); -if (!dev->base) - goto exit; +if (!dev->base) { +kfree (dev); +return ; + } + dev->dev.release = &txx9_device_release; dev->dev.bus = &txx9_sramc_subsys;sysfs_bin_attr_init (&dev->bindata_attr); dev->bindata_attr.attr.name ="bindata" ;
@@ -963,17 +972,15 @@ void __init txx9_sramc_init(struct resource *r) dev->bindata_attr.private = dev; err =device_register (&dev->dev);if (err) - goto exit; + goto exit_put; err =sysfs_create_bin_file (&dev->dev.kobj, &dev->bindata_attr);if (err) {device_unregister (&dev->dev); - goto exit; - } -return ; -exit: -if (dev) { -if (dev->base) -iounmap (dev->base); +iounmap (dev->base);kfree (dev); } +return ; +exit_put: +put_device (&dev->dev); +return ; }
Signature · 1 line
1.8.3.1
PATCH 15/38 mips: txx9: 7segled: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
Also, add a new tx_7segled_release function which will be called after the put_device to ensure that device is kfree'd.
--- arch/mips/txx9/generic/7segled.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
arch/mips/txx9/generic/7segled.c +10 -3
@@ -83,6 +83,10 @@ static struct bus_type tx_7segled_subsys = { .dev_name = "7segled", }; +void tx_7segled_release (struct device *dev) { +kfree (dev); +} +static int __init tx_7segled_init_sysfs (void ) {int error, i;
@@ -103,11 +107,14 @@ static int __init tx_7segled_init_sysfs(void) } dev->id = i; dev->bus = &tx_7segled_subsys; + dev->release = &tx_7segled_release; error =device_register (dev); -if (!error) { -device_create_file (dev, &dev_attr_ascii); -device_create_file (dev, &dev_attr_raw); +if (error) { +put_device (dev); +return error; } +device_create_file (dev, &dev_attr_ascii); +device_create_file (dev, &dev_attr_raw); }return error; }
Signature · 1 line
1.8.3.1
PATCH 16/38 mips: sgi-ip22: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
Also, create a gio_bus_release() that calls kfree on the device argument to properly kfree() the memory allocated for the device.
--- arch/mips/sgi-ip22/ip22-gio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arch/mips/sgi-ip22/ip22-gio.c +8 -1
@@ -24,8 +24,13 @@ static struct { { .name = "SGI GR2/GR3", .id = 0x7f }, }; +void gio_bus_release (struct device *dev) { +kfree (dev); +} +static struct device gio_bus = { .init_name ="gio" , + .release = &gio_bus_release, };/**
@@ -400,8 +405,10 @@ int __init ip22_gio_init(void)int ret; ret =device_register (&gio_bus); -if (ret) +if (ret) { +put_device (&gio_bus);return ret; + } ret =bus_register (&gio_bus_type);if (!ret) {
Signature · 1 line
1.8.3.1
PATCH 17/38 parisc: kernel: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- arch/parisc/kernel/drivers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/drivers.c +1 -1
@@ -428,7 +428,7 @@ struct parisc_device * create_tree_node(char id, struct device *parent) dev->dev.dma_mask = &dev->dma_mask; dev->dev.coherent_dma_mask = dev->dma_mask;if (device_register (&dev->dev)) { -kfree (dev); +put_device (&dev->dev);return NULL ; }
Signature · 1 line
1.8.3.1
James Bottomley
maintainerRe: [PATCH 17/38] parisc: kernel: add missing put_device call
Quoted 1 line · Levente Kurusa
This is required so that we give up the last reference to the device.
No, it's not. And the subject is misleading at best, since this isn't any form of problem in the code.
If the add fails, the device isn't visible in sysfs and no references have been handed out. We're perfectly entitled to follow the common pattern of simply destroying it at this point rather than going through the nascent refcounting.
James
PATCH 18/38 ia64: kernel: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device. Removed kfree() as put_device() will result in tiocx_bus_release called.
--- arch/ia64/sn/kernel/tiocx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/sn/kernel/tiocx.c +1 -1
@@ -209,7 +209,7 @@ cx_device_register(nasid_t nasid, int part_num, int mfg_num,dev_set_name (&cx_dev->dev,"%d" , cx_dev->cx_id.nasid); r =device_register (&cx_dev->dev);if (r) { -kfree (cx_dev); +put_device (&cx_dev->dev);return r; }get_device (&cx_dev->dev);
Signature · 1 line
1.8.3.1
PATCH 19/38 net: atm: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- net/atm/atm_sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/atm/atm_sysfs.c +3 -1
@@ -154,8 +154,10 @@ int atm_register_sysfs(struct atm_dev *adev, struct device *parent)dev_set_name (cdev,"%s%d" , adev->type, adev->number); err =device_register (cdev); -if (err <0 ) +if (err <0 ) { +put_device (cdev);return err; + }for (i =0 ; atm_attrs[i]; i++) { err =device_create_file (cdev, atm_attrs[i]);
Signature · 1 line
1.8.3.1
David Miller
maintainerRe: [PATCH 19/38] net: atm: add missing put_device call
From: Levente Kurusa <[email protected]>
Date: Thu, 19 Dec 2013 16:03:30 +0100
Quoted 3 lines
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>
...
net/atm/atm_sysfs.c int atm_register_sysfs(struct atm_dev *adev, struct device *parent) · line 160
Quoted 9 lines
net/atm/atm_sysfs.c +3
-1@@ -154,8 +154,10 @@ int atm_register_sysfs(struct atm_dev *adev, struct device *parent)dev_set_name (cdev,"%s%d" , adev->type, adev->number); err =device_register (cdev); -if (err <0 ) +if (err <0 ) { +put_device (cdev);return err; + }
This doesn't make any sense.
Nothing has a reference to 'cdev'. Yes, 'adev' has a reference, acquired by the caller of this function, but that's not what we're working with here.
PATCH 20/38 net: iucv: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- net/iucv/af_iucv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/iucv/af_iucv.c +3 -1
@@ -2377,8 +2377,10 @@ static int afiucv_iucv_init(void) af_iucv_dev->release = (void (*)(struct device *))kfree; af_iucv_dev->driver = &af_iucv_driver; err =device_register (af_iucv_dev); -if (err) +if (err) { +put_device (af_iucv_dev); goto out_driver; + }return 0 ; out_driver:
Signature · 1 line
1.8.3.1
David Miller
maintainerRe: [PATCH 20/38] net: iucv: add missing put_device call
From: Levente Kurusa <[email protected]>
Date: Thu, 19 Dec 2013 16:03:31 +0100
Quoted 3 lines
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>
...
net/iucv/af_iucv.c static int afiucv_iucv_init(void) · line 2383
Quoted 9 lines
net/iucv/af_iucv.c +3
-1@@ -2377,8 +2377,10 @@ static int afiucv_iucv_init(void) af_iucv_dev->release = (void (*)(struct device *))kfree; af_iucv_dev->driver = &af_iucv_driver; err =device_register (af_iucv_dev); -if (err) +if (err) { +put_device (af_iucv_dev); goto out_driver; + }
This has the same problem as the ATM patch, there is no reference held on af_iucv_dev, I mean look at where it comes from:
af_iucv_dev = kzalloc(sizeof(struct device), GFP_KERNEL); ... dev_set_name(af_iucv_dev, "af_iucv"); af_iucv_dev->bus = pr_iucv->bus; af_iucv_dev->parent = pr_iucv->root; af_iucv_dev->release = (void (*)(struct device *))kfree; af_iucv_dev->driver = &af_iucv_driver;
No reference count is incremented or set to one for af_iucv_dev.
Please study these code paths more carefully, thank you.
PATCH 21/38 workqueue: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device. Remove the kfree() as that is the job of wq_device_release which will now be called due to the reference count actually reaching zero.
--- kernel/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/workqueue.c +1 -1
@@ -3361,7 +3361,7 @@ int workqueue_sysfs_register(struct workqueue_struct *wq) ret =device_register (&wq_dev->dev);if (ret) { -kfree (wq_dev); +put_device (&wq_dev->dev); wq->wq_dev =NULL ;return ret; }
Signature · 1 line
1.8.3.1
Re: [PATCH 21/38] workqueue: add missing put_device call
Quoted 14 lines · Levente Kurusa
This is required so that we give up the last reference to the device. Remove the
kfree()as that is the job ofwq_device_releasewhich will now be called due to the reference count actually reaching zero.Signed-off-by Levente Kurusa <[email protected]>--- kernel/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/workqueue.c +0
-0
kernel/workqueue.c int workqueue_sysfs_register(struct workqueue_struct *wq) · line 3364
Quoted 5 lines
kernel/workqueue.c +1
-1@@ -3361,7 +3361,7 @@ int workqueue_sysfs_register(struct workqueue_struct *wq) ret =device_register (&wq_dev->dev);if (ret) { -kfree (wq_dev); +put_device (&wq_dev->dev);
Umm... this doesn't look right. You're basically converting the code to the following,
x = kmalloc(); if (register(x) < 0) put(x)
They're not symmetrical anymore. register(), or any API call really, isn't supposed to have side effects which need explicit cleanup after a failure. The fact that x is properly initialized even after register(x) failed is a coincidental implementation detail which shouldn't be depended upon. Your patch is actively breaking the convention for no good reason.
Quoted 1 line
From the patch title, I suppose you posted a bunch of patches towards
this direction. Please consider all of them nacked if they're doing the same thing.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 21/38] workqueue: add missing put_device call
Quoted 14 lines · Tejun Heo
Umm... this doesn't look right. You're basically converting the code to the following,
x = kmalloc(); if (register(x) < 0) put(x)They're not symmetrical anymore.
register(), or any API call really, isn't supposed to have side effects which need explicit cleanup after a failure. The fact that x is properly initialized even after register(x) failed is a coincidental implementation detail which shouldn't be depended upon. Your patch is actively breaking the convention for no good reason.
Quoted 8 lines
Nacked-by Tejun Heo <[email protected]>Quoted 1 line
From the patch title, I suppose you posted a bunch of patches towards
this direction. Please consider all of them nacked if they're doing the same thing.
Thanks.
The reason I removed the kfree() was because the put_device() will decrement wq_dev->dev's reference count to zero (it is set to one by device_register) and hence the wq_device_release() will be called. Now, this effectively does the same the kfree() call would have done but also driver core is notified.
Also, if you take a look at the comment for the device_register() function, it explicitly says NOT to kfree the struct device, but instead call put_device() and let the device's release() function take care.
Signature · 2 lines
Regards, Levente Kurusa
Tejun Heo
maintainerRe: [PATCH 21/38] workqueue: add missing put_device call
Hello,
Quoted 4 lines · Levente Kurusa
The reason I removed the
kfree()was because theput_device()will decrement wq_dev->dev's reference count to zero (it is set to one bydevice_register) and hence thewq_device_release()will be called. Now, this effectively does the same thekfree()call would have done but also driver core is notified.
Yeah, I know it does the same thing. It's just not the right way to do it.
Quoted 3 lines
Also, if you take a look at the comment for the
device_register()function, it explicitly says NOT to kfree the struct device, but instead callput_device()and let the device'srelease()function take care.
Greg, the API as described by the comment is really weird and unconventional. Failed calls are not supposed to have side effects which require explicit cleanup. Can we please update the comment?
Thanks.
Signature · 1 line
tejun
Re: [PATCH 21/38] workqueue: add missing put_device call
[+Cc Greg]
Quoted 10 lines · Tejun Heo
Hello,
Quoted 4 lines · Levente Kurusa
The reason I removed the
kfree()was because theput_device()will decrement wq_dev->dev's reference count to zero (it is set to one bydevice_register) and hence thewq_device_release()will be called. Now, this effectively does the same thekfree()call would have done but also driver core is notified.Yeah, I know it does the same thing. It's just not the right way to do it.
Quoted 8 lines
Quoted 3 lines
Also, if you take a look at the comment for the
device_register()function, it explicitly says NOT to kfree the struct device, but instead callput_device()and let the device'srelease()function take care.Greg, the API as described by the comment is really weird and unconventional. Failed calls are not supposed to have side effects which require explicit cleanup. Can we please update the comment?
Yes, it was already discussed that it would be more sane to have device_register() call put_device() if it would fail, but Greg said that the API was designed so that no kfree()s happen in the core.
Signature · 2 lines
Regards, Levente Kurusa
Tejun Heo
maintainerRe: [PATCH 21/38] workqueue: add missing put_device call
Quoted 8 lines · Levente Kurusa
Quoted 4 lines
Greg, the API as described by the comment is really weird and unconventional. Failed calls are not supposed to have side effects which require explicit cleanup. Can we please update the comment?
Yes, it was already discussed that it would be more sane to have
device_register()callput_device()if it would fail, but Greg said that the API was designed so that no kfree()s happen in the core.
Of course not. For the third time: A failed call shouldn't make material changes which makes difference to its caller. An obj which failed init should be destructible in the exact reverse operation that the caller took to create it. This is a fundamental rule of any API design. There sure are occasional exceptions but there's no reason to deviate from that here.
Thanks.
Signature · 1 line
tejun
PATCH 22/38 sound: ac97: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- sound/pci/ac97/ac97_codec.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/ac97/ac97_codec.c +1 -0
@@ -1964,6 +1964,7 @@ static int snd_ac97_dev_register(struct snd_device *device) snd_ac97_get_short_name(ac97));if ((err =device_register (&ac97->dev)) <0 ) {snd_printk (KERN_ERR "Can't register ac97 bus\n" ); +put_device (&ac97->dev); ac97->dev.bus =NULL ;return err; }
Signature · 1 line
1.8.3.1
Re: [PATCH 22/38] sound: ac97: add missing put_device call
At Thu, 19 Dec 2013 16:03:33 +0100,
Quoted 4 lines · Levente Kurusa
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>
Hmm, I see no merit by this patch. It's an error path and the device is referenced from nowhere, thus we don't care its refcount any longer from there. Any missing point?
thanks,
Takashi
Quoted 19 lines
--- sound/pci/ac97/ac97_codec.c | 1 + 1 file changed, 1 insertion(+)sound/pci/ac97/ac97_codec.c +1
-0@@ -1964,6 +1964,7 @@ static int snd_ac97_dev_register(struct snd_device *device) snd_ac97_get_short_name(ac97));if ((err =device_register (&ac97->dev)) <0 ) {snd_printk (KERN_ERR "Can't register ac97 bus\n" ); +put_device (&ac97->dev); ac97->dev.bus =NULL ;return err; }Signature · 1 line
1.8.3.1
PATCH 23/38 sound: soc: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- sound/soc/soc-core.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/soc-core.c +1 -0
@@ -536,6 +536,7 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec) err =device_register (&codec->ac97->dev);if (err <0 ) {dev_err (codec->dev,"ASoC: Can't register ac97 bus\n" ); +put_device (&codec->ac97->dev); codec->ac97->dev.bus =NULL ;return err; }
Signature · 1 line
1.8.3.1
Re: [PATCH 23/38] sound: soc: add missing put_device call
Quoted 1 line · Levente Kurusa
This is required so that we give up the last reference to the device.
Applied, thanks. Please use subject lines matching the standard for the subsystem.
PATCH 24/38 pcmcia: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- drivers/pcmcia/cs.c | 1 + 1 file changed, 1 insertion(+)
drivers/pcmcia/cs.c +1 -0
@@ -607,6 +607,7 @@ static int pccardd(void *__skt)if (ret) {dev_printk (KERN_WARNING , &skt->dev,"PCMCIA: unable to register socket\n" ); +put_device (&skt->dev); skt->thread =NULL ;complete (&skt->thread_done);return 0 ;
Signature · 1 line
1.8.3.1
PATCH 25/38 pnp: card: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- drivers/pnp/card.c | 1 + 1 file changed, 1 insertion(+)
drivers/pnp/card.c +1 -0
@@ -239,6 +239,7 @@ int pnp_add_card(struct pnp_card *card) error =device_register (&card->dev);if (error) {dev_err (&card->dev,"could not register (err=%d)\n" , error); +put_device (&card->dev);return error; }
Signature · 1 line
1.8.3.1
Rafael J. Wysocki
AppliedRe: [PATCH 25/38] pnp: card: add missing put_device call
Quoted 3 lines · Levente Kurusa
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>
Queued up for 3.14, thanks!
Quoted 17 lines
--- drivers/pnp/card.c | 1 + 1 file changed, 1 insertion(+)drivers/pnp/card.c +1
-0@@ -239,6 +239,7 @@ int pnp_add_card(struct pnp_card *card) error =device_register (&card->dev);if (error) {dev_err (&card->dev,"could not register (err=%d)\n" , error); +put_device (&card->dev);return error; }
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 26/38 xen: xenbus: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- drivers/xen/xenbus/xenbus_probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_probe.c +3 -1
@@ -465,8 +465,10 @@ int xenbus_probe_node(struct xen_bus_type *bus,/* Register with generic device framework. */ err =device_register (&xendev->dev); -if (err) +if (err) { +put_device (&xendev->dev); goto fail; + }return 0 ; fail:
Signature · 1 line
1.8.3.1
PATCH 26/38 xen: xenbus: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- drivers/xen/xenbus/xenbus_probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_probe.c +3 -1
@@ -465,8 +465,10 @@ int xenbus_probe_node(struct xen_bus_type *bus,/* Register with generic device framework. */ err =device_register (&xendev->dev); -if (err) +if (err) { +put_device (&xendev->dev); goto fail; + }return 0 ; fail:
Signature · 1 line
1.8.3.1
Re: [Xen-devel] [PATCH 26/38] xen: xenbus: add missing put_device call
Quoted 13 lines · Levente Kurusa
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>--- drivers/xen/xenbus/xenbus_probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/xenbus/xenbus_probe.c +0
-0@@ -465,8 +465,10 @@ int xenbus_probe_node(struct xen_bus_type *bus,
drivers/xen/xenbus/xenbus_probe.c int xenbus_probe_node(struct xen_bus_type *bus, · line 474
Quoted 10 lines
drivers/xen/xenbus/xenbus_probe.c +3
-1/* Register with generic device framework. */ err =device_register (&xendev->dev); -if (err) +if (err) { +put_device (&xendev->dev); goto fail; + }return 0 ; fail:
There is a kfree(xendev) here so this introduces a double-free.
David
Re: [Xen-devel] [PATCH 26/38] xen: xenbus: add missing put_device call
Quoted 22 lines · David Vrabel
Quoted 21 lines · Levente Kurusa
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>--- drivers/xen/xenbus/xenbus_probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/xenbus/xenbus_probe.c +3
-1@@ -465,8 +465,10 @@ int xenbus_probe_node(struct xen_bus_type *bus,/* Register with generic device framework. */ err =device_register (&xendev->dev); -if (err) +if (err) { +put_device (&xendev->dev); goto fail; + }
Quoted 4 lines
drivers/xen/xenbus/xenbus_probe.c int xenbus_probe_node(struct xen_bus_type *bus, · line 474
Quoted 2 lines
drivers/xen/xenbus/xenbus_probe.c +0
-0return 0 ; fail:There is a kfree(xendev) here so this introduces a double-free.
How? put_device doesn't touch xendev itself, does it? It just drops the ref on the dev member which is not separately dynamically allocated and so not freed either.
Ian.
Re: [PATCH 26/38] xen: xenbus: add missing put_device call
Quoted 23 lines · Ian Campbell
Quoted 22 lines · David Vrabel
Quoted 21 lines · Levente Kurusa
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>--- drivers/xen/xenbus/xenbus_probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/xenbus/xenbus_probe.c +3
-1@@ -465,8 +465,10 @@ int xenbus_probe_node(struct xen_bus_type *bus,/* Register with generic device framework. */ err =device_register (&xendev->dev); -if (err) +if (err) { +put_device (&xendev->dev); goto fail; + }
Quoted 8 lines
Quoted 4 lines
drivers/xen/xenbus/xenbus_probe.c int xenbus_probe_node(struct xen_bus_type *bus, · line 474
Quoted 2 lines
drivers/xen/xenbus/xenbus_probe.c +0
-0return 0 ; fail:There is a kfree(xendev) here so this introduces a double-free.
How?
put_devicedoesn't touch xendev itself, does it? It just drops the ref on the dev member which is not separately dynamically allocated and so not freed either.
Releasing all references to the struct device frees the containing structure via xenbus->dev.release. i.e., xenbus_dev_release() which does kfree(xendev).
David
Re: [Xen-devel] [PATCH 26/38] xen: xenbus: add missing put_device call
In reply to Ian CampbellQuoted 23 lines · Ian Campbell
Quoted 22 lines · David Vrabel
Quoted 21 lines · Levente Kurusa
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>--- drivers/xen/xenbus/xenbus_probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/xenbus/xenbus_probe.c +3
-1@@ -465,8 +465,10 @@ int xenbus_probe_node(struct xen_bus_type *bus,/* Register with generic device framework. */ err =device_register (&xendev->dev); -if (err) +if (err) { +put_device (&xendev->dev); goto fail; + }
Quoted 8 lines
Quoted 4 lines
drivers/xen/xenbus/xenbus_probe.c int xenbus_probe_node(struct xen_bus_type *bus, · line 474
Quoted 2 lines
drivers/xen/xenbus/xenbus_probe.c +0
-0return 0 ; fail:There is a kfree(xendev) here so this introduces a double-free.
How?
put_devicedoesn't touch xendev itself, does it? It just drops the ref on the dev member which is not separately dynamically allocated and so not freed either.
Releasing all references to the struct device frees the containing structure via xenbus->dev.release. i.e., xenbus_dev_release() which does kfree(xendev).
David
Re: [Xen-devel] [PATCH 26/38] xen: xenbus: add missing put_device call
Quoted 29 lines · David Vrabel
Quoted 28 lines · Ian Campbell
Quoted 26 lines · David Vrabel
Quoted 13 lines · Levente Kurusa
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>--- drivers/xen/xenbus/xenbus_probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/xenbus/xenbus_probe.c +0
-0@@ -465,8 +465,10 @@ int xenbus_probe_node(struct xen_bus_type *bus,drivers/xen/xenbus/xenbus_probe.c int xenbus_probe_node(struct xen_bus_type *bus, · line 474
Quoted 10 lines
drivers/xen/xenbus/xenbus_probe.c +3
-1/* Register with generic device framework. */ err =device_register (&xendev->dev); -if (err) +if (err) { +put_device (&xendev->dev); goto fail; + }return 0 ; fail:There is a kfree(xendev) here so this introduces a double-free.
Quoted 7 lines
Quoted 3 lines
How?
put_devicedoesn't touch xendev itself, does it? It just drops the ref on the dev member which is not separately dynamically allocated and so not freed either.Releasing all references to the struct device frees the containing structure via
xenbus->dev.release. i.e.,xenbus_dev_release()which does kfree(xendev).
Ooh, twisty, well spotted ;-)
Ian.
Re: [PATCH 26/38] xen: xenbus: add missing put_device call
In reply to David VrabelQuoted 29 lines · David Vrabel
Quoted 28 lines · Ian Campbell
Quoted 26 lines · David Vrabel
Quoted 13 lines · Levente Kurusa
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>--- drivers/xen/xenbus/xenbus_probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/xenbus/xenbus_probe.c +0
-0@@ -465,8 +465,10 @@ int xenbus_probe_node(struct xen_bus_type *bus,drivers/xen/xenbus/xenbus_probe.c int xenbus_probe_node(struct xen_bus_type *bus, · line 474
Quoted 10 lines
drivers/xen/xenbus/xenbus_probe.c +3
-1/* Register with generic device framework. */ err =device_register (&xendev->dev); -if (err) +if (err) { +put_device (&xendev->dev); goto fail; + }return 0 ; fail:There is a kfree(xendev) here so this introduces a double-free.
Quoted 7 lines
Quoted 3 lines
How?
put_devicedoesn't touch xendev itself, does it? It just drops the ref on the dev member which is not separately dynamically allocated and so not freed either.Releasing all references to the struct device frees the containing structure via
xenbus->dev.release. i.e.,xenbus_dev_release()which does kfree(xendev).
Ooh, twisty, well spotted ;-)
Ian.
Re: [PATCH 26/38] xen: xenbus: add missing put_device call
In reply to David VrabelQuoted 22 lines · David Vrabel
Quoted 21 lines · Levente Kurusa
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>--- drivers/xen/xenbus/xenbus_probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/xenbus/xenbus_probe.c +3
-1@@ -465,8 +465,10 @@ int xenbus_probe_node(struct xen_bus_type *bus,/* Register with generic device framework. */ err =device_register (&xendev->dev); -if (err) +if (err) { +put_device (&xendev->dev); goto fail; + }
Quoted 4 lines
drivers/xen/xenbus/xenbus_probe.c int xenbus_probe_node(struct xen_bus_type *bus, · line 474
Quoted 2 lines
drivers/xen/xenbus/xenbus_probe.c +0
-0return 0 ; fail:There is a kfree(xendev) here so this introduces a double-free.
How? put_device doesn't touch xendev itself, does it? It just drops the ref on the dev member which is not separately dynamically allocated and so not freed either.
Ian.
Re: [PATCH 26/38] xen: xenbus: add missing put_device call
In reply to Levente KurusaQuoted 13 lines · Levente Kurusa
This is required so that we give up the last reference to the device.
Signed-off-by Levente Kurusa <[email protected]>--- drivers/xen/xenbus/xenbus_probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/xenbus/xenbus_probe.c +0
-0@@ -465,8 +465,10 @@ int xenbus_probe_node(struct xen_bus_type *bus,
drivers/xen/xenbus/xenbus_probe.c int xenbus_probe_node(struct xen_bus_type *bus, · line 474
Quoted 10 lines
drivers/xen/xenbus/xenbus_probe.c +3
-1/* Register with generic device framework. */ err =device_register (&xendev->dev); -if (err) +if (err) { +put_device (&xendev->dev); goto fail; + }return 0 ; fail:
There is a kfree(xendev) here so this introduces a double-free.
David
PATCH 27/38 superhyway: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device. Also, this makes superhyway_device_release actually used.
--- drivers/sh/superhyway/superhyway.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/sh/superhyway/superhyway.c +5 -1
@@ -54,6 +54,7 @@ int superhyway_add_device(unsigned long base, struct superhyway_device *sdev, struct superhyway_bus *bus) {struct superhyway_device *dev = sdev; +int rc =0 ;if (!dev) { dev =kzalloc (sizeof (struct superhyway_device ),GFP_KERNEL );
@@ -86,8 +87,11 @@ int superhyway_add_device(unsigned long base, struct superhyway_device *sdev,dev_set_name (&dev->dev,"%02x" , superhyway_devices); superhyway_devices++; + rc =device_register (&dev->dev); +if (rc) +put_device (&dev->dev); -return device_register (&dev->dev); +return rc; } int superhyway_add_devices(struct superhyway_bus *bus,
Signature · 1 line
1.8.3.1
PATCH 28/38 superhyway: intc: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device.
--- drivers/sh/intc/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/sh/intc/core.c +3 -1
@@ -504,8 +504,10 @@ static int __init register_intc_devs(void)if (error =0 ) error =device_create_file (&d->dev, &dev_attr_name); -if (error) +if (error) { +put_device (&d->dev);break ; + } } }
Signature · 1 line
1.8.3.1
PATCH 29/38 superhyway: maple: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device. Also rework maple_release_device to use maple_free_dev instead, avoiding same code being in two functions at the same time.
--- drivers/sh/maple/maple.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
drivers/sh/maple/maple.c +9 -14
@@ -134,16 +134,18 @@ static int maple_dma_done(void)return (__raw_readl (MAPLE_STATE ) &1 ) =0 ; } +static void maple_free_dev (struct maple_device *mdev) +{ +kmem_cache_free (maple_queue_cache, mdev->mq->recvbuf); +kfree (mdev->mq); +kfree (mdev); +} +static void maple_release_device (struct device *dev) {struct maple_device *mdev; -struct mapleq *mq; - mdev =to_maple_dev (dev); - mq = mdev->mq; -kmem_cache_free (maple_queue_cache, mq->recvbuf); -kfree (mq); -kfree (mdev); +maple_free_dev (mdev); }/**
@@ -234,13 +236,6 @@ static struct maple_device *maple_alloc_dev(int port, int unit)return mdev; } -static void maple_free_dev (struct maple_device *mdev) -{ -kmem_cache_free (maple_queue_cache, mdev->mq->recvbuf); -kfree (mdev->mq); -kfree (mdev); -} -/* process the command queue into a maple command block * terminating command has bit 32 of first long set to 0 */
@@ -393,7 +388,7 @@ static void maple_attach_driver(struct maple_device *mdev)dev_warn (&mdev->dev,"could not register device at" " (%d, %d), with error 0x%X\n" , mdev->unit, mdev->port, error); -maple_free_dev (mdev); +put_device (&mdev->dev); mdev =NULL ;return ; }
Signature · 1 line
1.8.3.1
PATCH 30/38 vlynq: add missing put_device call
In reply to Levente KurusaThis is required so that we give up the last reference to the device. This will result in vlynq_device_release being called making the kfree() in the errorpath unneccessary.
--- drivers/vlynq/vlynq.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/vlynq/vlynq.c +4 -1
@@ -748,11 +748,14 @@ static int vlynq_probe(struct platform_device *pdev)return 0 ; fail_register: +put_device (&dev->dev); + dev->dev =0 ;iounmap (dev->local); fail_remap: fail_request:release_mem_region (regs_res->start, len); -kfree (dev); +if (dev) +kfree (dev);return result; }
Signature · 1 line
1.8.3.1
Re: [PATCH 30/38] vlynq: add missing put_device call
2013/12/19 Levente Kurusa <[email protected]>:
Quoted 5 lines
This is required so that we give up the last reference to the device. This will result in
vlynq_device_releasebeing called making thekfree()in the errorpath unneccessary.Signed-off-by Levente Kurusa <[email protected]>
Quoted 11 lines
--- drivers/vlynq/vlynq.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/vlynq/vlynq.c +0
-0@@ -748,11 +748,14 @@ static int vlynq_probe(struct platform_device *pdev)return 0 ;
drivers/vlynq/vlynq.c static int vlynq_probe(struct platform_device *pdev) · line 758
Quoted 10 lines
drivers/vlynq/vlynq.c +4
-1fail_register: +put_device (&dev->dev); + dev->dev =0 ;iounmap (dev->local); fail_remap: fail_request:release_mem_region (regs_res->start, len); -kfree (dev); +if (dev) +kfree (dev);
This probably now generates a checkpatch warning since it is safe to call kfree() on a NULL pointer.
Quoted 5 lines
drivers/vlynq/vlynq.c +0
-1return result; } --1.8.3.1
Signature · 1 line
Florian