ASoC: wm8731: Convert to devm_ functions
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Sat, 12 May 2012 19:08:43 +0000 (20:08 +0100)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Sat, 12 May 2012 19:11:38 +0000 (20:11 +0100)
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>
sound/soc/codecs/wm8731.c

index a32caa72bd7d727e4e94737e50650d647da1e2db..9d1b9b0271f18671bf50cdfb77c448b40d46db8b 100644 (file)
@@ -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);
@@ -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;
 }
 
@@ -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);
@@ -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;
 }