1 From af0ded6e9dd38f08a9ee621066e583b5cf972926 Mon Sep 17 00:00:00 2001
2 From: Takashi Iwai <tiwai@suse.de>
3 Date: Tue, 4 Sep 2018 17:58:50 +0200
4 Subject: [PATCH] staging: bcm2835-audio: Use card->private_data
6 commit 898001a0c845cefe5d47d133485712412853f0a8 upstream.
8 Instead of allocating a separate snd_device object, let snd_card_new()
9 allocate the private resource. This simplifies the code.
11 Signed-off-by: Takashi Iwai <tiwai@suse.de>
12 Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
15 .../vc04_services/bcm2835-audio/bcm2835.c | 91 +++----------------
16 1 file changed, 13 insertions(+), 78 deletions(-)
18 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
19 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
20 @@ -86,9 +86,6 @@ static int bcm2835_devm_add_vchi_ctx(str
22 static void snd_bcm2835_release(struct device *dev)
24 - struct bcm2835_chip *chip = dev_get_drvdata(dev);
29 static struct device *
30 @@ -117,69 +114,6 @@ snd_create_device(struct device *parent,
34 -/* component-destructor
35 - * (see "Management of Cards and Components")
37 -static int snd_bcm2835_dev_free(struct snd_device *device)
39 - struct bcm2835_chip *chip = device->device_data;
40 - struct snd_card *card = chip->card;
42 - snd_device_free(card, chip);
47 -/* chip-specific constructor
48 - * (see "Management of Cards and Components")
50 -static int snd_bcm2835_create(struct snd_card *card,
51 - struct bcm2835_chip **rchip)
53 - struct bcm2835_chip *chip;
55 - static struct snd_device_ops ops = {
56 - .dev_free = snd_bcm2835_dev_free,
61 - chip = kzalloc(sizeof(*chip), GFP_KERNEL);
66 - mutex_init(&chip->audio_mutex);
68 - chip->vchi_ctx = devres_find(card->dev->parent,
69 - bcm2835_devm_free_vchi_ctx, NULL, NULL);
70 - if (!chip->vchi_ctx) {
75 - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
85 -static struct snd_card *snd_bcm2835_card_new(struct device *dev)
87 - struct snd_card *card;
90 - ret = snd_card_new(dev, -1, NULL, THIS_MODULE, 0, &card);
92 - return ERR_PTR(ret);
97 typedef int (*bcm2835_audio_newpcm_func)(struct bcm2835_chip *chip,
99 enum snd_bcm2835_route route,
100 @@ -292,25 +226,26 @@ static int snd_add_child_device(struct d
101 return PTR_ERR(child);
104 - card = snd_bcm2835_card_new(child);
105 - if (IS_ERR(card)) {
106 + err = snd_card_new(child, -1, NULL, THIS_MODULE, sizeof(*chip), &card);
108 dev_err(child, "Failed to create card");
109 - return PTR_ERR(card);
113 - snd_card_set_dev(card, child);
114 + chip = card->private_data;
117 + mutex_init(&chip->audio_mutex);
119 + chip->vchi_ctx = devres_find(device,
120 + bcm2835_devm_free_vchi_ctx, NULL, NULL);
121 + if (!chip->vchi_ctx)
124 strcpy(card->driver, audio_driver->driver.name);
125 strcpy(card->shortname, audio_driver->shortname);
126 strcpy(card->longname, audio_driver->longname);
128 - err = snd_bcm2835_create(card, &chip);
130 - dev_err(child, "Failed to create chip, error %d\n", err);
136 err = audio_driver->newpcm(chip, audio_driver->shortname,