i2c: versatile: Convert to use resource managed devm_* APIs
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> Tested-by: Liviu Dudau <Liviu.Dudau@arm.com> Acked-by: Liviu Dudau <Liviu.Dudau@arm.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
This commit is contained in:
parent
9f6db9bfb5
commit
cc4618813e
|
@ -70,28 +70,14 @@ static int i2c_versatile_probe(struct platform_device *dev)
|
||||||
struct resource *r;
|
struct resource *r;
|
||||||
int ret;
|
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);
|
r = platform_get_resource(dev, IORESOURCE_MEM, 0);
|
||||||
if (!r) {
|
i2c->base = devm_ioremap_resource(&dev->dev, r);
|
||||||
ret = -EINVAL;
|
if (IS_ERR(i2c->base))
|
||||||
goto err_out;
|
return PTR_ERR(i2c->base);
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
writel(SCL | SDA, i2c->base + I2C_CONTROLS);
|
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;
|
i2c->adap.nr = dev->id;
|
||||||
ret = i2c_bit_add_numbered_bus(&i2c->adap);
|
ret = i2c_bit_add_numbered_bus(&i2c->adap);
|
||||||
if (ret >= 0) {
|
if (ret < 0)
|
||||||
platform_set_drvdata(dev, i2c);
|
return ret;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
iounmap(i2c->base);
|
platform_set_drvdata(dev, i2c);
|
||||||
err_free:
|
|
||||||
kfree(i2c);
|
return 0;
|
||||||
err_release:
|
|
||||||
release_mem_region(r->start, resource_size(r));
|
|
||||||
err_out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int i2c_versatile_remove(struct platform_device *dev)
|
static int i2c_versatile_remove(struct platform_device *dev)
|
||||||
|
|
Loading…
Reference in New Issue