Skip to content

Commit 3a1e341

Browse files
committed
ALSA: pcsp: Allocate resources with device-managed APIs
Use the new snd_devm_card_new() for the card object allocation and the devres version for the input device, and clean up the superfluous remove callback. Link: https://lore.kernel.org/r/20210715075941.23332-80-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent ed16a22 commit 3a1e341

3 files changed

Lines changed: 18 additions & 46 deletions

File tree

sound/drivers/pcsp/pcsp.c

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ struct snd_pcsp pcsp_chip;
4242

4343
static int snd_pcsp_create(struct snd_card *card)
4444
{
45-
static const struct snd_device_ops ops = { };
4645
unsigned int resolution = hrtimer_resolution;
47-
int err, div, min_div, order;
46+
int div, min_div, order;
4847

4948
if (!nopcm) {
5049
if (resolution > PCSP_MAX_PERIOD_NS) {
@@ -83,15 +82,18 @@ static int snd_pcsp_create(struct snd_card *card)
8382
pcsp_chip.port = 0x61;
8483
pcsp_chip.irq = -1;
8584
pcsp_chip.dma = -1;
86-
87-
/* Register device */
88-
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, &pcsp_chip, &ops);
89-
if (err < 0)
90-
return err;
85+
card->private_data = &pcsp_chip;
9186

9287
return 0;
9388
}
9489

90+
static void pcsp_stop_beep(struct snd_pcsp *chip);
91+
92+
static void alsa_card_pcsp_free(struct snd_card *card)
93+
{
94+
pcsp_stop_beep(card->private_data);
95+
}
96+
9597
static int snd_card_pcsp_probe(int devnum, struct device *dev)
9698
{
9799
struct snd_card *card;
@@ -103,22 +105,22 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev)
103105
hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
104106
pcsp_chip.timer.function = pcsp_do_timer;
105107

106-
err = snd_card_new(dev, index, id, THIS_MODULE, 0, &card);
108+
err = snd_devm_card_new(dev, index, id, THIS_MODULE, 0, &card);
107109
if (err < 0)
108110
return err;
109111

110112
err = snd_pcsp_create(card);
111113
if (err < 0)
112-
goto free_card;
114+
return err;
113115

114116
if (!nopcm) {
115117
err = snd_pcsp_new_pcm(&pcsp_chip);
116118
if (err < 0)
117-
goto free_card;
119+
return err;
118120
}
119121
err = snd_pcsp_new_mixer(&pcsp_chip, nopcm);
120122
if (err < 0)
121-
goto free_card;
123+
return err;
122124

123125
strcpy(card->driver, "PC-Speaker");
124126
strcpy(card->shortname, "pcsp");
@@ -127,13 +129,10 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev)
127129

128130
err = snd_card_register(card);
129131
if (err < 0)
130-
goto free_card;
132+
return err;
133+
card->private_free = alsa_card_pcsp_free;
131134

132135
return 0;
133-
134-
free_card:
135-
snd_card_free(card);
136-
return err;
137136
}
138137

139138
static int alsa_card_pcsp_init(struct device *dev)
@@ -155,11 +154,6 @@ static int alsa_card_pcsp_init(struct device *dev)
155154
return 0;
156155
}
157156

158-
static void alsa_card_pcsp_exit(struct snd_pcsp *chip)
159-
{
160-
snd_card_free(chip->card);
161-
}
162-
163157
static int pcsp_probe(struct platform_device *dev)
164158
{
165159
int err;
@@ -169,23 +163,13 @@ static int pcsp_probe(struct platform_device *dev)
169163
return err;
170164

171165
err = alsa_card_pcsp_init(&dev->dev);
172-
if (err < 0) {
173-
pcspkr_input_remove(pcsp_chip.input_dev);
166+
if (err < 0)
174167
return err;
175-
}
176168

177169
platform_set_drvdata(dev, &pcsp_chip);
178170
return 0;
179171
}
180172

181-
static int pcsp_remove(struct platform_device *dev)
182-
{
183-
struct snd_pcsp *chip = platform_get_drvdata(dev);
184-
pcspkr_input_remove(chip->input_dev);
185-
alsa_card_pcsp_exit(chip);
186-
return 0;
187-
}
188-
189173
static void pcsp_stop_beep(struct snd_pcsp *chip)
190174
{
191175
pcsp_sync_stop(chip);
@@ -218,7 +202,6 @@ static struct platform_driver pcsp_platform_driver = {
218202
.pm = PCSP_PM_OPS,
219203
},
220204
.probe = pcsp_probe,
221-
.remove = pcsp_remove,
222205
.shutdown = pcsp_shutdown,
223206
};
224207

sound/drivers/pcsp/pcsp_input.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int pcspkr_input_init(struct input_dev **rdev, struct device *dev)
7878
{
7979
int err;
8080

81-
struct input_dev *input_dev = input_allocate_device();
81+
struct input_dev *input_dev = devm_input_allocate_device(dev);
8282
if (!input_dev)
8383
return -ENOMEM;
8484

@@ -95,19 +95,9 @@ int pcspkr_input_init(struct input_dev **rdev, struct device *dev)
9595
input_dev->event = pcspkr_input_event;
9696

9797
err = input_register_device(input_dev);
98-
if (err) {
99-
input_free_device(input_dev);
98+
if (err)
10099
return err;
101-
}
102100

103101
*rdev = input_dev;
104102
return 0;
105103
}
106-
107-
int pcspkr_input_remove(struct input_dev *dev)
108-
{
109-
pcspkr_stop_sound();
110-
input_unregister_device(dev); /* this also does kfree() */
111-
112-
return 0;
113-
}

sound/drivers/pcsp/pcsp_input.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define __PCSP_INPUT_H__
1010

1111
int pcspkr_input_init(struct input_dev **rdev, struct device *dev);
12-
int pcspkr_input_remove(struct input_dev *dev);
1312
void pcspkr_stop_sound(void);
1413

1514
#endif

0 commit comments

Comments
 (0)