mfd: Convert da9052 to use devm_* APIs
Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
805b237a63
commit
6608a5e2dd
|
@ -70,7 +70,7 @@ static int __devinit da9052_i2c_probe(struct i2c_client *client,
|
|||
struct da9052 *da9052;
|
||||
int ret;
|
||||
|
||||
da9052 = kzalloc(sizeof(struct da9052), GFP_KERNEL);
|
||||
da9052 = devm_kzalloc(&client->dev, sizeof(struct da9052), GFP_KERNEL);
|
||||
if (!da9052)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -78,8 +78,7 @@ static int __devinit da9052_i2c_probe(struct i2c_client *client,
|
|||
I2C_FUNC_SMBUS_BYTE_DATA)) {
|
||||
dev_info(&client->dev, "Error in %s:i2c_check_functionality\n",
|
||||
__func__);
|
||||
ret = -ENODEV;
|
||||
goto err;
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
da9052->dev = &client->dev;
|
||||
|
@ -87,17 +86,17 @@ static int __devinit da9052_i2c_probe(struct i2c_client *client,
|
|||
|
||||
i2c_set_clientdata(client, da9052);
|
||||
|
||||
da9052->regmap = regmap_init_i2c(client, &da9052_regmap_config);
|
||||
da9052->regmap = devm_regmap_init_i2c(client, &da9052_regmap_config);
|
||||
if (IS_ERR(da9052->regmap)) {
|
||||
ret = PTR_ERR(da9052->regmap);
|
||||
dev_err(&client->dev, "Failed to allocate register map: %d\n",
|
||||
ret);
|
||||
goto err;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = da9052_i2c_enable_multiwrite(da9052);
|
||||
if (ret < 0)
|
||||
goto err_regmap;
|
||||
return ret;
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
if (!id) {
|
||||
|
@ -112,20 +111,14 @@ static int __devinit da9052_i2c_probe(struct i2c_client *client,
|
|||
if (!id) {
|
||||
ret = -ENODEV;
|
||||
dev_err(&client->dev, "id is null.\n");
|
||||
goto err_regmap;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = da9052_device_init(da9052, id->driver_data);
|
||||
if (ret != 0)
|
||||
goto err_regmap;
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
|
||||
err_regmap:
|
||||
regmap_exit(da9052->regmap);
|
||||
err:
|
||||
kfree(da9052);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __devexit da9052_i2c_remove(struct i2c_client *client)
|
||||
|
@ -133,9 +126,6 @@ static int __devexit da9052_i2c_remove(struct i2c_client *client)
|
|||
struct da9052 *da9052 = i2c_get_clientdata(client);
|
||||
|
||||
da9052_device_exit(da9052);
|
||||
regmap_exit(da9052->regmap);
|
||||
kfree(da9052);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,9 @@ static int __devinit da9052_spi_probe(struct spi_device *spi)
|
|||
{
|
||||
int ret;
|
||||
const struct spi_device_id *id = spi_get_device_id(spi);
|
||||
struct da9052 *da9052 = kzalloc(sizeof(struct da9052), GFP_KERNEL);
|
||||
struct da9052 *da9052;
|
||||
|
||||
da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL);
|
||||
if (!da9052)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -42,25 +43,19 @@ static int __devinit da9052_spi_probe(struct spi_device *spi)
|
|||
da9052_regmap_config.read_flag_mask = 1;
|
||||
da9052_regmap_config.write_flag_mask = 0;
|
||||
|
||||
da9052->regmap = regmap_init_spi(spi, &da9052_regmap_config);
|
||||
da9052->regmap = devm_regmap_init_spi(spi, &da9052_regmap_config);
|
||||
if (IS_ERR(da9052->regmap)) {
|
||||
ret = PTR_ERR(da9052->regmap);
|
||||
dev_err(&spi->dev, "Failed to allocate register map: %d\n",
|
||||
ret);
|
||||
goto err;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = da9052_device_init(da9052, id->driver_data);
|
||||
if (ret != 0)
|
||||
goto err_regmap;
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
|
||||
err_regmap:
|
||||
regmap_exit(da9052->regmap);
|
||||
err:
|
||||
kfree(da9052);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __devexit da9052_spi_remove(struct spi_device *spi)
|
||||
|
@ -68,9 +63,6 @@ static int __devexit da9052_spi_remove(struct spi_device *spi)
|
|||
struct da9052 *da9052 = dev_get_drvdata(&spi->dev);
|
||||
|
||||
da9052_device_exit(da9052);
|
||||
regmap_exit(da9052->regmap);
|
||||
kfree(da9052);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue