Skip to contentSkip to conversation

sh: dma-sysfs: add missing put_device call

PATCH Applied Levente Kurusa 10 participants 52 messages Dec 19, 2013 – Jan 6, 2014

Subsystems (22)
lore
Share & tools
lore
#0 lore raw

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
index 4b15fed..76271e6 100644
@@ -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
#1 lore raw

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
index b2b87c3..2e15262 100644
@@ -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
#2 lore raw

PATCH 3/38 powerpc: cell: add missing put_device call

In reply to Levente Kurusa

This 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
index f85db3a..f7fb0d9 100644
@@ -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
#3 lore raw

PATCH 4/38 powerpc: kernel: add missing put_device call

In reply to Levente Kurusa

This 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
index e7d0c88f..e8ed87e 100644
@@ -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
#4 lore raw

PATCH 5/38 sparc: kernel: add missing put_device call

In reply to Levente Kurusa

This 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
index 8647fcc..fb0088d 100644
@@ -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
maintainer
#5 lore raw

Re: [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 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.

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.

#6 lore raw

PATCH 6/38 arm: mach-s3c64: add missing put_device call

In reply to Levente Kurusa

This 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
index 7e22c21..090852d 100644
@@ -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
#7 lore raw

PATCH 7/38 arm: locomo: add missing put_device call

In reply to Levente Kurusa

This 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
index b55c362..e17d02c 100644
@@ -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
#8 lore raw

PATCH 8/38 arm: mach-rpc: add missing put_device call

In reply to Levente Kurusa

This 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
index fcb1d59..1c5f7cb 100644
@@ -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
#9 lore raw

PATCH 9/38 arm: mach-imx: add missing put_device calls

In reply to Levente Kurusa

This 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
index 1b4366a..0b17c89 100644
@@ -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
#10 lore raw

PATCH 10/38 arm: exynos: add missing put_device call

In reply to Levente Kurusa

This 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
index 61d2906..8b58829 100644
@@ -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
#11 lore raw

PATCH 11/38 arm: mach-integrator: add missing put_device call

In reply to Levente Kurusa

This 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
index f52c7af..1199f38 100644
@@ -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
#12 lore raw

PATCH 12/38 arm: s5pv210: add missing put_device call

In reply to Levente Kurusa

This 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
index 26027a2..81f43ae 100644
@@ -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
#13 lore raw

PATCH 13/38 arm: s390: add missing put_device call

In reply to Levente Kurusa

This 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
index 064c308..16c717f 100644
@@ -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
#14 lore raw

PATCH 14/38 mips: txx9: add missing put_device call

In reply to Levente Kurusa

This 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
index 2b0b83c..24332f5 100644
@@ -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
#15 lore raw

PATCH 15/38 mips: txx9: 7segled: add missing put_device call

In reply to Levente Kurusa

This 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
index 4642f56..3caa548 100644
@@ -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
#16 lore raw

PATCH 16/38 mips: sgi-ip22: add missing put_device call

In reply to Levente Kurusa

This 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
index ab0e379..931da33 100644
@@ -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
#17 lore raw

PATCH 17/38 parisc: kernel: add missing put_device call

In reply to Levente Kurusa

This 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
index 14285ca..b97cc05 100644
@@ -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
maintainer
#18 lore raw

Re: [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

#19 lore raw

PATCH 18/38 ia64: kernel: add missing put_device call

In reply to Levente Kurusa

This 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
index e35f648..6f369cc 100644
@@ -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
#20 lore raw

PATCH 19/38 net: atm: add missing put_device call

In reply to Levente Kurusa

This 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
index 350bf62..0e070c2 100644
@@ -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
maintainer
#21 lore raw

Re: [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.

...

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.

#22 lore raw

PATCH 20/38 net: iucv: add missing put_device call

In reply to Levente Kurusa

This 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
index 168aff5..0096206 100644
@@ -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
maintainer
#23 lore raw

Re: [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.

...

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.

#24 lore raw

PATCH 21/38 workqueue: add missing put_device call

In reply to Levente Kurusa

This 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
index 987293d..f3b3398 100644
@@ -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
maintainer Nacked-by on v1 21/38 NAK
#25 lore raw

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 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 +0 -0
index 987293d..f3b3398 100644

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
#26 lore raw

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
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
maintainer
#27 lore raw

Re: [PATCH 21/38] workqueue: add missing put_device call

Hello,

Quoted 4 lines · Levente Kurusa

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.

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 call put_device() and let the device's release() 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
#28 lore raw

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 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.

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 call put_device() and let the device's release() 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
maintainer
#29 lore raw

Re: [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() call put_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
#30 lore raw

PATCH 22/38 sound: ac97: add missing put_device call

In reply to Levente Kurusa

This 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
index bf578ba2..55186f8 100644
@@ -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
#31 lore raw

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.

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
index bf578ba2..55186f8 100644
@@ -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
#32 lore raw

PATCH 23/38 sound: soc: add missing put_device call

In reply to Levente Kurusa

This 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
index 4e53d87..21caa09 100644
@@ -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
maintainer Applied
#33 lore raw

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.

#34 lore raw

PATCH 24/38 pcmcia: add missing put_device call

In reply to Levente Kurusa

This 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
index 5292db6..5057de9 100644
@@ -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
#35 lore raw

PATCH 25/38 pnp: card: add missing put_device call

In reply to Levente Kurusa

This 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
index bc00693..874c236 100644
@@ -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
#36 lore raw

Re: [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.

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
index bc00693..874c236 100644
@@ -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.
#37 lore raw

PATCH 26/38 xen: xenbus: add missing put_device call

In reply to Levente Kurusa

This 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
index 3c0a74b..4abb9ee 100644
@@ -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
#38 lore raw

PATCH 26/38 xen: xenbus: add missing put_device call

In reply to Levente Kurusa

This 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
index 3c0a74b..4abb9ee 100644
@@ -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
#39 lore raw

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.

---
 drivers/xen/xenbus/xenbus_probe.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_probe.c +0 -0
index 3c0a74b..4abb9ee 100644
@@ -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

#40 lore raw

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.

---
 drivers/xen/xenbus/xenbus_probe.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_probe.c +3 -1
index 3c0a74b..4abb9ee 100644
@@ -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 -0
 	return 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.

#41 lore raw

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.

---
 drivers/xen/xenbus/xenbus_probe.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_probe.c +3 -1
index 3c0a74b..4abb9ee 100644
@@ -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 -0
 	return 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.

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

#42 lore raw

Re: [Xen-devel] [PATCH 26/38] xen: xenbus: add missing put_device call

In reply to Ian Campbell
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.

---
 drivers/xen/xenbus/xenbus_probe.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_probe.c +3 -1
index 3c0a74b..4abb9ee 100644
@@ -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 -0
 	return 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.

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

#43 lore raw

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.

---
 drivers/xen/xenbus/xenbus_probe.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_probe.c +0 -0
index 3c0a74b..4abb9ee 100644
@@ -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_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.

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.

#44 lore raw

Re: [PATCH 26/38] xen: xenbus: add missing put_device call

In reply to David Vrabel
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.

---
 drivers/xen/xenbus/xenbus_probe.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_probe.c +0 -0
index 3c0a74b..4abb9ee 100644
@@ -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_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.

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.

#45 lore raw

Re: [PATCH 26/38] xen: xenbus: add missing put_device call

In reply to David Vrabel
Quoted 22 lines · David Vrabel
Quoted 21 lines · Levente Kurusa

This 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
index 3c0a74b..4abb9ee 100644
@@ -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 -0
 	return 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.

#46 lore raw

Re: [PATCH 26/38] xen: xenbus: add missing put_device call

In reply to Levente Kurusa
Quoted 13 lines · Levente Kurusa

This 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 +0 -0
index 3c0a74b..4abb9ee 100644
@@ -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

#47 lore raw

PATCH 27/38 superhyway: add missing put_device call

In reply to Levente Kurusa

This 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
index 2d9e7f3..765cf7d 100644
@@ -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
#48 lore raw

PATCH 28/38 superhyway: intc: add missing put_device call

In reply to Levente Kurusa

This 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
index 8f32a13..c89768e 100644
@@ -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
#49 lore raw

PATCH 29/38 superhyway: maple: add missing put_device call

In reply to Levente Kurusa

This 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
index bec81c2..c4afb7e 100644
@@ -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
#50 lore raw

PATCH 30/38 vlynq: add missing put_device call

In reply to Levente Kurusa

This 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
index 7b07135..71d5905 100644
@@ -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
Acked-by on v1 30/38
#51 lore raw

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_release being called making the kfree() in the errorpath unneccessary.

Quoted 11 lines
---
 drivers/vlynq/vlynq.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/vlynq/vlynq.c +0 -0
index 7b07135..71d5905 100644
@@ -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 -1
 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);

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 -1
        return result;
 }
 
--

1.8.3.1

Signature · 1 line
Florian