2013-05-23 15:25:32

by Lee Jones

[permalink] [raw]
Subject: [PATCH 01/16] mfd: tps65912: Convert to managed resources for allocating memory

Saves on code and simplifies the driver, as these resources are now
tracked and freed automatically when the driver is realised.

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/tps65912-core.c | 2 --
drivers/mfd/tps65912-i2c.c | 3 ++-
drivers/mfd/tps65912-spi.c | 3 ++-
3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/tps65912-core.c b/drivers/mfd/tps65912-core.c
index f91037a..7035743 100644
--- a/drivers/mfd/tps65912-core.c
+++ b/drivers/mfd/tps65912-core.c
@@ -161,7 +161,6 @@ int tps65912_device_init(struct tps65912 *tps65912)

err:
mfd_remove_devices(tps65912->dev);
- kfree(tps65912);
return ret;
}

@@ -169,7 +168,6 @@ void tps65912_device_exit(struct tps65912 *tps65912)
{
mfd_remove_devices(tps65912->dev);
tps65912_irq_exit(tps65912);
- kfree(tps65912);
}

MODULE_AUTHOR("Margarita Olaya <[email protected]>");
diff --git a/drivers/mfd/tps65912-i2c.c b/drivers/mfd/tps65912-i2c.c
index c041f2c..6a6343e 100644
--- a/drivers/mfd/tps65912-i2c.c
+++ b/drivers/mfd/tps65912-i2c.c
@@ -77,7 +77,8 @@ static int tps65912_i2c_probe(struct i2c_client *i2c,
{
struct tps65912 *tps65912;

- tps65912 = kzalloc(sizeof(struct tps65912), GFP_KERNEL);
+ tps65912 = devm_kzalloc(&i2c->dev,
+ sizeof(struct tps65912), GFP_KERNEL);
if (tps65912 == NULL)
return -ENOMEM;

diff --git a/drivers/mfd/tps65912-spi.c b/drivers/mfd/tps65912-spi.c
index b45f460..69a5178 100644
--- a/drivers/mfd/tps65912-spi.c
+++ b/drivers/mfd/tps65912-spi.c
@@ -85,7 +85,8 @@ static int tps65912_spi_probe(struct spi_device *spi)
{
struct tps65912 *tps65912;

- tps65912 = kzalloc(sizeof(struct tps65912), GFP_KERNEL);
+ tps65912 = devm_kzalloc(&spi->dev,
+ sizeof(struct tps65912), GFP_KERNEL);
if (tps65912 == NULL)
return -ENOMEM;

--
1.7.10.4


2013-05-23 15:25:34

by Lee Jones

[permalink] [raw]
Subject: [PATCH 02/16] mfd: 88pm860x: Convert to managed resources for allocating memory

---
drivers/mfd/88pm860x-core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
index 31ca555..ef6d82c 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -1150,7 +1150,8 @@ static int pm860x_probe(struct i2c_client *client,
return -EINVAL;
}

- chip = kzalloc(sizeof(struct pm860x_chip), GFP_KERNEL);
+ chip = devm_kzalloc(&client->dev,
+ sizeof(struct pm860x_chip), GFP_KERNEL);
if (chip == NULL)
return -ENOMEM;

@@ -1160,7 +1161,6 @@ static int pm860x_probe(struct i2c_client *client,
ret = PTR_ERR(chip->regmap);
dev_err(&client->dev, "Failed to allocate register map: %d\n",
ret);
- kfree(chip);
return ret;
}
chip->client = client;
@@ -1204,7 +1204,6 @@ static int pm860x_remove(struct i2c_client *client)
i2c_unregister_device(chip->companion);
}
regmap_exit(chip->regmap);
- kfree(chip);
return 0;
}

--
1.7.10.4

2013-05-23 15:25:40

by Lee Jones

[permalink] [raw]
Subject: [PATCH 04/16] mfd: ab8500-debug: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/ab8500-debugfs.c | 34 ++++++++++++----------------------
1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index 37b7ce4..7e80a0e 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -2937,7 +2937,6 @@ static struct dentry *ab8500_gpadc_dir;
static int ab8500_debug_probe(struct platform_device *plf)
{
struct dentry *file;
- int ret = -ENOMEM;
struct ab8500 *ab8500;
struct resource *res;
debug_bank = AB8500_MISC;
@@ -2946,24 +2945,26 @@ static int ab8500_debug_probe(struct platform_device *plf)
ab8500 = dev_get_drvdata(plf->dev.parent);
num_irqs = ab8500->mask_size;

- irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL);
+ irq_count = devm_kzalloc(&plf->dev,
+ sizeof(*irq_count)*num_irqs, GFP_KERNEL);
if (!irq_count)
return -ENOMEM;

- dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
+ dev_attr = devm_kzalloc(&plf->dev,
+ sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
if (!dev_attr)
- goto out_freeirq_count;
+ return -ENOMEM;

- event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL);
+ event_name = devm_kzalloc(&plf->dev,
+ sizeof(*event_name)*num_irqs, GFP_KERNEL);
if (!event_name)
- goto out_freedev_attr;
+ return -ENOMEM;

res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
if (!res) {
dev_err(&plf->dev, "AB8500 irq not found, err %d\n",
irq_first);
- ret = -ENXIO;
- goto out_freeevent_name;
+ return ENXIO;
}
irq_ab8500 = res->start;

@@ -2971,16 +2972,14 @@ static int ab8500_debug_probe(struct platform_device *plf)
if (irq_first < 0) {
dev_err(&plf->dev, "First irq not found, err %d\n",
irq_first);
- ret = irq_first;
- goto out_freeevent_name;
+ return irq_first;
}

irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
if (irq_last < 0) {
dev_err(&plf->dev, "Last irq not found, err %d\n",
irq_last);
- ret = irq_last;
- goto out_freeevent_name;
+ return irq_last;
}

ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
@@ -3189,22 +3188,13 @@ err:
if (ab8500_dir)
debugfs_remove_recursive(ab8500_dir);
dev_err(&plf->dev, "failed to create debugfs entries.\n");
-out_freeevent_name:
- kfree(event_name);
-out_freedev_attr:
- kfree(dev_attr);
-out_freeirq_count:
- kfree(irq_count);

- return ret;
+ return -ENOMEM;
}

static int ab8500_debug_remove(struct platform_device *plf)
{
debugfs_remove_recursive(ab8500_dir);
- kfree(event_name);
- kfree(dev_attr);
- kfree(irq_count);

return 0;
}
--
1.7.10.4

2013-05-23 15:25:49

by Lee Jones

[permalink] [raw]
Subject: [PATCH 10/16] mfd: davinci_voicecodec: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/davinci_voicecodec.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/davinci_voicecodec.c b/drivers/mfd/davinci_voicecodec.c
index c60ab0c..b6e2973 100644
--- a/drivers/mfd/davinci_voicecodec.c
+++ b/drivers/mfd/davinci_voicecodec.c
@@ -50,7 +50,8 @@ static int __init davinci_vc_probe(struct platform_device *pdev)
struct mfd_cell *cell = NULL;
int ret;

- davinci_vc = kzalloc(sizeof(struct davinci_vc), GFP_KERNEL);
+ davinci_vc = devm_kzalloc(&pdev->dev,
+ sizeof(struct davinci_vc), GFP_KERNEL);
if (!davinci_vc) {
dev_dbg(&pdev->dev,
"could not allocate memory for private data\n");
@@ -61,8 +62,7 @@ static int __init davinci_vc_probe(struct platform_device *pdev)
if (IS_ERR(davinci_vc->clk)) {
dev_dbg(&pdev->dev,
"could not get the clock for voice codec\n");
- ret = -ENODEV;
- goto fail1;
+ return -ENODEV;
}
clk_enable(davinci_vc->clk);

@@ -145,8 +145,6 @@ fail2:
clk_disable(davinci_vc->clk);
clk_put(davinci_vc->clk);
davinci_vc->clk = NULL;
-fail1:
- kfree(davinci_vc);

return ret;
}
@@ -164,8 +162,6 @@ static int davinci_vc_remove(struct platform_device *pdev)
clk_put(davinci_vc->clk);
davinci_vc->clk = NULL;

- kfree(davinci_vc);
-
return 0;
}

--
1.7.10.4

2013-05-23 15:25:56

by Lee Jones

[permalink] [raw]
Subject: [PATCH 14/16] mfd: janz-cmodio: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/janz-cmodio.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
index 45ece11..fcbb2e9 100644
--- a/drivers/mfd/janz-cmodio.c
+++ b/drivers/mfd/janz-cmodio.c
@@ -183,11 +183,10 @@ static int cmodio_pci_probe(struct pci_dev *dev,
struct cmodio_device *priv;
int ret;

- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) {
dev_err(&dev->dev, "unable to allocate private data\n");
- ret = -ENOMEM;
- goto out_return;
+ return -ENOMEM;
}

pci_set_drvdata(dev, priv);
@@ -197,7 +196,7 @@ static int cmodio_pci_probe(struct pci_dev *dev,
ret = pci_enable_device(dev);
if (ret) {
dev_err(&dev->dev, "unable to enable device\n");
- goto out_free_priv;
+ return ret;
}

pci_set_master(dev);
@@ -248,9 +247,7 @@ out_pci_release_regions:
pci_release_regions(dev);
out_pci_disable_device:
pci_disable_device(dev);
-out_free_priv:
- kfree(priv);
-out_return:
+
return ret;
}

@@ -263,7 +260,6 @@ static void cmodio_pci_remove(struct pci_dev *dev)
iounmap(priv->ctrl);
pci_release_regions(dev);
pci_disable_device(dev);
- kfree(priv);
}

#define PCI_VENDOR_ID_JANZ 0x13c3
--
1.7.10.4

2013-05-23 15:25:44

by Lee Jones

[permalink] [raw]
Subject: [PATCH 07/16] mfd: adp5520: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/adp5520.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/adp5520.c b/drivers/mfd/adp5520.c
index 0d2eba0..28346ad 100644
--- a/drivers/mfd/adp5520.c
+++ b/drivers/mfd/adp5520.c
@@ -223,7 +223,7 @@ static int adp5520_probe(struct i2c_client *client,
return -ENODEV;
}

- chip = kzalloc(sizeof(*chip), GFP_KERNEL);
+ chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
return -ENOMEM;

@@ -244,7 +244,7 @@ static int adp5520_probe(struct i2c_client *client,
if (ret) {
dev_err(&client->dev, "failed to request irq %d\n",
chip->irq);
- goto out_free_chip;
+ return ret;
}
}

@@ -302,9 +302,6 @@ out_free_irq:
if (chip->irq)
free_irq(chip->irq, chip);

-out_free_chip:
- kfree(chip);
-
return ret;
}

@@ -317,7 +314,6 @@ static int adp5520_remove(struct i2c_client *client)

adp5520_remove_subdevs(chip);
adp5520_write(chip->dev, ADP5520_MODE_STATUS, 0);
- kfree(chip);
return 0;
}

--
1.7.10.4

2013-05-23 15:25:52

by Lee Jones

[permalink] [raw]
Subject: [PATCH 12/16] mfd: htc-i2cpld: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/htc-i2cpld.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/mfd/htc-i2cpld.c b/drivers/mfd/htc-i2cpld.c
index 324187c..c9dfce6 100644
--- a/drivers/mfd/htc-i2cpld.c
+++ b/drivers/mfd/htc-i2cpld.c
@@ -514,8 +514,8 @@ static int htcpld_setup_chips(struct platform_device *pdev)

/* Setup each chip's output GPIOs */
htcpld->nchips = pdata->num_chip;
- htcpld->chip = kzalloc(sizeof(struct htcpld_chip) * htcpld->nchips,
- GFP_KERNEL);
+ htcpld->chip = devm_kzalloc(dev, sizeof(struct htcpld_chip) * htcpld->nchips,
+ GFP_KERNEL);
if (!htcpld->chip) {
dev_warn(dev, "Unable to allocate memory for chips\n");
return -ENOMEM;
@@ -580,12 +580,11 @@ static int htcpld_core_probe(struct platform_device *pdev)
return -ENXIO;
}

- htcpld = kzalloc(sizeof(struct htcpld_data), GFP_KERNEL);
+ htcpld = devm_kzalloc(dev, sizeof(struct htcpld_data), GFP_KERNEL);
if (!htcpld)
return -ENOMEM;

/* Find chained irq */
- ret = -EINVAL;
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (res) {
int flags;
@@ -598,7 +597,7 @@ static int htcpld_core_probe(struct platform_device *pdev)
flags, pdev->name, htcpld);
if (ret) {
dev_warn(dev, "Unable to setup chained irq handler: %d\n", ret);
- goto fail;
+ return ret;
} else
device_init_wakeup(dev, 0);
}
@@ -609,7 +608,7 @@ static int htcpld_core_probe(struct platform_device *pdev)
/* Setup the htcpld chips */
ret = htcpld_setup_chips(pdev);
if (ret)
- goto fail;
+ return ret;

/* Request the GPIO(s) for the int reset and set them up */
if (pdata->int_reset_gpio_hi) {
@@ -644,10 +643,6 @@ static int htcpld_core_probe(struct platform_device *pdev)

dev_info(dev, "Initialized successfully\n");
return 0;
-
-fail:
- kfree(htcpld);
- return ret;
}

/* The I2C Driver -- used internally */
--
1.7.10.4

2013-05-23 15:26:01

by Lee Jones

[permalink] [raw]
Subject: [PATCH 16/16] mfd: max8925: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/max8925-i2c.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
index 92bbebd..8042b32 100644
--- a/drivers/mfd/max8925-i2c.c
+++ b/drivers/mfd/max8925-i2c.c
@@ -170,7 +170,8 @@ static int max8925_probe(struct i2c_client *client,
return -EINVAL;
}

- chip = kzalloc(sizeof(struct max8925_chip), GFP_KERNEL);
+ chip = devm_kzalloc(&client->dev,
+ sizeof(struct max8925_chip), GFP_KERNEL);
if (chip == NULL)
return -ENOMEM;
chip->i2c = client;
@@ -199,7 +200,6 @@ static int max8925_remove(struct i2c_client *client)
max8925_device_exit(chip);
i2c_unregister_device(chip->adc);
i2c_unregister_device(chip->rtc);
- kfree(chip);
return 0;
}

--
1.7.10.4

2013-05-23 15:26:45

by Lee Jones

[permalink] [raw]
Subject: [PATCH 09/16] mfd: cros_ec: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/cros_ec.c | 28 +++++++++-------------------
1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
index 10cd14e..1f36885 100644
--- a/drivers/mfd/cros_ec.c
+++ b/drivers/mfd/cros_ec.c
@@ -104,23 +104,19 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
ec_dev->command_sendrecv = cros_ec_command_sendrecv;

if (ec_dev->din_size) {
- ec_dev->din = kmalloc(ec_dev->din_size, GFP_KERNEL);
- if (!ec_dev->din) {
- err = -ENOMEM;
- goto fail_din;
- }
+ ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL);
+ if (!ec_dev->din)
+ return -ENOMEM;
}
if (ec_dev->dout_size) {
- ec_dev->dout = kmalloc(ec_dev->dout_size, GFP_KERNEL);
- if (!ec_dev->dout) {
- err = -ENOMEM;
- goto fail_dout;
- }
+ ec_dev->dout = devm_kzalloc(dev, ec_dev->dout_size, GFP_KERNEL);
+ if (!ec_dev->dout)
+ return -ENOMEM;
}

if (!ec_dev->irq) {
dev_dbg(dev, "no valid IRQ: %d\n", ec_dev->irq);
- goto fail_irq;
+ return err;
}

err = request_threaded_irq(ec_dev->irq, NULL, ec_irq_thread,
@@ -128,7 +124,7 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
"chromeos-ec", ec_dev);
if (err) {
dev_err(dev, "request irq %d: error %d\n", ec_dev->irq, err);
- goto fail_irq;
+ return err;
}

err = mfd_add_devices(dev, 0, cros_devs,
@@ -145,11 +141,7 @@ int cros_ec_register(struct cros_ec_device *ec_dev)

fail_mfd:
free_irq(ec_dev->irq, ec_dev);
-fail_irq:
- kfree(ec_dev->dout);
-fail_dout:
- kfree(ec_dev->din);
-fail_din:
+
return err;
}
EXPORT_SYMBOL(cros_ec_register);
@@ -158,8 +150,6 @@ int cros_ec_remove(struct cros_ec_device *ec_dev)
{
mfd_remove_devices(ec_dev->dev);
free_irq(ec_dev->irq, ec_dev);
- kfree(ec_dev->dout);
- kfree(ec_dev->din);

return 0;
}
--
1.7.10.4

2013-05-23 15:26:44

by Lee Jones

[permalink] [raw]
Subject: [PATCH 15/16] mfd: max77686: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/max77686.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 1cbb176..b094ac5 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -84,12 +84,12 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
pdata = max77686_i2c_parse_dt_pdata(&i2c->dev);

if (!pdata) {
- ret = -EIO;
dev_err(&i2c->dev, "No platform data found.\n");
- goto err;
+ return -EIO;
}

- max77686 = kzalloc(sizeof(struct max77686_dev), GFP_KERNEL);
+ max77686 = devm_kzalloc(&i2c->dev,
+ sizeof(struct max77686_dev), GFP_KERNEL);
if (max77686 == NULL)
return -ENOMEM;

@@ -107,7 +107,6 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
ret = PTR_ERR(max77686->regmap);
dev_err(max77686->dev, "Failed to allocate register map: %d\n",
ret);
- kfree(max77686);
return ret;
}

@@ -115,8 +114,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
MAX77686_REG_DEVICE_ID, &data) < 0) {
dev_err(max77686->dev,
"device not found on this channel (this is not an error)\n");
- ret = -ENODEV;
- goto err;
+ return -ENODEV;
} else
dev_info(max77686->dev, "device found\n");

@@ -127,17 +125,11 @@ static int max77686_i2c_probe(struct i2c_client *i2c,

ret = mfd_add_devices(max77686->dev, -1, max77686_devs,
ARRAY_SIZE(max77686_devs), NULL, 0, NULL);
+ if (ret < 0) {
+ mfd_remove_devices(max77686->dev);
+ i2c_unregister_device(max77686->rtc);
+ }

- if (ret < 0)
- goto err_mfd;
-
- return ret;
-
-err_mfd:
- mfd_remove_devices(max77686->dev);
- i2c_unregister_device(max77686->rtc);
-err:
- kfree(max77686);
return ret;
}

@@ -147,7 +139,6 @@ static int max77686_i2c_remove(struct i2c_client *i2c)

mfd_remove_devices(max77686->dev);
i2c_unregister_device(max77686->rtc);
- kfree(max77686);

return 0;
}
--
1.7.10.4

2013-05-23 15:28:27

by Lee Jones

[permalink] [raw]
Subject: [PATCH 13/16] mfd: htc-pasic3: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/htc-pasic3.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/mfd/htc-pasic3.c b/drivers/mfd/htc-pasic3.c
index 0285fce..0a5e85f 100644
--- a/drivers/mfd/htc-pasic3.c
+++ b/drivers/mfd/htc-pasic3.c
@@ -147,7 +147,7 @@ static int __init pasic3_probe(struct platform_device *pdev)
if (!request_mem_region(r->start, resource_size(r), "pasic3"))
return -EBUSY;

- asic = kzalloc(sizeof(struct pasic3_data), GFP_KERNEL);
+ asic = devm_kzalloc(dev, sizeof(struct pasic3_data), GFP_KERNEL);
if (!asic)
return -ENOMEM;

@@ -156,7 +156,6 @@ static int __init pasic3_probe(struct platform_device *pdev)
asic->mapping = ioremap(r->start, resource_size(r));
if (!asic->mapping) {
dev_err(dev, "couldn't ioremap PASIC3\n");
- kfree(asic);
return -ENOMEM;
}

@@ -195,7 +194,6 @@ static int pasic3_remove(struct platform_device *pdev)
iounmap(asic->mapping);
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(r->start, resource_size(r));
- kfree(asic);
return 0;
}

--
1.7.10.4

2013-05-23 15:28:50

by Lee Jones

[permalink] [raw]
Subject: [PATCH 11/16] mfd: htc-egpio: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/htc-egpio.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/htc-egpio.c b/drivers/mfd/htc-egpio.c
index bbaec0c..f2e0ad4 100644
--- a/drivers/mfd/htc-egpio.c
+++ b/drivers/mfd/htc-egpio.c
@@ -270,7 +270,7 @@ static int __init egpio_probe(struct platform_device *pdev)
int ret;

/* Initialize ei data structure. */
- ei = kzalloc(sizeof(*ei), GFP_KERNEL);
+ ei = devm_kzalloc(&pdev->dev, sizeof(*ei), GFP_KERNEL);
if (!ei)
return -ENOMEM;

@@ -306,7 +306,9 @@ static int __init egpio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, ei);

ei->nchips = pdata->num_chips;
- ei->chip = kzalloc(sizeof(struct egpio_chip) * ei->nchips, GFP_KERNEL);
+ ei->chip = devm_kzalloc(&pdev->dev,
+ sizeof(struct egpio_chip) * ei->nchips,
+ GFP_KERNEL);
if (!ei->chip) {
ret = -ENOMEM;
goto fail;
@@ -361,7 +363,6 @@ static int __init egpio_probe(struct platform_device *pdev)

fail:
printk(KERN_ERR "EGPIO failed to setup\n");
- kfree(ei);
return ret;
}

@@ -380,8 +381,6 @@ static int __exit egpio_remove(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 0);
}
iounmap(ei->base_addr);
- kfree(ei->chip);
- kfree(ei);

return 0;
}
--
1.7.10.4

2013-05-23 15:29:13

by Lee Jones

[permalink] [raw]
Subject: [PATCH 08/16] mfd: asic3: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/asic3.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/mfd/asic3.c b/drivers/mfd/asic3.c
index 1b15986..9532f74 100644
--- a/drivers/mfd/asic3.c
+++ b/drivers/mfd/asic3.c
@@ -958,7 +958,8 @@ static int __init asic3_probe(struct platform_device *pdev)
unsigned long clksel;
int ret = 0;

- asic = kzalloc(sizeof(struct asic3), GFP_KERNEL);
+ asic = devm_kzalloc(&pdev->dev,
+ sizeof(struct asic3), GFP_KERNEL);
if (asic == NULL) {
printk(KERN_ERR "kzalloc failed\n");
return -ENOMEM;
@@ -970,16 +971,14 @@ static int __init asic3_probe(struct platform_device *pdev)

mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!mem) {
- ret = -ENOMEM;
dev_err(asic->dev, "no MEM resource\n");
- goto out_free;
+ return -ENOMEM;
}

asic->mapping = ioremap(mem->start, resource_size(mem));
if (!asic->mapping) {
- ret = -ENOMEM;
dev_err(asic->dev, "Couldn't ioremap\n");
- goto out_free;
+ return -ENOMEM;
}

asic->irq_base = pdata->irq_base;
@@ -1033,9 +1032,6 @@ static int __init asic3_probe(struct platform_device *pdev)
out_unmap:
iounmap(asic->mapping);

- out_free:
- kfree(asic);
-
return ret;
}

@@ -1058,8 +1054,6 @@ static int asic3_remove(struct platform_device *pdev)

iounmap(asic->mapping);

- kfree(asic);
-
return 0;
}

--
1.7.10.4

2013-05-23 15:29:33

by Lee Jones

[permalink] [raw]
Subject: [PATCH 06/16] mfd: abx500-core: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/abx500-core.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
index 3714acb..f3a15aa 100644
--- a/drivers/mfd/abx500-core.c
+++ b/drivers/mfd/abx500-core.c
@@ -36,7 +36,9 @@ int abx500_register_ops(struct device *dev, struct abx500_ops *ops)
{
struct abx500_device_entry *dev_entry;

- dev_entry = kzalloc(sizeof(struct abx500_device_entry), GFP_KERNEL);
+ dev_entry = devm_kzalloc(dev,
+ sizeof(struct abx500_device_entry),
+ GFP_KERNEL);
if (!dev_entry) {
dev_err(dev, "register_ops kzalloc failed");
return -ENOMEM;
@@ -54,12 +56,8 @@ void abx500_remove_ops(struct device *dev)
struct abx500_device_entry *dev_entry, *tmp;

list_for_each_entry_safe(dev_entry, tmp, &abx500_list, list)
- {
- if (dev_entry->dev == dev) {
+ if (dev_entry->dev == dev)
list_del(&dev_entry->list);
- kfree(dev_entry);
- }
- }
}
EXPORT_SYMBOL(abx500_remove_ops);

--
1.7.10.4

2013-05-23 15:29:31

by Lee Jones

[permalink] [raw]
Subject: [PATCH 05/16] mfd: ab8500-gpadc: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/ab8500-gpadc.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/mfd/ab8500-gpadc.c b/drivers/mfd/ab8500-gpadc.c
index 13f7866..f1d4565 100644
--- a/drivers/mfd/ab8500-gpadc.c
+++ b/drivers/mfd/ab8500-gpadc.c
@@ -925,7 +925,7 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
int ret = 0;
struct ab8500_gpadc *gpadc;

- gpadc = kzalloc(sizeof(struct ab8500_gpadc), GFP_KERNEL);
+ gpadc = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_gpadc), GFP_KERNEL);
if (!gpadc) {
dev_err(&pdev->dev, "Error: No memory\n");
return -ENOMEM;
@@ -1005,8 +1005,6 @@ fail_irq:
free_irq(gpadc->irq_sw, gpadc);
free_irq(gpadc->irq_hw, gpadc);
fail:
- kfree(gpadc);
- gpadc = NULL;
return ret;
}

@@ -1031,8 +1029,6 @@ static int ab8500_gpadc_remove(struct platform_device *pdev)

pm_runtime_put_noidle(gpadc->dev);

- kfree(gpadc);
- gpadc = NULL;
return 0;
}

--
1.7.10.4

2013-05-23 15:30:04

by Lee Jones

[permalink] [raw]
Subject: [PATCH 03/16] mfd: ab3100-otp: Convert to managed resources for allocating memory

Signed-off-by: Lee Jones <[email protected]>
---
drivers/mfd/ab3100-otp.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/mfd/ab3100-otp.c b/drivers/mfd/ab3100-otp.c
index d7ce016..c9af16c 100644
--- a/drivers/mfd/ab3100-otp.c
+++ b/drivers/mfd/ab3100-otp.c
@@ -187,7 +187,7 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
int err = 0;
int i;

- otp = kzalloc(sizeof(struct ab3100_otp), GFP_KERNEL);
+ otp = devm_kzalloc(&pdev->dev, sizeof(struct ab3100_otp), GFP_KERNEL);
if (!otp) {
dev_err(&pdev->dev, "could not allocate AB3100 OTP device\n");
return -ENOMEM;
@@ -199,7 +199,7 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)

err = ab3100_otp_read(otp);
if (err)
- goto err_otp_read;
+ return err;

dev_info(&pdev->dev, "AB3100 OTP readout registered\n");

@@ -208,22 +208,19 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
err = device_create_file(&pdev->dev,
&ab3100_otp_attrs[i]);
if (err)
- goto err_create_file;
+ goto err;
}

/* debugfs entries */
err = ab3100_otp_init_debugfs(&pdev->dev, otp);
if (err)
- goto err_init_debugfs;
+ goto err;

return 0;

-err_init_debugfs:
-err_create_file:
+err:
while (--i >= 0)
device_remove_file(&pdev->dev, &ab3100_otp_attrs[i]);
-err_otp_read:
- kfree(otp);
return err;
}

@@ -236,7 +233,6 @@ static int __exit ab3100_otp_remove(struct platform_device *pdev)
device_remove_file(&pdev->dev,
&ab3100_otp_attrs[i]);
ab3100_otp_exit_debugfs(otp);
- kfree(otp);
return 0;
}

--
1.7.10.4

2013-06-11 18:20:01

by Samuel Ortiz

[permalink] [raw]
Subject: Re: [PATCH 01/16] mfd: tps65912: Convert to managed resources for allocating memory

Hi Lee,

On Thu, May 23, 2013 at 04:25:02PM +0100, Lee Jones wrote:
> Saves on code and simplifies the driver, as these resources are now
> tracked and freed automatically when the driver is realised.
>
> Signed-off-by: Lee Jones <[email protected]>
> ---
> drivers/mfd/tps65912-core.c | 2 --
> drivers/mfd/tps65912-i2c.c | 3 ++-
> drivers/mfd/tps65912-spi.c | 3 ++-
> 3 files changed, 4 insertions(+), 4 deletions(-)
All 16 patches applied to mfd-next, thanks.

Cheers,
Samuel.

--
Intel Open Source Technology Centre
http://oss.intel.com/