Skip to content

Commit

Permalink
ASoC: wm8731: Convert to devm_ functions
Browse files Browse the repository at this point in the history
Use the devm_ versions of the regmap and memory allocation functions,
saving some error handling code.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Mark Brown committed May 12, 2012
1 parent d564407 commit f1992dd
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions sound/soc/codecs/wm8731.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,16 +635,17 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi)
struct wm8731_priv *wm8731;
int ret;

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

wm8731->regmap = regmap_init_spi(spi, &wm8731_regmap);
wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap);
if (IS_ERR(wm8731->regmap)) {
ret = PTR_ERR(wm8731->regmap);
dev_err(&spi->dev, "Failed to allocate register map: %d\n",
ret);
goto err;
return ret;
}

spi_set_drvdata(spi, wm8731);
Expand All @@ -653,25 +654,15 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi)
&soc_codec_dev_wm8731, &wm8731_dai, 1);
if (ret != 0) {
dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret);
goto err_regmap;
return ret;
}

return 0;

err_regmap:
regmap_exit(wm8731->regmap);
err:
kfree(wm8731);
return ret;
}

static int __devexit wm8731_spi_remove(struct spi_device *spi)
{
struct wm8731_priv *wm8731 = spi_get_drvdata(spi);

snd_soc_unregister_codec(&spi->dev);
regmap_exit(wm8731->regmap);
kfree(wm8731);
return 0;
}

Expand All @@ -693,16 +684,17 @@ static __devinit int wm8731_i2c_probe(struct i2c_client *i2c,
struct wm8731_priv *wm8731;
int ret;

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

wm8731->regmap = regmap_init_i2c(i2c, &wm8731_regmap);
wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);
if (IS_ERR(wm8731->regmap)) {
ret = PTR_ERR(wm8731->regmap);
dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
ret);
goto err;
return ret;
}

i2c_set_clientdata(i2c, wm8731);
Expand All @@ -711,24 +703,15 @@ static __devinit int wm8731_i2c_probe(struct i2c_client *i2c,
&soc_codec_dev_wm8731, &wm8731_dai, 1);
if (ret != 0) {
dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
goto err_regmap;
return ret;
}

return 0;

err_regmap:
regmap_exit(wm8731->regmap);
err:
kfree(wm8731);
return ret;
}

static __devexit int wm8731_i2c_remove(struct i2c_client *client)
{
struct wm8731_priv *wm8731 = i2c_get_clientdata(client);
snd_soc_unregister_codec(&client->dev);
regmap_exit(wm8731->regmap);
kfree(wm8731);
return 0;
}

Expand Down

0 comments on commit f1992dd

Please sign in to comment.