Message ID | 1460644306.6039.3.camel@ingics.com |
---|---|
State | Superseded |
Headers | show |
2016-04-14 22:31 GMT+08:00 Axel Lin <axel.lin@ingics.com>: > Use devm_* APIs to simplify the code a bit. > This patch also fixes the memory leak when unload the module. > > Signed-off-by: Axel Lin <axel.lin@ingics.com> > --- > Hi, > I don't have this h/w, I'd appreciate if someone can test this patch. Obviously the module unload path has memory leak. Just wondering if anyone can review/test this patch. -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Dnia 2016-06-25, Sat o godzinie 09:41 +0800, Axel Lin pisze: > 2016-04-14 22:31 GMT+08:00 Axel Lin <axel.lin@ingics.com>: > > Use devm_* APIs to simplify the code a bit. > > This patch also fixes the memory leak when unload the module. > > > > Signed-off-by: Axel Lin <axel.lin@ingics.com> > > --- > > Hi, > > I don't have this h/w, I'd appreciate if someone can test this > > patch. > > Obviously the module unload path has memory leak. > Just wondering if anyone can review/test this patch. Gentlemen? (referring to the VE maintainers here) Original thread: thread.gmane.org/gmane.linux.drivers.i2c/27277 Thanks! Pawel -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, Jul 04, 2016 at 02:56:13PM +0100, Pawel Moll wrote: > Dnia 2016-06-25, Sat o godzinie 09:41 +0800, Axel Lin pisze: > > 2016-04-14 22:31 GMT+08:00 Axel Lin <axel.lin@ingics.com>: > > > Use devm_* APIs to simplify the code a bit. > > > This patch also fixes the memory leak when unload the module. > > > > > > Signed-off-by: Axel Lin <axel.lin@ingics.com> > > > --- > > > Hi, > > > I don't have this h/w, I'd appreciate if someone can test this > > > patch. > > > > Obviously the module unload path has memory leak. > > Just wondering if anyone can review/test this patch. > > Gentlemen? (referring to the VE maintainers here) > > Original thread: thread.gmane.org/gmane.linux.drivers.i2c/27277 We weren't CC'ed, thanks for the heads-up anyway we will have a look and test shortly (@Axel next time please CC us if you want us to test your patches, thanks). Lorenzo -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c index 240637f..c73d2d2 100644 --- a/drivers/i2c/busses/i2c-versatile.c +++ b/drivers/i2c/busses/i2c-versatile.c @@ -70,28 +70,14 @@ static int i2c_versatile_probe(struct platform_device *dev) struct resource *r; int ret; + i2c = devm_kzalloc(&dev->dev, sizeof(struct i2c_versatile), GFP_KERNEL); + if (!i2c) + return -ENOMEM; + r = platform_get_resource(dev, IORESOURCE_MEM, 0); - if (!r) { - ret = -EINVAL; - goto err_out; - } - - if (!request_mem_region(r->start, resource_size(r), "versatile-i2c")) { - ret = -EBUSY; - goto err_out; - } - - i2c = kzalloc(sizeof(struct i2c_versatile), GFP_KERNEL); - if (!i2c) { - ret = -ENOMEM; - goto err_release; - } - - i2c->base = ioremap(r->start, resource_size(r)); - if (!i2c->base) { - ret = -ENOMEM; - goto err_free; - } + i2c->base = devm_ioremap_resource(&dev->dev, r); + if (IS_ERR(i2c->base)) + return PTR_ERR(i2c->base); writel(SCL | SDA, i2c->base + I2C_CONTROLS); @@ -105,18 +91,12 @@ static int i2c_versatile_probe(struct platform_device *dev) i2c->adap.nr = dev->id; ret = i2c_bit_add_numbered_bus(&i2c->adap); - if (ret >= 0) { - platform_set_drvdata(dev, i2c); - return 0; - } - - iounmap(i2c->base); - err_free: - kfree(i2c); - err_release: - release_mem_region(r->start, resource_size(r)); - err_out: - return ret; + if (ret < 0) + return ret; + + platform_set_drvdata(dev, i2c); + + return 0; } static int i2c_versatile_remove(struct platform_device *dev)
Use devm_* APIs to simplify the code a bit. This patch also fixes the memory leak when unload the module. Signed-off-by: Axel Lin <axel.lin@ingics.com> --- Hi, I don't have this h/w, I'd appreciate if someone can test this patch. drivers/i2c/busses/i2c-versatile.c | 46 +++++++++++--------------------------- 1 file changed, 13 insertions(+), 33 deletions(-)