1 From c69fbfe4f9dde3389f982a41a2d66db1c49f722d Mon Sep 17 00:00:00 2001
2 From: Takashi Iwai <tiwai@suse.de>
3 Date: Tue, 4 Sep 2018 17:58:58 +0200
4 Subject: [PATCH 463/773] staging: bcm2835-audio: Simplify card object
7 commit 872ae2d63d516a2a3b9c833d8685afcfa7814542 upstream.
9 Instead of creating a dummy child device to manage the card object,
10 just use devm stuff directly for releasing with snd_card_free().
11 This results in a lot of code reduction.
13 Since the dummy child devices are gone, the device object to be passed
14 to the memory allocator needs to be adjusted as well.
16 Signed-off-by: Takashi Iwai <tiwai@suse.de>
17 Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
18 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 .../vc04_services/bcm2835-audio/bcm2835-pcm.c | 2 +-
21 .../vc04_services/bcm2835-audio/bcm2835.c | 120 +++++-------------
22 2 files changed, 33 insertions(+), 89 deletions(-)
24 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
25 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
26 @@ -349,7 +349,7 @@ int snd_bcm2835_new_pcm(struct bcm2835_c
27 &snd_bcm2835_playback_ops);
29 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
30 - chip->card->dev->parent, 128 * 1024, 128 * 1024);
31 + chip->card->dev, 128 * 1024, 128 * 1024);
34 chip->pcm_spdif = pcm;
35 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
36 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
37 @@ -22,38 +22,6 @@ module_param(enable_compat_alsa, bool, 0
38 MODULE_PARM_DESC(enable_compat_alsa,
39 "Enables ALSA compatibility virtual audio device");
41 -static void snd_devm_unregister_child(struct device *dev, void *res)
43 - struct device *childdev = *(struct device **)res;
44 - struct bcm2835_chip *chip = dev_get_drvdata(childdev);
45 - struct snd_card *card = chip->card;
47 - snd_card_free(card);
49 - device_unregister(childdev);
52 -static int snd_devm_add_child(struct device *dev, struct device *child)
57 - dr = devres_alloc(snd_devm_unregister_child, sizeof(*dr), GFP_KERNEL);
61 - ret = device_add(child);
68 - devres_add(dev, dr);
73 static void bcm2835_devm_free_vchi_ctx(struct device *dev, void *res)
75 struct bcm2835_vchi_ctx *vchi_ctx = res;
76 @@ -84,36 +52,6 @@ static int bcm2835_devm_add_vchi_ctx(str
80 -static void snd_bcm2835_release(struct device *dev)
84 -static struct device *
85 -snd_create_device(struct device *parent,
86 - struct device_driver *driver,
89 - struct device *device;
92 - device = devm_kzalloc(parent, sizeof(*device), GFP_KERNEL);
94 - return ERR_PTR(-ENOMEM);
96 - device_initialize(device);
97 - device->parent = parent;
98 - device->driver = driver;
99 - device->release = snd_bcm2835_release;
101 - dev_set_name(device, "%s", name);
103 - ret = snd_devm_add_child(parent, device);
105 - return ERR_PTR(ret);
110 typedef int (*bcm2835_audio_newpcm_func)(struct bcm2835_chip *chip,
112 enum snd_bcm2835_route route,
113 @@ -216,40 +154,36 @@ static struct bcm2835_audio_drivers chil
117 -static int snd_add_child_device(struct device *device,
118 +static void bcm2835_card_free(void *data)
120 + snd_card_free(data);
123 +static int snd_add_child_device(struct device *dev,
124 struct bcm2835_audio_driver *audio_driver,
127 struct snd_card *card;
128 - struct device *child;
129 struct bcm2835_chip *chip;
132 - child = snd_create_device(device, &audio_driver->driver,
133 - audio_driver->driver.name);
134 - if (IS_ERR(child)) {
136 - "Unable to create child device %p, error %ld",
137 - audio_driver->driver.name,
139 - return PTR_ERR(child);
142 - err = snd_card_new(child, -1, NULL, THIS_MODULE, sizeof(*chip), &card);
143 + err = snd_card_new(dev, -1, NULL, THIS_MODULE, sizeof(*chip), &card);
145 - dev_err(child, "Failed to create card");
146 + dev_err(dev, "Failed to create card");
150 chip = card->private_data;
154 mutex_init(&chip->audio_mutex);
156 - chip->vchi_ctx = devres_find(device,
157 + chip->vchi_ctx = devres_find(dev,
158 bcm2835_devm_free_vchi_ctx, NULL, NULL);
159 - if (!chip->vchi_ctx)
161 + if (!chip->vchi_ctx) {
166 strcpy(card->driver, audio_driver->driver.name);
167 strcpy(card->shortname, audio_driver->shortname);
168 @@ -259,26 +193,36 @@ static int snd_add_child_device(struct d
172 - dev_err(child, "Failed to create pcm, error %d\n", err);
174 + dev_err(dev, "Failed to create pcm, error %d\n", err);
178 err = audio_driver->newctl(chip);
180 - dev_err(child, "Failed to create controls, error %d\n", err);
182 + dev_err(dev, "Failed to create controls, error %d\n", err);
186 err = snd_card_register(card);
188 - dev_err(child, "Failed to register card, error %d\n", err);
190 + dev_err(dev, "Failed to register card, error %d\n", err);
194 - dev_set_drvdata(child, chip);
195 - dev_info(child, "card created with %d channels\n", numchans);
196 + dev_set_drvdata(dev, chip);
198 + err = devm_add_action(dev, bcm2835_card_free, card);
200 + dev_err(dev, "Failed to add devm action, err %d\n", err);
204 + dev_info(dev, "card created with %d channels\n", numchans);
208 + snd_card_free(card);
212 static int snd_add_child_devices(struct device *device, u32 numchans)