summaryrefslogtreecommitdiffstats
path: root/drivers/staging/vc04_services
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2018-09-04 17:58:50 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-09-10 11:15:00 +0200
commitbe2af4715f383d5d9d2741e94076c2c027c5d060 (patch)
tree96bc9a27a23b2ea42ba9d6ffaa52abc353187cc9 /drivers/staging/vc04_services
parentd7ca3a71545bae2a802ab64afd7636c2daf26699 (diff)
downloadlinux-stable-be2af4715f383d5d9d2741e94076c2c027c5d060.tar.gz
linux-stable-be2af4715f383d5d9d2741e94076c2c027c5d060.tar.bz2
linux-stable-be2af4715f383d5d9d2741e94076c2c027c5d060.zip
staging: bcm2835-audio: Use card->private_data
Instead of allocating a separate snd_device object, let snd_card_new() allocate the private resource. This simplifies the code. Signed-off-by: Takashi Iwai <tiwai@suse.de> Tested-by: Stefan Wahren <stefan.wahren@i2se.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/vc04_services')
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835.c91
1 files changed, 13 insertions, 78 deletions
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
index 6876a5eadc07..55e7fbc3ec44 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
@@ -86,9 +86,6 @@ static int bcm2835_devm_add_vchi_ctx(struct device *dev)
static void snd_bcm2835_release(struct device *dev)
{
- struct bcm2835_chip *chip = dev_get_drvdata(dev);
-
- kfree(chip);
}
static struct device *
@@ -117,69 +114,6 @@ snd_create_device(struct device *parent,
return device;
}
-/* component-destructor
- * (see "Management of Cards and Components")
- */
-static int snd_bcm2835_dev_free(struct snd_device *device)
-{
- struct bcm2835_chip *chip = device->device_data;
- struct snd_card *card = chip->card;
-
- snd_device_free(card, chip);
-
- return 0;
-}
-
-/* chip-specific constructor
- * (see "Management of Cards and Components")
- */
-static int snd_bcm2835_create(struct snd_card *card,
- struct bcm2835_chip **rchip)
-{
- struct bcm2835_chip *chip;
- int err;
- static struct snd_device_ops ops = {
- .dev_free = snd_bcm2835_dev_free,
- };
-
- *rchip = NULL;
-
- chip = kzalloc(sizeof(*chip), GFP_KERNEL);
- if (!chip)
- return -ENOMEM;
-
- chip->card = card;
- mutex_init(&chip->audio_mutex);
-
- chip->vchi_ctx = devres_find(card->dev->parent,
- bcm2835_devm_free_vchi_ctx, NULL, NULL);
- if (!chip->vchi_ctx) {
- kfree(chip);
- return -ENODEV;
- }
-
- err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
- if (err) {
- kfree(chip);
- return err;
- }
-
- *rchip = chip;
- return 0;
-}
-
-static struct snd_card *snd_bcm2835_card_new(struct device *dev)
-{
- struct snd_card *card;
- int ret;
-
- ret = snd_card_new(dev, -1, NULL, THIS_MODULE, 0, &card);
- if (ret)
- return ERR_PTR(ret);
-
- return card;
-}
-
typedef int (*bcm2835_audio_newpcm_func)(struct bcm2835_chip *chip,
const char *name,
enum snd_bcm2835_route route,
@@ -292,25 +226,26 @@ static int snd_add_child_device(struct device *device,
return PTR_ERR(child);
}
- card = snd_bcm2835_card_new(child);
- if (IS_ERR(card)) {
+ err = snd_card_new(child, -1, NULL, THIS_MODULE, sizeof(*chip), &card);
+ if (err < 0) {
dev_err(child, "Failed to create card");
- return PTR_ERR(card);
+ return err;
}
- snd_card_set_dev(card, child);
+ chip = card->private_data;
+ chip->card = card;
+ chip->dev = child;
+ mutex_init(&chip->audio_mutex);
+
+ chip->vchi_ctx = devres_find(device,
+ bcm2835_devm_free_vchi_ctx, NULL, NULL);
+ if (!chip->vchi_ctx)
+ return -ENODEV;
+
strcpy(card->driver, audio_driver->driver.name);
strcpy(card->shortname, audio_driver->shortname);
strcpy(card->longname, audio_driver->longname);
- err = snd_bcm2835_create(card, &chip);
- if (err) {
- dev_err(child, "Failed to create chip, error %d\n", err);
- return err;
- }
-
- chip->dev = child;
-
err = audio_driver->newpcm(chip, audio_driver->shortname,
audio_driver->route,
numchans);